在计算机之间同步 bash 配置文件

Jos*_*osh 14 linux terminal .bash-profile macos

我的 .bash_profile 中有很多东西。问题是,我经常使用 ~3 台计算机,而且我厌倦了将我的首选项复制粘贴到任何地方。其中两个运行 Ubuntu 10.10,一个运行 OSX。我想知道是否有办法使用 Dropbox 来共享单个 prefs 文件。比如,当 bash 启动时,告诉它检查~/Dropbox/Bash/.bash_profile?

虽然,我也可以告诉 emacs 以~/Dropbox/Emacs/.emacs某种方式查看吗?

And*_*ovs 18

~/.bash_profile

DROPBOX_PROFILE='~/Dropbox/Bash/.bash_profile'
if [ -f $DROPBOX_PROFILE ]; then
    source $DROPBOX_PROFILE
fi
Run Code Online (Sandbox Code Playgroud)

~/.emacs

(load "~/Dropbox/Emacs/.emacs")
Run Code Online (Sandbox Code Playgroud)

  • 我个人觉得 `source` 比点运算符更易读(和谷歌搜索),但它是你的答案,所以我不会编辑它。除此之外,+1 是一个很好的答案。 (4认同)

gar*_*ohn 6

这样可以避免使用特殊的配置文件作为 Dropbox 版本的来源吗?

$ ln -s ~/Dropbox/Bash/.bash_profile ~/.bash_profile
$ ln -s ~/Dropbox/Emacs/.emacs ~/.emacs
Run Code Online (Sandbox Code Playgroud)


小智 5

在您的常规 .bash_profile 中,只需调用 ~/Dropbox/Bash/.bash_profile。

#.bash_profile
. ~/Dropbox/Bash/.bash_profile # the '.' command runs a file.
Run Code Online (Sandbox Code Playgroud)

实际上,您可能想将共享文件称为其他名称,或者至少不要将其设为隐藏文件。