Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Unix tool that visualizes shell commands usage (github.com/irevenko)
98 points by irevenko on Feb 26, 2021 | hide | past | favorite | 24 comments



Pretty cool terminal visualizations, but tbh straight unix tools allow you to do this (might be different than 4th column for you depending on history format):

`history | awk '{print $4}' | sort | uniq -c | sort`

      56 tree
      58 make
      59 youtube-dl
      69 cmake
      71 which
      76 docker
      78 scala
      80 drive
      80 wget
      96 curl
      99 head
     102 echo
     105 pip
     114 scp
     119 ssh
     131 open
     135 conda
     135 kubectl
     141 man
     181 sudo
     298 mkdir
     350 grep
     378 ls
     409 find
     415 mv
     544 cp
     553 python
     568 brew
     601 cat
     674 rm
    1928 vim
    1972 cd
    2845 git

Also, I'm noticing this won't catch anything in pipes otherwise I'd expect to see less and xargs pretty high up.


Add -n to the second sort to actually get a numerically (as opposed to lexically) sorted list. Also, here (using bash on linux) awk needs $2 instead of $4.

It doesn't catch the pipes, because you are parsing the command lines as entered, and you filter for a single parameter from each.


Interesting command usage. One tip I'd offer is to use a `trash` command instead of `rm`. Unix doesn't usually offer it, but installing is as simple as `apt install trash-cli`.

You've gotten lucky 674 times by not `rm`-ing the wrong thing.


Looks cool, but nothing much happens for me. I used brew to install go, then ran the following:

  % type -a go
  /usr/local/bin/go
  % cd tsukae
  % go get -d ./...
  go: downloading github.com/inconshreveable/mousetrap v1.0.0
  % go run main.go
  o: downloading github.com/spf13/cobra v1.1.3
  go: downloading github.com/gizak/termui/v3 v3.1.0
  go: downloading github.com/mattn/go-runewidth v0.0.2
  go: downloading github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
  go: downloading github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7
  go: downloading github.com/spf13/pflag v1.0.5
...a whole lot of usage information... ...but nothing useful (not a go person, so, YMMV)....

Any ideas?

FYI,

  % go version
  go version go1.16 darwin/amd64


cd tsukae

go build

./tsukae


Closer! That got me the executable. Now I get a stack trace....

  % ./tsukae bash
  panic: runtime error: slice bounds out of range [:7] with capacity 4

  goroutine 1 [running]:
    github.com/irevenko/tsukae/cmd.GetShellCommandsUsage(0x1205b84, 0x4, 0x7, 0x4, 0x3, 0xc000066180, 0xc000127d78, 0x1159965, 0xc000120500)
   /Users/pww/tsukae/cmd/shell_name.go:22 +0x16d
  github.com/irevenko/tsukae/cmd.glob..func4(0x135df20, 0xc00005c8b0, 0x0, 0x1)
   /Users/pww/tsukae/cmd/commands.go:88 +0x1bf
  github.com/spf13/cobra.(*Command).execute(0x135df20, 0xc00005c8a0, 0x1, 0x1, 0x135df20, 0xc00005c8a0)
    /Users/pww/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:856 +0x2c2
  github.com/spf13/cobra.(*Command).ExecuteC(0x135e1a0, 0xc000000180, 0xc000127f78, 0x10069e5)
     /Users/pww/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
  github.com/spf13/cobra.(\*Command).Execute(...)
       /Users/pww/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:897
  main.main()
   /Users/pww/tsukae/main.go:12 +0x36


i figured it out, you just need to have bigger history, currently you only have 4 unique commands in your hist file.


My history has a few thousand commands....


try go 1.15


If one of your top commands is `clear`, you may like my alias `c`:

  $ alias c='clear &&'
  $ # Usage:
  $ c git status
[1]: https://github.com/grantzvolsky/skel/blob/ea43b1969463a97f96...


If you use bash (or zsh, and maybe others), hit ^L (control-L) to clear the screen. From the bash(1) manual:

clear-screen (C-l) Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the screen.


I must hit ctrl-l a thousand times a day, learned it before I knew of clear.


If one of your top commands is `cd ../..` you may like my alias/function `..`

    $ .. 2 # go back 2 directories, i.e. 'cd ../..'
    $ .. # 'cd ..'
https://github.com/Aperocky/unix-setup/blob/master/.bashrc#L...


Going to my home dir is another frequent operation for me so I also have

  alias ~='pushd ~'
(Those are tildes but may look like dashes depending on your font and size...)

Not as fancy as some other aliases I see here but does the (basic) trick.


A raw "cd" with no arguments will take you back to your home-directory. Of course "~" is one less character to type, but on the off-chance you didn't know.


As we're offering alternatives. Either `shopt autocd` in bash or `setopt auto_cd` in zsh, then ~ changes to home by simply being a path.


I use '..' for '$ cd ..' and '...' for '$ cd ../..'.


I like '$ .. 5' because after the number goes up the dots become very hard to count.


Great idea, thanks!


I clear the screen a lot, but I use Cmd+K to clear the whole Terminal.app screen or Cmd+L to clear the last command (and its output) on Mac, rather than using the `clear` command. I use Bash, not sure if it works on other terminal emulators.


Cool! I’ve used xonsh for some time, it can store history in sqlite format. Then any such analysis can be done with SELECT...ORDER BY etc.


YES!!! I've been waiting for someone to do this for a decade or more.

This + https://tldr.sh/ and the command line will be so much easier for me (but especially beginners!).

With your tool, having an easy way to copy and paste your personal usage into some central website and then have some scripts would be a great thing to show aggregates.

You could probably just create a single new repo and people could send PR's with their usage dumped to CSV (and they could remove any person info manually before). Then you just have a script that reads those CSVs and prints a nice web page with summary data.


tsukae does mean "use" in Japanese -- but it's the blunt command form (命令形) "Use it!!"


A cool tool!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: