跨多个计算机管理用户配置文件

时间:2022-06-20 10:53:53

I commonly work on multiple computers. I have various configuration files, eg, .bashrc, .gitconfig, .irbrc, .vimrc and configuration folders, eg, .vim/ that contain valuable customizations. Sometimes I want small variations in configuration between the different computers.

我通常在多台电脑上工作。我有各种配置文件,例如.bashrc, .gitconfig, .irbrc, .vimrc和配置文件夹,例如,.vim/包含有价值的自定义。有时我想在不同的计算机之间配置一些细微的配置。

I want to use version control to manage these different files.

我想使用版本控制来管理这些不同的文件。

  • do others use version control to manage their configuration files?
  • 其他人是否使用版本控制来管理他们的配置文件?
  • what are some hints that might make this easier?
  • 有什么提示可以让这一切变得更容易?
  • what's the most elegant way of dealing with variations between the computers?
  • 处理计算机之间的差异最优雅的方式是什么?
  • I'm comfortable with git; any other suggestions?
  • 我与git舒适;还有其他的建议吗?

11 个解决方案

#1


17  

I keep a folder at ~/config/ which is a bzr repository. I push/pull the repository between my various computers to sync it up. I have an install script which I use to make symlinks to my home directory:

我在~/config/这是一个bzr存储库。我在不同的计算机之间推/拉存储库来同步它。我有一个安装脚本,我使用它来创建到我的主目录的符号链接:

#! /bin/sh
# link all files to the home directory, asking about overwrites
cd `dirname $0`
SCRIPT_DIR=`pwd`
SCRIPT_NAME=`basename $0`
FILES=`bzr ls --versioned --non-recursive`

cd $HOME
for FILE in $FILES; do
    ln --symbolic --interactive $SCRIPT_DIR/$FILE
done
rm $TARGET_DIR/$SCRIPT_NAME

If you want to use git instead of bzr, you can instead use:

如果你想使用git bzr,而是相反,可以使用:

FILES=`git ls-tree --name-only HEAD`

(I had to ask SO to figure that out)

(我不得不问)

EDIT: I don't actually do this anymore, now I have a dotfiles repo on github, with a nice rake install script that someone else wrote.

编辑:我实际上不再这样做了,现在我在github上有了一个dotfiles repo,它有一个别人编写的漂亮的rake安装脚本。

#2


14  

At the moment, I use a cloned git repo. To keep things simple, the only file that needs to vary between the different machines is .bashrc. It's nice if there can be just one version of this file that responds differently on different machines. Thus, in my .bashrc:

目前,我使用一个克隆的git repo。为了保持简单,在不同的机器之间唯一需要改变的文件是.bashrc。如果这个文件只有一个版本在不同的机器上响应不同,那就太好了。因此,在我. bashrc:

if [ $(hostname) == 'host1' ]; then
     # things to do differently on host1.
elif [ $(hostname) == 'host2' ]; then
     # things to do differently on host2.
fi

This obviously has some limitations (such as that a different technique would be required for .vimrc or other config files needing customization), but it works fairly well.

这显然有一些限制(例如,一种不同的技术将所需. vimrc或其他配置文件需要定制),但是它很有效。

#3


3  

With CfEngine you can manage config files across machines and do also many more things! The learning curve is maybe a bit high but worth it if you have to manage/update/maintain a pool of computers running linux regularly.

使用CfEngine,您可以跨机器管理配置文件,并做更多的事情!学习曲线可能有点高,但如果您必须管理/更新/维护一个定期运行linux的计算机池,那么它是值得的。

#4


2  

If you use git, you could define an "origin" repo to be the master; and then do a clone on each computer you work. you could use a branch for every computer to have your set of config files.

如果你使用git,你可以定义一个“起源”回购主;然后做一个克隆在每台计算机的工作。您可以使用一个分支为每台计算机的配置文件。

#5


2  

Easy. Use DropBox for that: http://www.nixtutor.com/linux/sync-config-files-across-multiple-computers-with-dropbox/

一件容易的事。使用DropBox来实现这一功能:http://www.nixtutor.com/linux/sync-config- fils-acrossmulticomputers-with-dropbox/。

#6


2  

I use slack for a similar situation. slack allows definition of roles/subroles so you can manage files with small variation either through a cloned file or patch. The slack directory is then managed by git in my deployment.

我在类似的情况下使用slack。slack允许定义角色/子角色,因此您可以通过克隆文件或补丁来管理变化不大的文件。然后,在我的部署中,slack目录由git管理。

#7


2  

Here are some dotfile managers:

以下是一些点文件管理器:

  • homesick: Based on Ruby
  • 家:基于Ruby
  • homeshick: Same as first one, but without ruby dependency
  • homeshick:和第一个一样,但是没有ruby依赖
  • dfm: Written in Perl
  • dfm:用Perl编写的

#8


1  

git with branches for custom computers, with automated sync at login seems like a good solutions to me.

git为定制计算机提供分支,在登录时自动同步,这对我来说是一个很好的解决方案。

I've used etckeeper for versioning configurations, but I've never actually expanded to user configurations.

我使用了etckeeper来进行版本配置,但是我从来没有扩展到用户配置。

#9


1  

This kind of question comes up occasionally, and I've never seen a tool to handle this common use case, so I wrote a script that uses git and symlinks to manage these files.

这种问题偶尔会出现,我从来没有见过处理这种常见用例的工具,所以我编写了一个脚本,使用git和symlinks来管理这些文件。

See http://github.com/bstpierre/dotfiles

参见http://github.com/bstpierre/dotfiles

It is not perfect. There is currently a bug related to handling directories, and there is no support yet for variations across computers.

它不是完美的。目前有一个与处理目录相关的错误,而且在计算机上也没有对变化的支持。

Before using any tool of this nature, make sure you have good backups!

在使用任何此类工具之前,请确保您有良好的备份!

#10


1  

I think what you want could be similar to what I've been doing...

我觉得你想要的和我做的一样……

Make a directory in home called .host_configs/ . This is version controlled. Or in my case it lives in a special folder on a central computer, I scp it down on any new machine. Inside it make a folder for every host that you want different configurations for. The folder for each host should be named after the short hostname for that machine. So in your git repo you have:

在home创建一个名为.host_configs/的目录。这是版本控制。或者在我的例子中,它住在*计算机的一个特殊的文件夹里,我在任何一台新机器上都能找到它。在它里面为每个你想要不同配置的主机创建一个文件夹。每个主机的文件夹应该以该机器的短主机名命名。所以在你的git里,你有:

.host_configs/
           homecomp1/
           girlfriendcomp1/
           workcomp1/
           workcomp2/

In each host specific folder, put the .vimrc, .irbrc, etc., configuration files for that specific box. And also, in each host folder make a file called .[SHORT_HOST]_rc. For instance, if your machine is name "sane" have a file named .sane_rc ... This file will contain the lines that would normally be in .bashrc that are unique to that host. For instance, if it's a mac and it needs alias ls='ls -GF' instead of alias ls='ls --color=auto' which works for most nix machines for ls with colors, put that line in the .[SHORT_HOST]_rc for that machine, along with whatever special functions, declarations, etc, that would normally go into the .bashrc or .profile etc. (or .zshrc, .tschrc, as the case may be). So the version controlled ~/.host_configs/ folder looks like:

在每个主机特定文件夹中,放置.vimrc、.irbrc等特定框的配置文件。并且,在每个主机文件夹中创建一个名为.[SHORT_HOST]_rc的文件。例如,如果您的机器名为“sane”,则有一个名为.sane_rc的文件…这个文件将包含通常位于.bashrc中的、该主机唯一的行。例如,如果它是一个mac和它需要别名ls = ' ls女朋友而不是别名ls = ' ls -颜色=汽车的工作对于大多数nix ls的机器颜色,把这条线。[SHORT_HOST]_rc机,以及任何特殊函数声明、等,通常会进入. bashrc或. profile等。(或. zshrc .tschrc,视情况而定)。所以版本控制了~/。host_configs /文件夹看起来像:

.host_configs/
           homecomp1/
                    .homecomp1_rc        #special shell configs for this hostname
                    .vimrc               #you know the rest
                    .irbrc
                    .Xresources
           girlfriendcomp1/
                    .girlfriendcomp1_rc
                    .vimrc
                    .bubblebathrc
           workcomp1/
                    .workcomp1_rc
                    .bashrc
                    .vimrc
           workcomp2/
                    .workcomp2_rc
                    .bashrc
                    .vimrc

I use all the same barebones $HOME/.bashrc (or ~/.tshrc etc) on all of my machines. I just take the basic one that comes with the distro in question and move all of the host-specific configuration into the .host-configs/[SHORT_HOST]/.[SHORT_HOST]_rc file.

我用的都是同样的不义之财。bashrc(或(~ /。tshrc等)在我所有的机器上。我只使用与发行版相关的基本配置,并将所有特定于主机的配置移到.host-configs/[SHORT_HOST]/中。[SHORT_HOST]_rc文件。

Put this at the bottom (of $HOME/.bashrc):

把这个放在底部($HOME/.bashrc):

export SHORT_HOST="sane"
for file in `find ~/.host_configs/$SHORT_HOST -name ".*"`
do
ln -s $file `basename $file`
done
source ~/`.$SHORT_HOST`_rc

(Finds all of the dot-files for the host and makes a symlink in home to the~/.host_configs/foo_host folder). Your dot files are in their normal location but they are symlinked to version control. The above also sources all of the lines in your [$SHORT_HOST]_rc file into .bashrc

(查找主机的所有点文件,并在主页中创建一个symlink)。host_configs / foo_host文件夹)。您的点文件在它们的正常位置,但是它们是与版本控制相关的。上面的内容还将[$SHORT_HOST]_rc文件中的所有行都转换为.bashrc

You can commit back to git from the ~/.host_configs/ folder whenever you have changes.

您可以从~/提交回git。当您有更改时,host_configs/文件夹。

That's what it looks like in shell, which is probably all you need, but if you need other features, I would write something that uses the same principles (sourcing an external .rc file into .bashrc and symlinking all the config files to the structured version control folder) in something more versatile/less ugly than shell. So instead of the above in your .bashrc, there could be:

壳牌的样子,可能是你所需要的,但是如果你需要其他的功能,我想写点东西,使用相同的原则(采购外部.rc文件. bashrc并将所有的配置文件结构化版本控制文件夹)在一些更通用的丑陋/低于壳。因此,在你的。bashrc中,可以有以下内容:

export SHORT_HOST="sane"
ruby ~/import_conf.rb $SHORT_HOST

...and write your import_conf.rb to do more complex conf management, like placing a specific configuration file in some directory besides home, or handling a config folder like .ssh/, .subversion/ etc. That's what I do, it's pretty elegant for me, but there may be better solutions. Dropbox with some creative symlinks is also an excellent idea, though you're relying on a third party, and you need to be in a graphical environment. Also note there are inconsistencies between what you can do with symlinks + dropbox in Linux and shortcuts + dropbox in Windows if you implement something that wants to play with Windows.

…和编写import_conf。rb进行更复杂的conf管理,比如在home之外的某个目录中放置特定的配置文件,或者处理.ssh/、.subversion/等配置文件夹。Dropbox拥有一些有创意的符号链接也是一个不错的主意,尽管你需要依赖第三方,而且你需要在一个图形化的环境中。同样要注意的是,如果你实现了想要在Windows上运行的东西,你可以使用Linux中的symlinks + dropbox和Windows中的快捷方式+ dropbox之间的不一致性。

#11


0  

Now there is also vcsh

现在还有vcsh

From the README:

的自述:

vcsh - manage config files in $HOME via fake bare git repositories

vcsh -通过假的裸git库管理$HOME中的配置文件

[...]

[…]

vcsh allows you to have several git repositories, all maintaining their working trees in $HOME without clobbering each other. That, in turn, means you can have one repository per config set (zsh, vim, ssh, etc), picking and choosing which configs you want to use on which machine.

vcsh允许您拥有几个git仓库,它们都在$HOME中维护工作树,而不会互相造成破坏。反过来,这意味着您可以拥有每个配置集(zsh、vim、ssh等)的一个存储库,选择您想要在哪台机器上使用的配置。

Works perfectly, but may be a bit daunting if you are not an experienced git user.

如果您不是一个有经验的git用户,那么可以很好地工作,但是可能会有些困难。

#1


17  

I keep a folder at ~/config/ which is a bzr repository. I push/pull the repository between my various computers to sync it up. I have an install script which I use to make symlinks to my home directory:

我在~/config/这是一个bzr存储库。我在不同的计算机之间推/拉存储库来同步它。我有一个安装脚本,我使用它来创建到我的主目录的符号链接:

#! /bin/sh
# link all files to the home directory, asking about overwrites
cd `dirname $0`
SCRIPT_DIR=`pwd`
SCRIPT_NAME=`basename $0`
FILES=`bzr ls --versioned --non-recursive`

cd $HOME
for FILE in $FILES; do
    ln --symbolic --interactive $SCRIPT_DIR/$FILE
done
rm $TARGET_DIR/$SCRIPT_NAME

If you want to use git instead of bzr, you can instead use:

如果你想使用git bzr,而是相反,可以使用:

FILES=`git ls-tree --name-only HEAD`

(I had to ask SO to figure that out)

(我不得不问)

EDIT: I don't actually do this anymore, now I have a dotfiles repo on github, with a nice rake install script that someone else wrote.

编辑:我实际上不再这样做了,现在我在github上有了一个dotfiles repo,它有一个别人编写的漂亮的rake安装脚本。

#2


14  

At the moment, I use a cloned git repo. To keep things simple, the only file that needs to vary between the different machines is .bashrc. It's nice if there can be just one version of this file that responds differently on different machines. Thus, in my .bashrc:

目前,我使用一个克隆的git repo。为了保持简单,在不同的机器之间唯一需要改变的文件是.bashrc。如果这个文件只有一个版本在不同的机器上响应不同,那就太好了。因此,在我. bashrc:

if [ $(hostname) == 'host1' ]; then
     # things to do differently on host1.
elif [ $(hostname) == 'host2' ]; then
     # things to do differently on host2.
fi

This obviously has some limitations (such as that a different technique would be required for .vimrc or other config files needing customization), but it works fairly well.

这显然有一些限制(例如,一种不同的技术将所需. vimrc或其他配置文件需要定制),但是它很有效。

#3


3  

With CfEngine you can manage config files across machines and do also many more things! The learning curve is maybe a bit high but worth it if you have to manage/update/maintain a pool of computers running linux regularly.

使用CfEngine,您可以跨机器管理配置文件,并做更多的事情!学习曲线可能有点高,但如果您必须管理/更新/维护一个定期运行linux的计算机池,那么它是值得的。

#4


2  

If you use git, you could define an "origin" repo to be the master; and then do a clone on each computer you work. you could use a branch for every computer to have your set of config files.

如果你使用git,你可以定义一个“起源”回购主;然后做一个克隆在每台计算机的工作。您可以使用一个分支为每台计算机的配置文件。

#5


2  

Easy. Use DropBox for that: http://www.nixtutor.com/linux/sync-config-files-across-multiple-computers-with-dropbox/

一件容易的事。使用DropBox来实现这一功能:http://www.nixtutor.com/linux/sync-config- fils-acrossmulticomputers-with-dropbox/。

#6


2  

I use slack for a similar situation. slack allows definition of roles/subroles so you can manage files with small variation either through a cloned file or patch. The slack directory is then managed by git in my deployment.

我在类似的情况下使用slack。slack允许定义角色/子角色,因此您可以通过克隆文件或补丁来管理变化不大的文件。然后,在我的部署中,slack目录由git管理。

#7


2  

Here are some dotfile managers:

以下是一些点文件管理器:

  • homesick: Based on Ruby
  • 家:基于Ruby
  • homeshick: Same as first one, but without ruby dependency
  • homeshick:和第一个一样,但是没有ruby依赖
  • dfm: Written in Perl
  • dfm:用Perl编写的

#8


1  

git with branches for custom computers, with automated sync at login seems like a good solutions to me.

git为定制计算机提供分支,在登录时自动同步,这对我来说是一个很好的解决方案。

I've used etckeeper for versioning configurations, but I've never actually expanded to user configurations.

我使用了etckeeper来进行版本配置,但是我从来没有扩展到用户配置。

#9


1  

This kind of question comes up occasionally, and I've never seen a tool to handle this common use case, so I wrote a script that uses git and symlinks to manage these files.

这种问题偶尔会出现,我从来没有见过处理这种常见用例的工具,所以我编写了一个脚本,使用git和symlinks来管理这些文件。

See http://github.com/bstpierre/dotfiles

参见http://github.com/bstpierre/dotfiles

It is not perfect. There is currently a bug related to handling directories, and there is no support yet for variations across computers.

它不是完美的。目前有一个与处理目录相关的错误,而且在计算机上也没有对变化的支持。

Before using any tool of this nature, make sure you have good backups!

在使用任何此类工具之前,请确保您有良好的备份!

#10


1  

I think what you want could be similar to what I've been doing...

我觉得你想要的和我做的一样……

Make a directory in home called .host_configs/ . This is version controlled. Or in my case it lives in a special folder on a central computer, I scp it down on any new machine. Inside it make a folder for every host that you want different configurations for. The folder for each host should be named after the short hostname for that machine. So in your git repo you have:

在home创建一个名为.host_configs/的目录。这是版本控制。或者在我的例子中,它住在*计算机的一个特殊的文件夹里,我在任何一台新机器上都能找到它。在它里面为每个你想要不同配置的主机创建一个文件夹。每个主机的文件夹应该以该机器的短主机名命名。所以在你的git里,你有:

.host_configs/
           homecomp1/
           girlfriendcomp1/
           workcomp1/
           workcomp2/

In each host specific folder, put the .vimrc, .irbrc, etc., configuration files for that specific box. And also, in each host folder make a file called .[SHORT_HOST]_rc. For instance, if your machine is name "sane" have a file named .sane_rc ... This file will contain the lines that would normally be in .bashrc that are unique to that host. For instance, if it's a mac and it needs alias ls='ls -GF' instead of alias ls='ls --color=auto' which works for most nix machines for ls with colors, put that line in the .[SHORT_HOST]_rc for that machine, along with whatever special functions, declarations, etc, that would normally go into the .bashrc or .profile etc. (or .zshrc, .tschrc, as the case may be). So the version controlled ~/.host_configs/ folder looks like:

在每个主机特定文件夹中,放置.vimrc、.irbrc等特定框的配置文件。并且,在每个主机文件夹中创建一个名为.[SHORT_HOST]_rc的文件。例如,如果您的机器名为“sane”,则有一个名为.sane_rc的文件…这个文件将包含通常位于.bashrc中的、该主机唯一的行。例如,如果它是一个mac和它需要别名ls = ' ls女朋友而不是别名ls = ' ls -颜色=汽车的工作对于大多数nix ls的机器颜色,把这条线。[SHORT_HOST]_rc机,以及任何特殊函数声明、等,通常会进入. bashrc或. profile等。(或. zshrc .tschrc,视情况而定)。所以版本控制了~/。host_configs /文件夹看起来像:

.host_configs/
           homecomp1/
                    .homecomp1_rc        #special shell configs for this hostname
                    .vimrc               #you know the rest
                    .irbrc
                    .Xresources
           girlfriendcomp1/
                    .girlfriendcomp1_rc
                    .vimrc
                    .bubblebathrc
           workcomp1/
                    .workcomp1_rc
                    .bashrc
                    .vimrc
           workcomp2/
                    .workcomp2_rc
                    .bashrc
                    .vimrc

