Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am currently storing most of my dotfiles in a git repository to make keeping them in sync across all my computers easier. I've just recently acquired a Macbook so now have to have all my dotfiles supporting the differences between Linux and Darwin. The first incompatability that I have encountered is colour coding ls, in Linux this is the flag --color=auto and for Darwin it is -G.

My first attempt at making my .zshrc portable is to do the following:

case `uname` in
  Darwin)
    alias ls='ls -FG'
    ;;
  Linux)
    alias ls='ls -F --color=auto'
    ;;
esac

Once I find a few more things to change I'll probably pull the computer specific stuff out to separate files to keep it a bit cleaner. What I'm mainly wondering is if there is a better way to do this other than using `uname` to determine which stuff to run.

share|improve this question
add comment

1 Answer

I used to use this mechanism:

envfile="$HOME/.bash/os.`uname`.sh"
if [ -r $envfile ]; then
    . $envfile
fi
envfile="$HOME/.bash/host.`uname -n`.sh"
if [ -r $envfile ]; then
    . $envfile
fi

Then I could rsync the .bash directory around to each machine as needed to keep all up to date.

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.