Auto complete for often used command line commands?
For some projects I often type in a couple commands, like for example:
cd an/extremely/long/path/in/which/I/have/some/kinda/project
and
./runmyproject --with some --command line --options set
Seeing that I'm pretty lazy I try to avoid typing those commands in full again and again. So I can of course use the up-key a lot to find back those commands, but often, I also have so many commands in between, that searching for it takes even more time than just typing it.
I now wonder if there is some kind of utility that can suggest a full command which I use a lot, when I haven't typed all of it yet. So that I can for example type 'cd an/' and that it already suggests the rest of the path because I've used it so much the past month.
I did find something called Bash Smart Complete. But that is a little "dumb" in that it doesn't look at the commands I used before. I just also found this SO answer, which suggests putting the commands I use a lot in a file. That however, is not responsive enough in that I would need to create a new file for it every time I start new projects or change folders or program arguments.
Does anybody know any other utility or other way to achieve this? Or, would anybody know how I could alter the Bash Smart Complete so that it can look at the commands I used in say the past month and complete the command which fits and has been used the most in the past month?
[EDIT] Below are some really great answers. I haven marked any as a definite answer yet. Not because I do not like the answers, I do, but because none of them is an absolute winner. I think the Finalterm is a great project. Unfortunately it is still rather rough around the edges. For example; it doesn't support copy-paste yet. I would keep on eye on that project though, because when it will mature I think it'll be a great terminal app. As for the other answers; they either suggested creating an alias, which is not what I want to do because it creates extra work instead of taking work away, or using Ctrl+R, which is a brilliant (I didn't know about it!). A couple of people suggested using Ctrl+R, so I can't really highlight one answer over the other.
So for now I am definitely using Ctrl+R, and in the future I might use Finalterm.
Thanks for all the great answers guys!
Solution 1:
If the commands are often used, they are recorded in the command history bash tracks in .bash_history
.
Now the trick: You can reverse search this history to re-execute commands by pressing CTRL-r.
In inverse history search mode, bash shows, live, as you type, the most recent command in the history that start with your given input. Then press enter to accept and execute the proposed command. Keep pressing CTRL-R to cycle to older commands with the same prefix.
This is builtin in bash, no need for customizing scripts or install software :) It is one of the most useful features of bash, imho.
Solution 2:
Paste (Ctrl-Shift-V) the following into a terminal screen:
echo '"\e[A": history-search-backward' > ~/.inputrc
echo '"\e[B": history-search-forward' >> ~/.inputrc
echo 'set show-all-if-ambiguous on' >> ~/.inputrc
echo 'set completion-ignore-case on' >> ~/.inputrc
Exit (Ctrl-D) the terminal screen, then open Terminal again.
Now you can just type the first couple of characters, then press Up or Down to scroll through the filtered list
Solution 3:
Final Term
There is this very promising Terminal App Called Final Term. Among its many features, it also has a history of remebering commands, so that you can then select it. Here are some more features:
You can read more about it in this article.
Here is the the website from the creators. http://finalterm.org/
To Install it
sudo add-apt-repository ppa:versable/finalterm-daily
sudo apt-get update
sudo apt-get install finalterm
Warning
I have said that it is promising. The only issue is that it is at version 0.1. So some things like vim
and nano
don't work well yet. I have also noticed that it does not yet support Drag-and-Drop, and copy and paste. But it does have the feature you request. As the software matures, it will become one of the best terminals for the desktop.
Screenshot
Here is the function in action:
Hope this helps.
*I am on Saucy, so that is why I have a Salamander background :)