I use all the same barebones $HOME/.bashrc (or ~/.tshrc etc) on all of my machines. I just take the basic one that comes with the distro in question and move all of the host-specific configuration into the .host-configs/[SHORT_HOST]/.[SHORT_HOST]_rc file.

我用的都是同样的不义之财。bashrc(或(~ /。tshrc等)在我所有的机器上。我只使用与发行版相关的基本配置,并将所有特定于主机的配置移到.host-configs/[SHORT_HOST]/中。[SHORT_HOST]_rc文件。

Put this at the bottom (of $HOME/.bashrc):

把这个放在底部($HOME/.bashrc):

export SHORT_HOST="sane"
for file in `find ~/.host_configs/$SHORT_HOST -name ".*"`
do
ln -s $file `basename $file`
done
source ~/`.$SHORT_HOST`_rc

(Finds all of the dot-files for the host and makes a symlink in home to the~/.host_configs/foo_host folder). Your dot files are in their normal location but they are symlinked to version control. The above also sources all of the lines in your [$SHORT_HOST]_rc file into .bashrc

(查找主机的所有点文件,并在主页中创建一个symlink)。host_configs / foo_host文件夹)。您的点文件在它们的正常位置,但是它们是与版本控制相关的。上面的内容还将[$SHORT_HOST]_rc文件中的所有行都转换为.bashrc

You can commit back to git from the ~/.host_configs/ folder whenever you have changes.

您可以从~/提交回git。当您有更改时,host_configs/文件夹。

That's what it looks like in shell, which is probably all you need, but if you need other features, I would write something that uses the same principles (sourcing an external .rc file into .bashrc and symlinking all the config files to the structured version control folder) in something more versatile/less ugly than shell. So instead of the above in your .bashrc, there could be:

壳牌的样子,可能是你所需要的,但是如果你需要其他的功能,我想写点东西,使用相同的原则(采购外部.rc文件. bashrc并将所有的配置文件结构化版本控制文件夹)在一些更通用的丑陋/低于壳。因此,在你的。bashrc中,可以有以下内容:

export SHORT_HOST="sane"
ruby ~/import_conf.rb $SHORT_HOST

...and write your import_conf.rb to do more complex conf management, like placing a specific configuration file in some directory besides home, or handling a config folder like .ssh/, .subversion/ etc. That's what I do, it's pretty elegant for me, but there may be better solutions. Dropbox with some creative symlinks is also an excellent idea, though you're relying on a third party, and you need to be in a graphical environment. Also note there are inconsistencies between what you can do with symlinks + dropbox in Linux and shortcuts + dropbox in Windows if you implement something that wants to play with Windows.

…和编写import_conf。rb进行更复杂的conf管理,比如在home之外的某个目录中放置特定的配置文件,或者处理.ssh/、.subversion/等配置文件夹。Dropbox拥有一些有创意的符号链接也是一个不错的主意,尽管你需要依赖第三方,而且你需要在一个图形化的环境中。同样要注意的是,如果你实现了想要在Windows上运行的东西,你可以使用Linux中的symlinks + dropbox和Windows中的快捷方式+ dropbox之间的不一致性。

#11


0  

Now there is also vcsh

现在还有vcsh

From the README:

的自述:

vcsh - manage config files in $HOME via fake bare git repositories

vcsh -通过假的裸git库管理$HOME中的配置文件

[...]

[…]

vcsh allows you to have several git repositories, all maintaining their working trees in $HOME without clobbering each other. That, in turn, means you can have one repository per config set (zsh, vim, ssh, etc), picking and choosing which configs you want to use on which machine.

vcsh允许您拥有几个git仓库,它们都在$HOME中维护工作树,而不会互相造成破坏。反过来,这意味着您可以拥有每个配置集(zsh、vim、ssh等)的一个存储库,选择您想要在哪台机器上使用的配置。

Works perfectly, but may be a bit daunting if you are not an experienced git user.

如果您不是一个有经验的git用户,那么可以很好地工作,但是可能会有些困难。