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?

weemattisnot
  • 889
  • 5
  • 16

1 Answers1

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!

vasili111
  • 6,032
  • 10
  • 50
  • 80
egmont
  • 581
  • 3
  • 11
  • 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? – weemattisnot Apr 22 '15 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 '15 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). – weemattisnot Apr 23 '15 at 14:46
  • "You can determine the character sequence emitted by a key by pressing Ctrl-v..." See: http://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command – AAAfarmclub Jan 22 '17 at 10:55