Assign function keys to your frequent commands

bind '"<ctrl+v><functionKey>":"command\n"'
This is a common use of bind. Hitting any key after will output the key's character sequence. This makes possible using it into a bind command. So pressing ctrl+v and then F2 will output "^[[12~", once binded every time you'll press the function key F2 it will execute your command. Added the \n to make it execute it as well.
Sample Output
bind '"<ctrl+v><F2>":"ps aux\n"'

root      1826  0.0  0.3 116536  3400 pts/0    Ss   16:41   0:02 -bash
chrony    1952  0.0  0.1  24728  1476 ?        S    17:14   0:00 /usr/sbin/chronyd 
root      6543  0.0  0.0      0     0 ?        R    19:38   0:00 [kworker/0:3]
root      6560  0.0  0.0      0     0 ?        S    19:46   0:00 [kworker/0:0]
root      6572  0.0  0.0      0     0 ?        S    19:51   0:00 [kworker/0:1]
root      6574  0.0  0.0      0     0 ?        S    19:55   0:00 [kworker/0:2]
root      6575  0.0  0.1 123372  1388 pts/0    R+   19:57   0:00 ps aux

By: nnsense
2015-05-11 17:59:09

2 Alternatives + Submit Alt

What Others Think

Useful. Personally I prefer aliases/functions. It's easier to remember p for ps rather than, say, . . I suggest editing your description, though to make it clear *what* gets typed into the command. i.e. Control and V, then Function-Key, not '
flatcap · 284 weeks and 3 days ago
Good point, description modified.
nnsense · 284 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: