4 ms·
Here is a zsh function (added to ~/.zshrc) I made for use with https://github.com/larkery/zsh-histdb https://github.com/larkery/zsh-histdb to get the same effec
by lrobinovitch 5y ago
Here is a zsh function (added to ~/.zshrc) I made for use with https://github.com/larkery/zsh-histdb 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
"
}
- Spivak 5y agozsh-histdb is such a gem and I wish was just the default everywhere.
- baby 5y agoI looked it up and the installation seems pretty involved, so I gave up.
- capableweb 5y agoInvolved? Love to hear how it could be easier, requires just about 3 steps for download+installation+usage 1. Download the `sqlite-history.zsh` file to somewhere (or use oh-my-zsh) 2. Source that file in your `.zshrc` 3. Run `autoload -Uz add-zsh-hook` in your `.zshrc` That's it. I can't imagine a way it could be easier in fact.
- baby 5y agoLooks like you have to do more stuff on mac
- capableweb 5y ago> Looks like you have to do more stuff on mac 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 :)
- baby 5y agoI'm an assisted human being, I need instructions like these :D https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md#oh-my-zsh https://github.com/zsh-users/zsh-syntax-highlighting/blob/ma... 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 :) (I know it's free, not complaining)
- ldrndll 5y agoFor what it's worth, I installed it with my zsh plugin manager without any issues. A simple case of adding it to the list: zinit light-mode for \ zinit-zsh/z-a-as-monitor \ zinit-zsh/z-a-patch-dl \ reegnz/jq-zsh-plugin \ larkery/zsh-histdb
- pokstad 5y agoThis makes me wonder, is there a SQLite equivalent for JSON based data?
- kevmo314 5y agoSQLite is a good equivalent :D https://www.sqlite.org/json1.html https://www.sqlite.org/json1.html
- karl42 5y agoFor some JSON files, sqlite-utils' memory command works great. E.g. sqlite-utils memory 'SELECT * FROM a JOIN b USING (pkey)' a.json b.json See https://sqlite-utils.datasette.io/en/stable/cli.html#querying-data-directly-using-an-in-memory-database https://sqlite-utils.datasette.io/en/stable/cli.html#queryin...
- onion2k 5y agoYou could use jq to do something similar.
- ZeroGravitas 5y agoThe 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. https://github.com/fiatjaf/jiq https://github.com/fiatjaf/jiq
- Y_Y 5y agoI 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.
- capableweb 5y agoThe 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.
- Y_Y 5y agoIndeed 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.