Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'd like to have the same keyboard shortcuts in all the terminals I use. Since they don't have the same *nix on them, and since terminals can be very different, I'm looking for a reasonably portable way to get keyboard shortcuts from one *nix terminal (at least supported by a standard Ubuntu 12.04 installation) to other terminals (Bash only).

That is, I'm trying to generate commands in one terminal to execute on another terminal, in order to use the same keyboard shortcuts in the second terminal. Especially things like Alt-Del (delete the word to the right of the cursor) and Ctrl-Left (move the cursor one word to the left), which on some hosts I work on simply prints the escape code instead of performing the expected actions.

This is also meant as a precursor to possibly changing the .inputrc on the target host. The important points are to be able to

  1. Figure out which keyboard shortcuts are defined on my local host.
  2. Figure out whether any commonly used shortcuts are not defined from the remote host.
  3. Copy the shortcut definitions to the remote host.
  4. Verify that the shortcuts work as expected on the remote host.
  5. Be reasonably sure that the shortcuts would also work on a third host, possibly with very old versions of Bash and standard tools like grep and sed.
share|improve this question
    
I have no idea what you're trying to do. Your answer doesn't clarify this: there's no variable part, so why aren't you writing those bind instructions in your .bashrc or .inputrc? –  Gilles Oct 17 '12 at 22:34
    
@Gilles Clarified. Also, I can't just modify the .bashrc or .inputrc on these servers - They are used by others and monitored for any changes. –  l0b0 Oct 18 '12 at 5:47
    
Looks like different OS ships different shell, if you install the same shell, wouldn't it solve the problem? –  warl0ck Oct 18 '12 at 5:50
    
@warl0ck: One is running Bash 3.00.16(1) and the other 4.2.24(1), but I can't just install another shell on these machines either. –  l0b0 Oct 18 '12 at 7:37

1 Answer 1

up vote 0 down vote accepted

The current solution is as follows:

bind -p | grep -ve '^$' -e '^#' -e 'self-insert$' | sed -e "s/\(.*\)/bind '\1'/" | tr -s '\n' ';'

This produces a single line like this:

bind '"\C-g": abort';bind '"\C-x\C-g": abort';[...];bind '"\e\C-y": yank-nth-arg';bind '"\ey": yank-pop';

This seems to work, but I'm not sure if it's portable.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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