Terminal prefix search when hitting up

terminal

#1

I’m coming from Nitrious.io, and the terminal there had a nice feature relating to hitting the up arrow key in the terminal. Right now hitting up simply goes to the previous command in the history reguardless of anything else (as far as I can tell). It would be really nice if it actually did a prefix search on your command histry based on what you’ve already typed. Here is example of some stuff I might type in Rails.

rake db:migrate
git push
git push heroku master
heroku run rake db:migrate
rails s -b $IP -p $PORT
git add -A
git commit -m "added stuff"
git push

Now at this point I’d like to have the following:

  • If I simply hit up it should show git push
  • If I type git push then hit up it’ll show git push heroku master
  • If I type rails s and hit up it’ll show rails s -b $IP -p $PORT
  • If I type rake and hit up it’ll show rake db:migrate
  • If I type heroku run and hit up it’ll show heroku run rake db:migrate

This would save a fair bit of typing at the terminal.

As a secondary related feature, I would be nice to be able to select the text in the terminal type delete, and it would delete the selected text. This is so you can type some stuff, quickly clear it then hit up if you just want the previous command.


#2

Interesting thought, though this is unexpected behavior for everyone that has used a standard *nix terminal (if I’m not mistaken). You can get similar functionality by hitting Ctrl+R and then typing in something like sudo. To find the next result back, just hit Ctrl+R again until you find what you’re looking for.


#3

Fair point.

Another option would be to use a modifier key such as hold shift + up, which is probably even better than I had in mind.

I’ve gotten around this somewhat by setting up aliases for commands in the ~ folder. However, not everyone’s going to take the time to setup aliasing and this method still seems rather nice. It also means I ended up setting up a favorite for my aliases file just so I had easy access to them for reference. Since, a number of them are ones I’ve found online.