Hacker News new | past | comments | ask | show | jobs | submit login

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 "
      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.

zsh-histdb is such a gem and I wish was just the default everywhere.

I looked it up and the installation seems pretty involved, so I gave up.

Involved? 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.

Looks like you have to do more stuff on mac

> 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 :)

I'm an assisted human being, I need instructions like these :D 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)

For 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 \

This makes me wonder, is there a SQLite equivalent for JSON based data?

SQLite is a good equivalent :D https://www.sqlite.org/json1.html

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.


For 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#queryin...

You could use jq to do something similar.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact