gabebw / most-used

Find your most-used shell commands
BSD 3-Clause "New" or "Revised" License
12 stars 0 forks source link

Parse Bash history #11

Closed gabebw closed 7 years ago

gabebw commented 7 years ago

It could switch depending on $SHELL value (and be forced to use one or the other with --shell zsh or --shell bash).

Here's what history -a produces:

    1  ls
    2  strace tmux
    3  brew install strace
    4  /usr/local/bin/brew install strace
    5  dtrace -h
    6  man dtrace
    7  dtrace -f execve ls
    8  sudo dtrace -f execve ls
    9  sudo dtrace -f execve 
   10  sudo dtrace 
   11  sudo dtrace -f execve -c ls
   ...etc...
   69  wc -l ~/.bash_history 
   70  history | wc -l
   71  history
   72  echo '
   73  ls
   74  '

Note that this does not understand newlines like fc does, so echo '\nls\n' gets interpreted as lines 72, 73, and 74. 😬

gabebw commented 7 years ago

Maybe it's better to just do the equivalent of cat ${HISTFILE:-~/.bash_history} since running an interactive shell just for history isn't actually worth it.

gabebw commented 7 years ago

The history file looks like this:

b
ls
history
g | less
gabebw commented 7 years ago

Fixed by #13.