dorian-top 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/top +43 -0
  3. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 532ba71144adb7c7f6efdaf770bf47561d52cd4259392d91fb57cc7da92b5ada
4
+ data.tar.gz: 59720b5f25e6bd5936ab82353fe075e29bce398e92b5b4e2b2dd35f2eee1b38d
5
+ SHA512:
6
+ metadata.gz: 4109a260b9cf1be18923bdc3ef3e6168f821071fcdfb12bb84ff10f1666f1ee7f451d4accddc0a8bccd218b9a6d6a82fbde675e508568361046e92be657f1c26
7
+ data.tar.gz: 63e847864c5aadfc0e8a2799fb9a1aee259af177bd444ffdd50ae9c5bb580b5b644228a3176de05d4a90a7c7d8cfb2946e4cb90c61bd8bfa207f940c63ae52db
data/bin/top ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ if ARGV.size > 2 || ARGV.first == "-h" || ARGV.first == "--help"
5
+ puts "USAGE: top [N] [SHELL]"
6
+ exit
7
+ end
8
+
9
+ N = (ARGV.first || 10).to_i
10
+ SHELL = File.basename(ARGV.last || ENV["SHELL"] || "bash")
11
+
12
+ HISTORY =
13
+ if SHELL == "fish"
14
+ File
15
+ .read("#{Dir.home}/.local/share/fish/fish_history")
16
+ .lines
17
+ .grep(/^- cmd: /)
18
+ .map { |line| line.split("- cmd: ", 2).last.strip }
19
+ elsif SHELL == "bash"
20
+ File.read("#{Dir.home}/.bash_history").lines.map(&:strip)
21
+ elsif SHELL == "zsh"
22
+ File.read("#{Dir.home}/.zsh_history").lines.map(&:strip)
23
+ else
24
+ raise NotImplementedError.new(SHELL)
25
+ end
26
+
27
+ puts(
28
+ HISTORY
29
+ .map(&:split)
30
+ .map(&:first)
31
+ .tally
32
+ .to_a
33
+ .sort_by(&:last)
34
+ .reverse
35
+ .map
36
+ .with_index do |(command, command_count), index|
37
+ "#{index + 1}\t" \
38
+ "#{command_count}\t" \
39
+ "#{(command_count * 100 / HISTORY.size.to_f).round(3)}%\t" \
40
+ "#{command}"
41
+ end
42
+ .first(N)
43
+ )
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dorian-top
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dorian Marié
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Lists the most used commands
15
+
16
+ e.g. `top`, `top 20`
17
+ email: dorian@dorianmarie.com
18
+ executables:
19
+ - top
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/top
24
+ homepage: https://github.com/dorianmariecom/dorian-top
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ rubygems_mfa_required: 'true'
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubygems_version: 3.5.3
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Lists the most used commands
48
+ test_files: []