12

I have tons of stuff in my .bash_profile. The problem is, I use ~3 computers very frequently, and I'm tired of having to copy paste my prefs everywhere. Two of them run Ubuntu 10.10, and one runs OSX. I was wondering if there was a way to use Dropbox, to share a single prefs file. Like, when bash starts, tell it to check ~/Dropbox/Bash/.bash_profile ?

Although, could I also tell emacs to look in ~/Dropbox/Emacs/.emacs somehow?

  • 2
    Clever question! – msanford Dec 21 '10 at 4:33
  • I can't seem to comment on the (great) selected answer. I don't know if this is something specific to osx/mac but I needed to make a couple of changes for it to work DROPBOX_PROFILE='~/Dropbox/Bash/.bash_profile' if [ -f $DROPBOX_PROFILE ]; then . $DROPBOX_PROFILE fi Should be DROPBOX_PROFILE="$HOME/Dropbox/Bash/.bash_profile" if [ -f $DROPBOX_PROFILE ]; then . $DROPBOX_PROFILE fi Hope that helps. – Jason Jan 26 '11 at 1:45
  • Just to make it clearer: @Jason's tweaks are to replace the single-quotes with double-quotes and to replace '~' with '$HOME' in the definition of DROPBOX_PROFILE – sprugman Dec 11 '11 at 19:30
17

~/.bash_profile

DROPBOX_PROFILE='~/Dropbox/Bash/.bash_profile'
if [ -f $DROPBOX_PROFILE ]; then
    . $DROPBOX_PROFILE
fi

~/.emacs

(load "~/Dropbox/Emacs/.emacs")
| improve this answer | |
  • 3
    I personally feel that source is more readable (and googlable) than the dot operator, but it is your answer and so I will not edit it. Other than that, +1 for a good answer. – Hello71 Jan 26 '11 at 1:13
  • @Hello71 Can you elaborate on source a bit. I'm intrigued. Thanks! – Joshua Pinter Apr 11 '19 at 19:51
  • @Hello71 Ah, I think I know what you mean now. And I completely agree. using . is much more cryptic than using source. – Joshua Pinter Apr 11 '19 at 19:52
  • If you have a space in your path, like when you have a business Dropbox and want to use your personal one, e.g. Dropbox (Personal), you'll need to use double quotes when referencing the variable, like "$DROPBOX_PROFILE". – Joshua Pinter Apr 13 '19 at 21:35
6

How about this, which avoids having special config files that source the Dropbox versions?

$ ln -s ~/Dropbox/Bash/.bash_profile ~/.bash_profile
$ ln -s ~/Dropbox/Emacs/.emacs ~/.emacs
| improve this answer | |
5

In your regular .bash_profile, just call ~/Dropbox/Bash/.bash_profile.

#.bash_profile
. ~/Dropbox/Bash/.bash_profile # the '.' command runs a file.

Actually, you probably want to call the shared file something else, or at least not make it a hidden file.

| improve this answer | |
3

I think this would get what you want, just check to see if the file exists, if so, source it.

in $HOME/.bash_profile

[ -f $HOME/Dropbox/Bash/.bash_profile ] && source $HOME/Dropbox/Bash/.bash_profile
| improve this answer | |
1

Also check out "homeboy" for general development machine sync'ing and updating: https://github.com/preston/homeboy

| improve this answer | |
0

comment to: https://superuser.com/a/224204/401026 (Answer of Andrejs Cainikovs)

my changes for macOS 10.12.6 Sierra, iTerm2 Build 3.2.0, Terminal Version 2.7.3 (388.1.1):
- replaced tilde
- replace single quotes by double quotes

DROPBOX_PROFILE="/Users/xxx/Dropbox/Bash/.bash_profile"
if [ -f $DROPBOX_PROFILE ]; then
    . $DROPBOX_PROFILE
fi

sorry: I couldn't write comments, so I have to add another answer

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.