A seemingly little known input option can transform the way you use your shell:
cat >> ~/.inputrc <<'EOF'
# narrow history to input text left of the cursor
$if bash
"\e[A": history-search-backward
"\e[B": history-search-forward
$endif
EOF
That is the single most valuable option you’ll ever need; it’s essentially how the command history works OOTB in vim. It sets ↑ and ↓ to search the history for lines starting with what’s to the left of the cursor.
Take this current real life example:
How it transformed my shell usage
Using that inputrc option, I don’t need to write many scripts, because I can just retrieve my ad hoc scriptlets with a simple search pattern; I have a lot of those in my history. To be perfectly honest, though, I kinda sorta lied, when implying that I’m using Bash, because ever since I had my first experience with GRML’s non-plus ultra excellent Zsh setup, I have switched to Zsh and never looked back; it too did need a little tweak of the config, though:
bindkey "^[OA" history-beginning-search-backward
bindkey "^[OB" history-beginning-search-forward
bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward
because it has its own line editor zle; that way the cursor stays in position, just like with the ~/.inputrc setting, so one can refine the search, if there are too many matches. Keeping with the ip link example, suppose you have run other commands starting with sudo ip between the last MTU adjustments and typing sudo ip↑ gets you sudo ip address ...; with the cursor still just after ip, you can refine the search by typing link↑ and so on — you get the gist.
That, combined with the power of Tab (menu) completion everywhere has made me into a desktop refugee who practically lives in a shell. I always cry a little inside whenever I am forced to use any default shell setup, which doesn’t have these rather basic but very very powerful options set, so virtually all of them — except GRML, of course, which has the slightly inferior default setting that puts the cursor at the end of the line but showed me that this was even possible. I am truly baffled that this isn’t the default. Maybe someone just needs to spread the word; happy to oblige:
![]()
@Canonical