Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I work on a lot of different machines, all running Ubuntu (not always the same version). I have some really basic customizations to my prompt I would like to have available on all machines.

I currently use Dropbox and store all my other "dot files" there, such as my .vim/ .vimrc .gitconfig .ackrc. I then just link them to my home folder from my Dropbox folder. Voilà, all machines in sync.

I am unsure what the repercussions of doing something like this with my bashrc is. Can any one offer suggestions? Maybe an easy way to load a separate file in the bashrc?

share|improve this question
add comment

5 Answers

up vote 19 down vote accepted

I don't see any real repercussions, but I suppose it depends on what you have in there! If it's just quick aliases that work the same everywhere, and cosmetic stuff, I don't see any issues.

You could either just move your .bashrc to someplace in your Dropbox folder and then symlink it on each of the machines.

  mkdir -p ~/Dropbox/dotfiles
  mv ~/.bashrc ~/Dropbox/dotfiles/.bashrc
  ln -s ~/Dropbox/dotfiles/.bashrc ~/.bashrc

I actually have quite a few dotfiles in my home folder which are actually symlinks to shared folders in my Dropbox account.

Another option is that you could create a file inside your dropbox folder to be sourced by your .bashrc:

I.e., in your .bashrc, put:

source $HOME/Dropbox/dotfiles/bashrc-shared-settings

and then create a bashrc-shared-settings file which is the stuff you want used on all machines, and you can still keep separate .bashrc files.

(You can also abbreviate source as just . in bash.)

share|improve this answer
    
I do have my other dot files set up as per your example, I am just not so familiar with bash and was unsure how "special" all the default stuff Ubuntu puts in there is. I am going to go ahead and use the source method you suggested. Thank you! –  Alan Peabody Dec 1 '10 at 14:14
add comment

The main risk that I can think of is that you must remember that synchronization is not the same as backing up. Any mistakes will be synced to all of your machines.

To include a separate file in your ~/.bashrc add something like so:

if [ -f ~/.foo ]; then
    . ~/.foo
fi

Where ~/.foo is the separate file.

share|improve this answer
1  
You're right! But luckily, dropbox keeps revisions of your files, so stuff is backed up automatically :) –  Alex Dec 1 '10 at 3:51
    
Thanks for the great suggestion, I will be manually sourcing a second file and I will probably use this syntax. –  Alan Peabody Dec 1 '10 at 14:17
add comment

I keep my .bashrc symlinked in Dropbox along with lots of other config files (.gitconfig, .vimrc, etc).

I source a file called .bashrc_local at the end of it for other settings which I might want to keep machine independent.

if [ -f ~/.bashrc_local ]; then
    . ~/.bashrc_local
fi
share|improve this answer
add comment

Usually, centralizing configuration files is a good thing! If you want to customize what runs based off of a given OS or hostname, you can do something like the following in your .bashrc:

export HOSTNAME=`hostname | cut -f1 -d'.'`

if [ -f ~/.bash/os/$OSTYPE.sh ]; then
    source ~/.bash/os/$OSTYPE.sh
fi

if [ -f ~/.bash/host/$HOSTNAME.sh ]; then
    source ~/.bash/host/$HOSTNAME.sh
fi

Then, create a .bash directory and the os and host directories under that and put any custom settings in files called <whatever>.sh where <whatever> is the os type or the host you want customized.

I keep all of these files in dropbox, and I have a bash script called link_dropbox in my Dropbox folder that helps me to facilitate linking them in:

#!/bin/bash

#Array of <source><space><link> target->symlink mappings
linkarray=( "~/Dropbox/config/bashrc ~/.bashrc"
            "~/Dropbox/config/bash ~/.bash"
            "~/Dropbox/config/vimrc ~/.vimrc"
            "~/Dropbox/config/vim ~/.vim"
            "~/Dropbox/config/ssh ~/.ssh"
            "~/Dropbox/config/screenrc ~/.screenrc"
            "~/Dropbox/bin ~/bin" )

#turn off globbing to split each entry on spaces
set -f
for entry in "${linkarray[@]}"
do
    targets=( $entry )
    #eval will expand the tildes
    eval from=${targets[0]}
    eval to=${targets[1]}
        #if the target exists and is not a symlink, err on the side of caution
        if [ -e "$to" -a ! -L "$to" ]
        then
            echo "$to exists and is not a link, skipping..."
        else
            #probably safe to delete an existing symlink
            if [ -e "$to" ]
            then
                rm $to
            fi
            ln -s $from $to
        fi
done
share|improve this answer
add comment

Syncing with Dropbox is great, but if you don't want to install Dropbox on the server, you can implement my method.

  1. Create a file with your shared bash settings in your Dropbox folder.

  2. Right click the file and click "Share Link" from the Dropbox menu.

  3. Then click "Get Link." This will copy the shared link to your clipboard.

  4. Add ?dl=1 to the end of the shared file. This lets you get the raw file. Your shared link should now look similar to mine: https://dl.dropbox.com/s/h25q5c3czo6mnjo/shared_bash_settings.sh?dl=1

  5. Add this line to ~/.bashrc

    source $HOME/.bash_shared_settings

  6. Create a cronjob with your preferred interval using this command (Replace with your Dropbox Shared File!)

    */30 * * * * curl -sS https://dl.dropbox.com/s/h25q5c3czo6mnjo/shared_bash_settings.sh?dl=1 > ~/.bash_shared_settings; chmod +x ~/.bash_shared_settings;

This will update your copy of ~/.bash_shared_settings every half an hour. Every time you reload your session, you'll include the latest changes.

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.