Remix.run Logo
afefers a day ago

Can you explain how you achieve this?

WalterGR 17 hours ago | parent | next [-]

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
import 21 hours ago | parent | prev [-]

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

https://github.com/junegunn/fzf