4 ms·
I feel like discussion of 'sensible bash defaults' is incomplete without mention of .inputrc. My most "can't live without it" setting for bash is actually an .
by thom_nic 11y ago
I feel like discussion of 'sensible bash defaults' is incomplete without mention of .inputrc. My most "can't live without it" setting for bash is actually an .inputrc setting:
# From http://www.ukuug.org/events/linux2003/papers/bash_tips/
# Incremental searching with Up and Down is configured in .inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
... so if I type `ssh <up arrow>` I get the last command that started with `ssh`, not the last command I ran. oh-my-zsh thankfully does this by default as well. But I still use my .inputrc on server boxen where I don't want/need to install a different default shell.
Also worth noting that all of those `bind` commands in OP's script are actually .inputrc lines if you remove the `bind` and surrounding quotes.
- ajross 11y agoThis is why these things are so personal. I'd hate this. The up/down bindings are absolutely tied to specific command orders in my head. I need to know that "three commands back" is wherever I was in the sequence of commands that I'm repeating. If I'm trying to semantically query my history (for "ssh") in this case I'll use the ^R binding to incrementally search the history, or literally grep ~/.history for what I'm looking for. That's not to say that you're "wrong", just that calling these things "sensible defaults" is sort of missing the point. Nothing about them is sensible for everyone.
- omalsa04 11y agoIf you just press "up" without typing anything first then it works as you expect. I find ^R annoying if I've already started typing the command and then realise I can search the history (although that's probably configurable). Once you get used to it, the only downside of up/down history search is when you ever use a shell that doesn't do it and you feel lost.
- zo1 11y agoOn a standard Ubuntu install: If you press ^R after already typing part of what you're searching for, and then press a key (space, or more of the command you're searching for), then it'll switch to the history-search mode with that value pre-filled in.
- plorg 11y agoI have it as "\e[5~": history-search-backward "\e[6~": history-search-forward This allows you to continue using arrows for absolute chronological history then use PageUp and PageDn for history search. You could also change it to "\e[5~": history-substring-search-backward "\e[6~": history-substring-search-forward if you want to search for a string match anywhere in the command rather than at the beginning. It might be 'substr' rather than 'substring' depending on your Bash version. Obviously the utility of this depends on your keyboard layout and config, as much as it does on personal preferences. You can see the full list of commands at https://www.gnu.org/software/bash/manual/html_node/Commands-For-History.html https://www.gnu.org/software/bash/manual/html_node/Commands-....
- deleted 11y ago[deleted]
- thom_nic 11y agoYup, it changes the default behavior slightly but as @omalsa04 mentioned if you just hit <up> without typing anything it will iterate through the whole command history, the same as it would without this binding.
- insanebits 11y agoSo that is where it actually comes from. I was wondering for some time now. This is one of my favorite features on oh-my-zsh! It mostly helps when you type complicated command and after half an hour you need to repeat it for some reason. You type the command you used, and hit a arrow up.
- thom_nic 11y agoI don't think zsh uses the .inputrc file, actually. I've actually never looked into how oh-my-zsh does it.
- ianmcgowan 11y agoI have to comment just to say "thanks!" - don't know how I lived this long without knowing this one trick. This just blew my mind!