19 ms·
Fortunately my memory was never good enough for me to use that facility. C-r is how I always lookup earlier commands.
by satya71 5y ago
Fortunately my memory was never good enough for me to use that facility. C-r is how I always lookup earlier commands.
- aulin 5y agoI always add "\e[A": history-search-backward "\e[B": history-search-forward to my .inputrc, I find it easier to use than C-r as it's some sort of autocomplete from history. But looking up commands with !number can still be very useful when you don't remember the command you need but remember when you used it (e.g. what commands you ran before and after).
- kreetx 5y agoWhat are the "\e[A" and "\e[B" do, are they key presses? I usually do `history | grep ...` to find the command and then use it. Non-emacs users might tend to find this surprising, but in a shell buffer you can move around with your cursor like in a text file, so after executing `history` you can search for the command as string then copy-paste it.
- aulin 5y agoYep, it binds history search to key up and key down. Start typing a command, press up or down and it will scroll through matching completions from history
- aeonflux 5y agoI've used build-in browser for years, but I highly recommend switching to https://github.com/junegunn/fzf https://github.com/junegunn/fzf for C-r in shell. Night and day boost.
- jakzq 5y agoCan you navigate C-r history, or are you forced to see only the last command?
- mbilker 5y agoYou can! If you do C-r again, then it will show the next command in your history for the given search.
- isenhaard 5y agoI've noted once within my personal bash cheat sheet this: Search the command history * Search as you type: Ctrl + r and type the search term; Repeat Ctrl + r to loop through results. * Search the last remembered search term: Ctrl + r twice. * End the search at current history entry: Ctrl + j * Cancel the search and restore original line: Ctrl + g Try of course at your own risk. But works for me.
- srik 5y agoPair <C-r> with `fzf` if you want good ux.
- deleted 5y ago[deleted]
- Mizza 5y agohttps://github.com/cantino/mcfly https://github.com/cantino/mcfly Life changer
- IshKebab 5y agoAgreed. Much better than Bash's terrible built in ctrl-R which doesn't even show what you're typing if it doesn't match.
- boffinAudio 5y agoI do this too, but you know what is an even cooler and more rewarding way to exploit the shell history? By COMMENTING your commands: $ grep -i myname /etc/passwd # passgrep .. .. $ Ctrl-R "passgr" It is so rewarding to do some intense bash work with liberal command line comments and then come back a few weeks later, "history | grep \#", and see my work notes - along with the relevant commands - available. I used to write '~/bin' scripts for special stuff, including comments in the .sh source itself - but now it just makes more sense to wang a comment at the end of the complex/interesting commands and then just grep for the comment later ..
- kevincox 5y agoI have a similar system but take advantage of prefix-search rather than Ctrl+r For commands that I reuse semi-frequently I set an environment variable so that I can easily find them with prefix searching. So for example I sometimes pin IPFS paths to Infura so I have this command in my history. I can then type pin=<Up> and recall that command (until it drops off the end of my shell history). pin= r curl -fiXPOST "https://ipfs.infura.io:5001/api/v0/pin/add?recursive=true&arg=$(c)"
- boffinAudio 5y agoUseful, but dangerous! I would have to check if there is already an environment variable in use before I did that ..
- kevincox 5y agoI know this command doesn't depend on a lowercase `pin` variable so there is no danger. Note that this doesn't change the variable in the shell, just the executed command.
- boffinAudio 5y agoYeah, its the 'knowing beforehand' part that makes this dangerous for me. ;) Cute trick though, will work it into my workflow and see how it feels.