Following the instructions here, I edited by .bash_profile to enable the up and down arrows to autocomplete what I have typed in the shell based on previous commands.
I added to my .bash_profile:
# bind history search to up and down arrows
if [[ $- == *i* ]]
then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
This is great, but I want the down arrow to return to my original text if I can't find the command I'm looking for.
For example, say I have three previous commands:
ls -l
ls -al
Now, I type ls
with the intention of autocompleting it to ls -a
.
I hit the up arrow, which (with my current implementation) autocompletes my text to ls -al
. I hit the up arrow again, which autocompletes my text to ls -l
. At this point, I decide that I won't find the command I'm looking for. If I press the down arrow, the text changes to ls -al
, but pressing the down arrow again doesn't change anything. I want pressing the down arrow to return to my original text (ls
in this case) after I've reached the most recent command in the history.
I would really appreciate it if anyone could help me out or point me in the right direction.
Thanks!
history-search-forward
unless there is nothing forward, in which case the down arrow would map toCtrl+K
? – Zach Kirsch Sep 04 '15 at 03:18fc
to retrieve history items. Mixing shell functions and line editor commands is easier in zsh. – Gilles 'SO- stop being evil' Sep 04 '15 at 22:21