[HN Gopher] Trick to find commands in the terminal quickly
       ___________________________________________________________________
        
       Trick to find commands in the terminal quickly
        
       Author : Toby1VC
       Score  : 44 points
       Date   : 2025-02-16 19:54 UTC (3 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | jstanley wrote:
       | > Instead of icons you could use text which you can grep later
       | easily.
       | 
       | An obvious improvement! And if you're using text you don't even
       | need to be watching out to recognise it, you can search with
       | Ctrl-R.
        
       | ashenke wrote:
       | For these commands I want to rerun, but not often enough, I add a
       | comment to the command like `yay - Sc # clear pacman and yay
       | caches` so it's easier to search in the future
        
         | Etheryte wrote:
         | I use this a lot too, often with cherry-picks and reverts that
         | can't be merged into this or that branch yet, too. It's very
         | convenient and works everywhere without installing anything.
        
         | polivier wrote:
         | Oh man that's clever, I never thought of doing that!
        
       | Gualdrapo wrote:
       | Then I'd spend even more time looking for an icon I'd think
       | represents best the command, and then looking for that icon in
       | the emoji selector
        
       | psxuaw wrote:
       | I just add " ###" to the end of commands run frequently. It makes
       | easier to identify important commands with atuin, fzf or plain
       | bash/fish history search.
        
         | __MatrixMan__ wrote:
         | I prefix them with comments                   # sometag
         | the --actual --command
         | 
         | "Bashtags" I call them, despite not actually being in bash
         | these days.
        
       | Duanemclemore wrote:
       | Clever approach, but one extra step for me.
       | 
       | I made a shell script "hg" which stands for "history | grep." So
       | "hg .wine" brings up all commands in the bash command history
       | buffer with the string .wine in them, say "1601 ls .wine" To run
       | one of course you just enter ! and the number of the command. So
       | like... !1601. Whole process is extremely ergonomic.
       | 
       | Although - if anyone wants to write a shell extension that always
       | runs the command output in a separate panel and keeps the parent
       | panel (or tab) to just the commands entered that would be cool
       | too.
        
         | plasticchris wrote:
         | You can search the history with ctrl-r and then type the
         | search. To make it even better use fzf as well.
        
       | adamredwoods wrote:
       | I love making little bash scripts to improve my workflow, and I
       | think everyone should do it, but-- on their own.
       | 
       | For example I have 'glast' to list the 5 previous git branches.
       | 
       | Or I have 'phelp' that basically lists the available commands in
       | a package file.
        
       | ralgozino wrote:
       | Install "fzf" [0] and set it up to be used with control+r,
       | there's no going back. You get as a bonus the chance to use fzf
       | in a lot of other places :)
       | 
       | I guess that more advance tool would be "atuin" [1], but it is
       | too much for my use case.
       | 
       | [0] https://github.com/junegunn/fzf [1]
       | https://github.com/atuinsh/atuin
        
         | noman-land wrote:
         | I switched to atuin and it's a huge step up from native Ctrl +
         | R and fzf because you can press Ctrl + R again and again and it
         | switches between searching through directory, session, host, or
         | global history.
        
           | bencornia wrote:
           | I listened to an interview with the creator of atuin on the
           | changelog podcast. It seems like a compelling idea. The only
           | thing that makes me consider switching from the fzf/ctr-r
           | combo is syncing my history between tmux sessions. But I
           | don't spend enough time in the terminal to really justify the
           | time to set it up.
        
           | nelsonfigueroa wrote:
           | Never heard of atuin but it looks awesome. I'm going to try
           | it out.
        
             | worldsayshi wrote:
             | Oh, looked at the feature set. Sounds interesting.
             | 
             | "Sync your shell history to all of your machines, wherever
             | they are"
             | 
             | That sounds like a potential security issue though.
        
         | hiAndrewQuinn wrote:
         | Seconding `fzf`, it's such an improvement from the stock Ctrl-R
         | behavior I think it's worth installing even if you never
         | actually run `fzf` at the command line itself. Hence why I led
         | with the new shortcuts at https://andrew-quinn.me/fzf (fuzzy
         | `cd` with Alt-C being the other one of note).
         | 
         | Interestingly, the default fish shell also comes with something
         | similar these days, although I still prefer the look of `fzf`.
        
           | worldsayshi wrote:
           | fzf is also really good when you want to make interactive
           | bash scripts (or recipes in Justfiles or Makefiles).
        
         | petters wrote:
         | This has been a larger productivity boost for me than LLMs. I
         | suppose I should use LLMs more.
        
         | nelsonfigueroa wrote:
         | +1 for `fzf`. And if you're using Oh My Zsh then check out fzf-
         | zsh-plugin: https://github.com/unixorn/fzf-zsh-plugin
        
       | pjmlp wrote:
       | Ctrl+R followed by key parts of it.
        
         | ckastner wrote:
         | Yes, this. For example, `Ctrl+R makedo` would go back in
         | history to the first command that matches this, to use the `
         | ./scripts/makedocs.sh` example from the article.
        
         | jmholla wrote:
         | Yup. Then if you want to run the commands that you ran after it
         | last time, hit `Ctrl+O` instead of `Enter` and the next command
         | you ran will be pre-filled on the prompt.
        
       | IshKebab wrote:
       | https://github.com/cantino/mcfly
       | 
       | https://github.com/atuinsh/atuin
       | 
       | You're welcome.
        
         | codetrotter wrote:
         | atuin is the G.O.A.T.
        
         | mb7733 wrote:
         | +1 for autin, and in case anyone is wondering, it works on
         | windows with e.g. git bash too. You just need to build it
         | yourself.
        
         | will_wright wrote:
         | came here to add atuin!
        
       | bilekas wrote:
       | Ctrl+R for reverse search is okay but can get a bit tedious when
       | looking for variations on the command.
        
         | chasil wrote:
         | If you "set -o vi" then (Esc)/ becomes reverse search.
         | 
         | Like vi in reverse, n goes further back, but N goes forward.
         | 
         | The "set -o vi" option is a POSIX optional feature, and should
         | work in any compliant shell.
        
           | bilekas wrote:
           | I'll give it a try, might see if could integrate it into
           | telescope for vim too because I find myself a bit slow when
           | there using harpoon at the moment.
        
       | TZubiri wrote:
       | Ctrl shift R
        
       | TeMPOraL wrote:
       | Interesting.
       | 
       | For me, C-r is sufficient (and/or M-r in Emacs, where C-r by
       | default does reverse interactive search on the text in buffer;
       | it's nice to have both at the same time, actually). However, I
       | must have skipped some education about shell history and/or its
       | default settings, because half the time I need it, the command I
       | want isn't there to be found. I also observed the following kinds
       | of behaviors:
       | 
       | - Sometimes, shell history seems to be scoped (or reacting to)
       | current working directory;
       | 
       | - Sometimes, commands executed on remote machines end up being
       | saved in local history;
       | 
       | - When the shell gets killed (e.g. when Emacs crashes and takes
       | down the shells open inside with it), or the system crashes,
       | _sometimes_ the history gets saved, and sometimes nothing remains
       | from a session that spanned multiple days;
       | 
       | - When I have multiple terminals open, it's a coin toss whether
       | only one will have history saved or all of them, and then another
       | toss as to whether histories will be CWD-sensitive or not.
       | 
       | Is there a good primer/community consensus on how to configure
       | shell so all history gets saved in sensible manner (including
       | continuously, so it survives a crash)?
        
         | cjauvin wrote:
         | > Is there a good primer/community consensus on how to
         | configure shell so all history gets saved in sensible manner
         | (including continuously, so it survives a crash)?
         | 
         | I find that zsh is quite good at addressing some of the issues
         | you mention.
        
         | worldsayshi wrote:
         | Install fzf and ctrl-r will become much better.
        
           | abuani wrote:
           | Fzf has been a district before and after type tool for me.
           | There's so many use cases for it, and the fuzzy search in
           | history is amazing.
        
             | worldsayshi wrote:
             | Yeah, for example I've started looking at making tui:s in
             | go using tview and here fzf-tmux works great as a
             | (multi-)select fuzzy find popup.
        
         | hakcermani wrote:
         | .. have added a gist in comments below, i got used to saving
         | separate history files for each project and launch gnome-
         | terminal with that .. and Ctrl-R within that scope
        
         | foobarqux wrote:
         | There are shell options you need to set to, for example, make
         | shell history saving work when multiple terminals are used (the
         | defaults are bad). Read the manual
        
         | Throe93939 wrote:
         | Fish shell does not have this problems
        
       | 1oooqooq wrote:
       | sligthly ontopic of emoji commands on shell for dyslexics and/or
       | visual people, here's one i use often
       | https://github.com/gcb/emojihash.sh?tab=readme-ov-file
        
       | mooreds wrote:
       | The first thing I add to my shell RC file is 'set -o vi'
       | 
       | Then I can use the vi/vim search keys
       | 
       | - escape
       | 
       | - '/'
       | 
       | - <type words>
       | 
       | - hit n or N to move back and forth
       | 
       | Way way easier than using the up or down arrow.
        
         | SoftTalker wrote:
         | Unless you use emacs, then the shell history keys seem normal
        
           | chasil wrote:
           | POSIX outlines vi mode, but emacs is not mentioned.
           | 
           | " _vi_ - Allow shell command line editing using the built-in
           | vi editor. Enabling vi mode shall disable any other command
           | line editing mode provided as an implementation extension. "
           | 
           | https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V.
           | ..
        
       | seiferteric wrote:
       | I made a tool some years ago to store commands in a dot files
       | https://github.com/seiferteric/clamp
        
       | SoftTalker wrote:
       | If you have a command you run over and over, make an alias for
       | it. That way if your shell history gets clobbered you still have
       | it.
        
       | hakcermani wrote:
       | .. another cheap trick .. when juggling different projects i keep
       | a separate history file for each under ~/.histories/ .. shameless
       | plug to my gist .. bash script that launches gnome-terminal with
       | a named history file ..
       | 
       | https://gist.github.com/appsmatics/ff27e885460bd345eabe1c5f7...
        
       | jasonpeacock wrote:
       | Or use the right tools, like atuin[1] and hoard[2], to manage
       | your shell history and preserve frequent/favorite commands.
       | 
       | [1] https://terminaltrove.com/atuin/
       | 
       | [2] https://terminaltrove.com/hoard/
        
       | VeejayRampay wrote:
       | I use television (https://github.com/alexpasmantier/television)
       | with shell integration
       | 
       | so basically I end up doing ctrl-r, then fuzzy find the command
       | and run it
        
       ___________________________________________________________________
       (page generated 2025-02-16 23:00 UTC)