Ubuntu – Change Default TTY shortcut

12.04key-bindingshortcut-keystty

I would like to change the default shortcut to switch back and forth to the tty. By default it is ctrl + alt + F#. I have tried making a custom shortcut using Ubuntu's keyboard settings but it only worked while using the graphical interface when i switch back to tty it doesn't work. So I need to figure out how to change the default binding of the ctrl + alt + F# shortcut to make a single key toggle back and forth between two TTYs.

Best Answer

You can use bind to bind a key to some function. Here is what I did:

bind '"\ea": ". ~/newScript.sh\n" '

Here newScript.sh is the file which changes the tty and \ea means that whenever Alt+A is pressed, the script executes.

The contents of newScript.sh are:

#! /bin/bash
ttyNum="$(tty)"
ttyNum=$(echo ${ttyNum##*y})
ttyNum=$(( (ttyNum +1) % 7))
chvt $ttyNum

Note that if you want to store the key bindings permanently, you can store them in your `~/.inputrc' file. For more information, you can visit this link: http://www.techrepublic.com/article/find-and-bind-key-sequences-in-bash/5683375

Update: You can store the bind line in your ~/.bashrc file so that you don't have to do it again.

Related Question