Feeling At Home On Someone Else's Server (January 17, 2013)

I used to do crazy stuff to setup my Unix environment. Back when I was working at Tadpole, I had a Python script that would generate a .profile with paths that existed. Madness!

At Bouygues Telecom I saw the light. Actually I saw it when I finished working there, but that's another story .

The project I was working on had a regression test suite that was written entirely in shell. This made me realize that it was sufficiently powerful to setup my environment. So I started using bash or ksh to setup binary paths, ls colors, etc...

Later, I started using zsh and now there is no way I am going back to bash. I think of it as the emacs of shells. It comes with the kitchen sink.

Anyway to get to the point of this blog, these days to feel at home on a server I only need two configuration files:

When I am sharing an account .zshrc is usually OK as everyone else uses bash. However my .vimrc is problematic as it messes the other users editing experience. They will notice the colors are not right on their white background.

This is what I do to keep everyone happy. I renamed .vimrc to .vimrc-ivan and do the following in .zshrc to load it up:

# setup which vi to use
which vim > /dev/null 2>&1
if test $? -eq 0 ; then
    export EDITOR=vim
    if test -f ${HOME}/.vimrc-ivan ; then
        alias vi="vim -u ${HOME}/.vimrc-ivan"
    else
        alias vi=vim
    fi
else
    export EDITOR=vi
fi

In the same vein I want to run zsh on the server when I login. I can't change the shell of the account, that would also annoy people. I simply alias ssh in .zshrc:

# change host name in screen
ssh () {
    if [[ $1 -regex-match  '(redmine.*|jenkins.*)' ]] ; then
        # start zsh on servers that don't belong to me
        /usr/bin/ssh $* -t exec zsh
    else
        /usr/bin/ssh $*
    fi
    if test x${TERM} = xscreen ; then
        printf "\033k`hostname -s`\033\\\\"
    fi
}

Now when I ssh to a server I have the prompt I like and I can edit files the way I want to. All this without irritating others is a boon. It's time to hack and be merry!

back