jog
jog copied to clipboard
Multi-line command support
trafficstars
$ cd
$ echo '123
456'
$ cat ~/.zsh_history_ext
$ echo '123
456'|/home/user
$ jog
456'
jog shows just the last line of a multi-line command
FWIW, here is my version of this trick:
function zshaddhistory() {
if [[ $1 == $'jog\n' ]]; then return; fi
printf '%s\t%q\n' "$PWD" "${1%%$'\n'}" >> ~/.cache/jog-history
}
function jog() {
grep -a --color=never "^${PWD}"$'\t' ~/.cache/jog-history |
tail | sed 's/^[^\t]+\t//' | xargs -n1 echo
}
With this version, your example produces:
❯ echo '123
… quote ❯ 456'
123
456
❯ cat ~/.cache/jog-history
/Users/jason echo\ \'123$'\n'456\'
❯ jog
echo '123$\n456'
This makes it work almost like the built-in zsh history command (which would store it as two lines, but display it as echo '123\n456').
Other things I changed included:
- Skip adding calls to
jogto the history, rather than skip reading them from the history - Store the history file in
~/.cache(mostly because I keep my dotfiles in git, so putting things like this into~/.cachemeans I don't need to add additional top-levelgitignoreentries - Store the directory first, followed by a tab so it works with commands that include pipes
- Do the directory removal after the tail, rather than stripping the directory from possibly hundreds or thousands of lines and then discarding most of them.
@jasonk I don't know if I misused something but my zsh print out the directory + \n and the command. e.g:
❯ jog
/home/me
cat .cache/jog-history
I'm using zsh with Ubuntu on wsl 2