gabebw / most-used

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

Parse `fc` output instead #1

Closed gabebw closed 7 years ago

gabebw commented 7 years ago

The contents of ~/.zsh_history are not well-formed (e.g. there can be mismatched quotes that were Ctrl-C'd). However, the zsh builtin fc can parse it just fine.

It'd be cool to mimic whatever fc is doing, but here's a way easier thing for this project to do:

fc -lDt '%Y-%m-%d %H:%M:%S' 1 | most-used

That fc command prints out a command number, timestamp, and time taken for each command like so:

  109  2017-06-21 15:35:52  0:00  rrg positions\\n^C^C^C^C^C^C^C^C^C^C^C
# ...more...
 1011  2017-07-05 12:58:05  0:00  dotfiles
 1012  2017-07-05 12:58:06  0:00  gd\n
 1013  2017-07-05 12:58:07  0:00  ga .

It's quite well-formed.

gabebw commented 7 years ago

Hmmmm, but there's no way to distinguish in fc between "user typed literally slash-n" as a newline and "user hit enter" (real newline).

~/.zsh_history does distinguish.

gabebw commented 7 years ago

Maybe split on "\n: "?

gabebw commented 7 years ago

This is done.