Here is a zsh function (added to ~/.zshrc) I made for use with https://github.com/larkery/zsh-histdb to get the same effect, but only showing commands whose exit_status is 0:
jog() {
sqlite3 $HOME/.histdb/zsh-history.db "
SELECT
replace(commands.argv, '
', '
')
FROM commands
JOIN history ON history.command_id = commands.id
JOIN places ON history.place_id = places.id
WHERE history.exit_status = 0
AND dir = '${PWD}'
AND places.host = '${HOST}'
AND commands.argv != 'jog'
AND commands.argv NOT LIKE 'z %'
AND commands.argv NOT LIKE 'cd %'
AND commands.argv != '..'
ORDER BY start_time DESC
LIMIT 10
"
}
I love having stuff like this in zsh except that I very often have commands that don't exit with 0 either because I made a mistake, or because of something happening like referencing a file that might have been there but wasn't.
I understand not wanting to clog up your history with typos, but some configs even default to not being able to press up-arrow to get a command that I just mistyped.
The function lrobinovitch showed is not overwriting your history, it just shows the successful commands when running `jog`. Your up/down-arrow and ctrl+p will still work like normal, typos or not.
But if you did do a mistake in your command, like referring to a file that doesn't exist, don't you rerun the command again but with the correct parameters? Then it would be included there as well (when running `jog`).
Otherwise, it's trivial to remove the WHERE statement so it shows all the commands, seems zsh-histdb stores everything, successful or not.
Indeed not. In fact the issue would be with some history never getting recorded at all. Thank you for clarifying though, that the dir-based history tools don't affect the existing history.
The example I was trying to explain above referred to deliberately referencing a filename which may not correspond to an existing file. Like I might stat a file, to know when it was created, but if it hasn't been created yet then that's an answer too.
Are you referring to the "Note for OS X users" section in the README? If so, it's only additional step, so 4 in total... I know macOS users might not be the most technical, but I think most of them (at least developers on macOS) should be able to follow it :)
btw my comment was not here to tell people I was lazy. It was here as feedback. Users are lazy. Online businesses track and look to decrease the number of clicks that lead to a sale, there's no reason developer tools shouldn't try to do the same :)
The other tools mentioned are all good, theres also jiq, which lets you run jq interactively against an input until you get the incantation right, then confirm it to get the full output.