bash has a great feature called dynamic-complete-history that will allow you to complete text at point with contents from your bash history list.
examine the following workflow :
$ touch file1.txt file-with-a-long-name.txt file3.txt
$ some commands
$ some more commands
$ change directory
$ touch file…
at this point you want to type touch file-with-a-long-name.txt to create another file with the same name in the new directory. would it not be great if i could hit a few characters and then magically complete the name just like hitting TAB in bash completes filenames. yes you can using the bash feature dynamic-complete-history.
$ touch file
and then hit C-M-i (Ctrl+Alt+i) and bash will try to complete the the file name by scanning through the history list. if there are multiple matches then it will display all matching items. enter some more characters until u get a unique match and then hit C-M-i.
the gist of the matter is that if you have already typed some thing and it is in the history list then you can insert it at point with ease. this saves typing which is a good thing.
at first i wrongly assumed that this feature was provided by the gnu readline library but on examining the man page of readline i could not find the corresponding documentation. it turns out that this is a feature provided by bash. on reading the man page of bash i found that it is bound to the key M-TAB but on gnome3 M-TAB is the task switcher i.e. it cycles between open applications. fortunately the magic key chord “\M-\C-i” (Alt+Ctrl+i) is also bound to dynamic-complete-history. this i found out by examining the output of bind -p. i have no idea where this binding is defined
to learn more about bind try
$ help bind
yes that is a help not man
bash version i tested this on is GNU bash, version 4.2.24(2)-release (i686-pc-linux-gnu)
the M in the key chord is the Meta key which is the Alt key on my keyboard.
point basically means where your cursor is at.
bash history list is not the same as ~/.bash_history