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.

We have a bunch of servers set up with set -o vi in their ~/.bashrc.

It would be nice to be able to ssh into these boxes and automagically run set -o emacs as a timesave.

I've seen a solution indicating that such additions should be made on the remote host ~/.bashrc but we cannot modify these for various reasons.

Another solution suggests using:

spawn ssh -t user@host "set -o emacs; /bin/bash -i"

..but I understand this requires running the expect shell instead of plain bash.

Is there a simple way to achieve this goal? Any suggestions would be very much appreciated.

share|improve this question
    
Is there an issue changing ~/.bashrc? –  Karlson Nov 13 '12 at 16:38
    
What is the expect shell? I know of the expect TCL-based command language often (mis?)used to automate secure logons and such - is this what you mean? Also - and this is a shot in the dark - but how do you find ssh user@host '( set -o ; /bin/bash -i /otherrc )' works for you? –  mikeserv Mar 30 at 14:02
add comment

3 Answers

ssh -t user@host bash -o emacs -i
share|improve this answer
    
This doesn't work unfortunately. –  KomodoDave Nov 13 '12 at 18:27
1  
Because there's a command in .bashrc that overrides it? Add --norc, or --rcfile yourfile.rc instead. –  Jim Paris Nov 13 '12 at 19:19
    
As I said in my original post there is set -o vi in every server .bashrc. I did as you suggested, inserting --norc immediately after bash in your above command. The parameter was clearly applied since the bash prompt presented appeared different, however emacs keybindings were still not enabled. –  KomodoDave Nov 14 '12 at 13:12
1  
If you have set -o vi in your profile files too (or they source .bashrc), you might need: ssh -t user@host bash --norc --noprofile -o emacs -i –  Jim Paris Nov 14 '12 at 15:53
    
Thank you for yet another suggestion Jim. Unfortunately this one didn't work either! I'm thinking this may not be possible, it's certainly frustrating to have tried so many approaches without success. –  KomodoDave Nov 14 '12 at 15:58
show 1 more comment

Start bash with the --rcfile option and specify a different bashrc. For example, write a file called ~/.bashrc-emacs that contains

. ~/.bashrc
set -o emacs

and run

ssh -t user@host bash --rcfile=.bashrc-emacs

You can use --norc to skip reading /etc/bash.bashrc and ~/.bashrc altogether. Bash is in emacs mode by default.

If you do want to read the remote .bashrc and you don't want to write to any file on the server, I think expect is your best bet.

share|improve this answer
    
Or even something like grep -v 'set -o vi' /etc/bash.bashrc | ( exec bash -i <&0 ) might work. –  mikeserv Mar 30 at 14:08
add comment

I realize you mentioned not to edit .bashrc. However, I hope this might help someone else. I have been looking for a good answer to a similar problem for many years. I like to use vi but don't want to change the default for everyone else.

Edit /etc/ssh/ssh_config in your local configuration and add the following line:

SendEnv EDITOR

You can use any environment variable but EDITOR seems like a good choice. In my case EDITOR is set to vim.

In the remote system, edit /etc/ssh/sshd_config and add the following line:

AcceptEnv EDITOR

Edit .bashrc or .bash_profile and add the following:

if [ "$EDITOR" = "vim" ]; then
         set -o vi;
fi

For the use case in this question, replace vi with emacs. Note: You might need to restart sshd in the target system.

share|improve this answer
add comment

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.