6 ms·
I virtually never use !! any more. Instead I just type control-r followed by a portion of the command in my history that I'm interested in. That's a much more
by pmoriarty 10y ago
I virtually never use !! any more. Instead I just type control-r followed by a portion of the command in my history that I'm interested in.
That's a much more interactive way of getting to the command I want, and if the first match isn't what I want I can either keep typing more of the command or type control-r for the next match. I can also type control-s to go to the previous match. For that last trick to work, you need to do something like this first: stty stop ""
Granted, I use zsh, but I think it works pretty much the same in bash.
Another trick I really like, which I've only used in zsh, but which might exist in bash too (since bash and zsh have so much feature parity these days) is to bind a keystroke to "insert-last-word". When this keystroke is hit, it appends the last argument of the previous command to the end of the current line, further typing of this same keystroke will remove the appended argument and instead append the last argument of the previous command, and so on. I use this all the time and therefore never have to type !$
And my favorite shell trick of all time: set -o vi
- igg 10y agofzf [0] works pretty well for this. [0] https://github.com/junegunn/fzf https://github.com/junegunn/fzf
- pmoriarty 10y agoIs there any way to force the installer to compile from source rather than downloading a binary? I'm a little wary of precompiled binaries.
- icebraining 10y agoThere's a Makefile in the src directory, seems like you can run "make release" to compile from source.
- pjmlp 10y agoDo you also validate the whole source code, including running it through static analysis, before compiling it?
- marklgr 10y ago> When this keystroke is hit, it appends the last argument of the previous command to the end of the current line There's `Meta-_` to insert the previous last word, but you cannot cycle with the previous words--it inserts the last word of the previous commands. You can give it a count, though (with Meta+nums).
- Myrmornis 10y agoAgreed, but even nicer than control-r are the readline functions `history-search-backward` and `history-search-forward`. Personally I bind them to up/down which on OS X at least involves: # Put this in some file like ~/.readline-bindings "\e[A": history-search-backward "\e[B": history-search-forward # And this in your ~/.bashrc or ~/.zshrc bind -f ~/.readline-bindings That way if you haven't typed any input it behaves like normal up (previous command), but if you've typed some characters it only retrieves matching commands. http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/ http://codeinthehole.com/writing/the-most-important-command-...
- musicmatze 10y agoIs there a way to make this work with `set -o vi`? So I can use j/k to browse the history this way?
- deleted 10y ago[deleted]
- lolive 10y agoMapping these to Up/Down arrows (instead of PgUp-PdDn) is the best idea EVER !!!
- devnonymous 10y agoJust curious since I don't use a mac, doesn't writing the mappings to .inputrc work? IIRC, putting your readline bindings there makes it available for all readline enabled prompts, not just bash ie: Python, pgsql, mysql,.. Etc
- Myrmornis 10y agoYes I think that's a better approach, thanks. I don't know why I started using `bind` in my shell config.
- deleted 10y ago[deleted]
- Jerry2 10y ago>Granted, I use zsh, but I think it works pretty much the same in bash. I also use zsh and I don't even use ctrl+r anymore. I just type a portion of the command I remember and hit the up arrow key. Almost always the command I want is only one to three arrow keys away. zsh matches partial commands really well.
- pmoriarty 10y agoI like the incremental searching that using control-r lets you do. That can come in really handy when I don't remember precisely what the command I want is. I can start typing and then type more once I see some results to hone in more precisely to what I want, or even backspace over some of what I've typed and type some more without having to start all over again. Also, using control-r instead of the arrow keys doesn't force me to move my wrists and lets me keep my fingers mostly on the home row. I try to use the arrow keys as little as possible.
- JoshTriplett 10y agoBash has similar commands available to move up and down by matching commands. However, I find such modal behavior of up/down confusing; I prefer to have up and down always move by one command, and use C-r for reverse isearch.
- distrill 10y agoAgreed, but this only works if you know you are right about the beginning of the command. Ctrl-R is still the best way I know to search for a command that I may not be sure about the first letters of.
- vbernat 10y agoAn interesting "extension" of C-r with zsh is to add pattern search: bindkey '^r' history-incremental-pattern-search-backward When you remember parts of the commands, you can do "C-r" then "echo*something".
- nicops 10y agoAgreed. I guess everything is subjective, but when I read the article state: > While the [ctrl-r] method is more powerful, when doing some redundant task, it’s much easier to remember !22 than it is to muck with ctrl-r type searches or even the arrow keys. how?!