You are right, this is not an OS X specific question. The answer is found in
bash, the standard shell on OS X (also included in most if not all Linux distros).
bash provides a built-in command called
bind that can be used to bind a key combination (like AltK) to a command (like
Open Terminal and type:
bind '"\ek":"ssh foo\n"'
This will bind the key combination
\ek (in Terminal both AltK and EscK) to the command
ssh foo. The
\n adds a return.
Now press AltK and
ssh foo will be executed (modify
ssh foo to your needs).
If you want this key combination to be automatically loaded when starting a Terminal create a file called
.inputrc in your home folder:
and open it:
open -e ~/.inputrc
You will see TextEdit open. Type:
and save it (or use your favorite editor). That's it!
There's much more to it than what I've explained here. I recommend that you have a look to this question: http://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command and check (the rather dry) section READLINE in
man bash. Notice that the escape sequence
\M-, which in other operating systems is mapped to Alt, doesn't work in Terminal. You need to use
\e to bind Alt.
Since escape sequences are terminal emulation dependent I'd like to share the setup I used to test the above command: