0

I use a terminal for just about everything. There are a few commands that I often execute within a directory like:

emacs main.tex
evince main.pdf

It may seem silly, I'd like to be able to run a set of commands like this with a single keystroke. Is there any way to map (say) F9 to write a specific sequence of characters to an open gnome terminal?

1 Answer 1

1

gnome-terminal doesn't have such a feature, but you might configure bash (actually, readline) to insert a certain string for a given key. Edit ~/.inputrc or /etc/inputrc and add such lines:

"\e[19~": "emacs main.tex"
"\e[20~": "evince main.pdf"

Watch out: When you press F8 or F9, these will do exactly the same as if you've typed those characters; no matter what the context is. E.g. if you type rm and then press space, F8, Enter, you'll remove your main.tex!

4
  • Awesome! Is there a way to add a carriage return to the end? Where do you find the escape codes for the f-keys? And can you add modifiers to the keys, like shift-F9? Apr 22, 2015 at 22:21
  • 1
    Newline can be added as \n. To figure out the escape codes (even with modifier), the easiest method is to launch a cat command, and then press the desired key. You'll need to replace the initial ^[ by \e but the rest stays the same. Note that these sequences might vary across terminals, but if they do, you can add multiple versions to your inputrc.
    – egmont
    Apr 22, 2015 at 22:27
  • 1
    I needed to add $include /etc/inputrc to the top of my .inputrc file to keep the default quick-keys (like C-a taking me to the start of the line). Apr 23, 2015 at 14:46
  • "You can determine the character sequence emitted by a key by pressing Ctrl-v..." See: stackoverflow.com/questions/4200800/… Jan 22, 2017 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.