remix logo

Hacker Remix

Show HN: Zev – Remember (or discover) terminal commands

86 points by dtnewman 4 days ago | 38 comments

submeta 4 days ago

Nice! I use a combination of an endless bash (zsh) history with timestamps that I navigate via fzf and ctr+r and comments I occasionally add to commands via # at the end followed by my annotation so that I can rediscover the command.

I do this ever since I switched to a Mac in 2015 and my history has over 60,000 lines. So that’s basically my knowledge base :)

But your project looks nice. Will check out.

reddit_clone 3 days ago

Exactly my setup including the #tag's. It is my second brain.

What I love about this is the fzf's fuzzy narrow down. You don't have to start at the beginning of command, you don't have to worry about exact spelling. Just a few snippets you remember, it will narrow it down really fast.

I use the same fuzzy search narrow downs in Emacs.

I miss it everywhere else.

aldanor 18 hours ago

Fish has built in fuzzy search on ctrl-r as well, with no extra config needed

afefers 3 days ago

Can you explain how you achieve this?

WalterGR 3 days ago

Shells that use readline (such as bash) may have a history search feature built-in and on by default. Try pressing Ctrl-r or Cmd-r and see if a prompt pops up.

You can build your own workflow by hand by doing something like:

1. Turn on your shell’s feature to record command history.

2. Look into its feature set to control things such as how many entries it remembers, whether it remembers duplicate entries, and whether it timestamps each entry. (Don’t forget to restart each instance of your shell, if needed, for changes to take effect.)

3. Install a tool such as fzf that allows interactive filtering of arbitrary text. (Via Homebrew it’s `brew install fzf`. It’s likely something similar for other package managers.) These tools usually: read lines of input, prompt the user to optionally filter but eventually select a line, then just print that line.

4. Write the necessary shell script(s) / functions / aliases to do things like:

+ invoke the fuzzy-finder on the shell’s history file or a modified version of that file (for example, a modified version that excludes bash’s timestamp lines, or that joins them - perhaps in a human-readable format - with the command it timestamps.)

+ process the output of the fuzzy-finder tool (for example, to copy the command to the clipboard, paste it into the shell, or execute it immediately - which will necessitate things like removing any timestamps or additional notation added in the previous step.)

Step 4 can be easy as something approximating (I’m on mobile right now):

   fzf “$HOME/.bash_history” | copy-to-clipboard

porridgeraisin 2 days ago

Fzf installs hooks automatically for ctrl+r and a bunch of other stuff

Search for `fzf --bash`. Note that the version in the ubuntu repos is too old to have this feature (I think)

import 3 days ago

Not op but you need fzf and you need to increase the history size of your bash/ssh whatever

https://github.com/junegunn/fzf

AvieDeckard 3 days ago

Your gif in your README features a prompt asking to "show all files in this directory" but the 'ls -lh' returned and selected in the demo gif does not show all files, just the ones that aren't hidden. I'd have chosen a more accurate interaction for the demo.

rco8786 2 days ago

Kind of a good example of how AI gets it "almost" right.

chrisco23 4 days ago

I'm trying to get this to work with ollama. I'm on Arch Linux, fish shell, new to ollama, and only very rarely used pipx. I get:

raise ValueError("OPENAI_BASE_URL and OPENAI_API_KEY must be set. Try running `zev --setup`.") ValueError: OPENAI_BASE_URL and OPENAI_API_KEY must be set. Try running `zev --setup`

even when I run (for example) set -x ZEV_USE_OLLAMA 1; zev 'show all files and all permissions'

dtnewman 4 days ago

creator here. It pulls env variables from a file in your appstorage directory. I need to change this in a future release to make it cleaner, since I don't think i like it intermingling with env variables.

That said, did you run `zev --setup`?

lionkor 3 days ago

Why are you using env variables when you don't pull them primarily from the process env?

dtnewman 3 days ago

I’m debating changing it. I do pull in env vars to use as default values (e.g. you already have an API key set). But I might transition way from env variables.

dtnewman 4 days ago

btw, feel free to open an issue on github :)

arjie 4 days ago

I don't like most of these commands because they just execute. This one is nice because it will be in your history. The current trick I use is to use copilot.vim at the command line. It naturally fits into my flow.

Recently some of my friends reported that it just wants to do comments and I've noticed that it actually biases towards that nowadays, so I start it with something to get it kicked off.

I've been managing to try to figure out what in the prompt makes it like that, but for the moment that little workaround gives me both the comment and the command in my history so it's easier to r-i-search for it.

https://x.com/arjie/status/1575201117595926530

You just set up copilot for neovim normally and set it as your EDITOR. https://wiki.roshangeorge.dev/index.php/AI_Completion_In_The...