Apple - Moving .bash_profile to Dropbox

You can have additional file in Dropbox folder and then on every machine inside your .bash_profile file put this:

FILE="/path/to/DropboxFolder/shared_bash_profile_file"
if [ -f $FILE ];
then
    source $FILE
fi

It is not a good idea to put the whole .bash_profile in Dropbox, either by tweaking the Dropbox paths or through a symlink. Different machines may require slightly different content of this file. Examples: different software versions installed requiring different configuration, different paths, different names for things such as partitions under /dev/.

Do this instead: put all your customized functions and aliases in a file $HOME/Dropbox/my_functions.sh and then include the line

. $HOME/Dropbox/my_functions.sh

in your .bash_profile.


I think is better idea to upload to a repository. Let me tell you how I did it.

I version the whole ~/bin directory. My .bash_profile is on that directory. The $HOME/.bash_profile is a link to ~/bin/.bash_profile.

My .bash_profile looks like this:

if [[ $OSTYPE == darwin* ]]; then
    . ~/bin/includes/exports-osx.sh
    . ~/bin/includes/bash-stuff-osx.sh
    . ~/bin/includes/aliases-osx.sh
    . ~/bin/includes/functions-osx.sh
elif [[ $OSTYPE == linux* ]]; then
    . ~/bin/includes/exports-linux.sh
    . ~/bin/includes/terminal-linux.sh
    . ~/bin/includes/aliases-linux.sh
    . ~/bin/includes/ssh-keys-linux.sh
    . ~/bin/includes/bash-stuff-linux.sh
fi

. ~/bin/includes/bash-stuff.sh
. ~/bin/includes/aliases.sh
. ~/bin/includes/powerline.sh
. ~/bin/includes/functions.sh
. ~/bin/includes/work-stuff.sh

That way I can easilly track changes.

To keep the repo update you can create a cron or LaunchAgents script that pull the changes on your ~/bin directory once a day:

cd ~/bin && git pull origin $(git name-rev --name-only HEAD)