简体   繁体   English

我可以在git中修改名称与操作系统相关的路径

[英]Can I version a path in git whose name is operating system dependent

I wish to store my Mac, Windows and Linux vim configuration files in git. 我希望将我的Mac,Windows和Linux vim配置文件存储在git中。 On *nix systems, your vim configuration files go in ${HOME}/.vim but for the Windows binary, the same directory is named "vimfiles" Can I configure git to accommodate the different directory name? 在* nix系统上,您的vim配置文件位于$ {HOME} /。vim中,但对于Windows二进制文件,同一目录名为“vimfiles”我是否可以配置git以容纳不同的目录名称?

You don't need to configure Git, just tell Vim to use ~/.vim for Windows, too, by putting the following fragment into your ~/.vimrc : 您不需要配置Git,只需告诉Vim使用~/.vim for Windows,将以下片段放入~/.vimrc

" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
" across (heterogeneous) systems easier.
if has('win32') || has('win64')
    set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
endif

My setup is very simple. 我的设置非常简单。

On Mac, the versioned directory is: 在Mac上,版本化目录是:

/Users/username/.vim

On Linux, it is: 在Linux上,它是:

/home/username/.vim

On Windows XP (yes), it is: 在Windows XP上(是),它是:

C:\Documents and Settings\username\vimfiles

They all point to the same GitHub repository. 它们都指向同一个GitHub存储库。

My settings are stored in a vimrc (no . or _ ) file located at the root of the repository. 我的设置存储在位于存储库根目录的vimrc (no ._ )文件中。 Therefore its versioned and commited/pushed/pulled like all the rest. 因此它的版本和提交/推/拉像所有其余的。

The actual default user-specific vimrc , 实际的默认用户特定vimrc

/Users/username/.vimrc
/home/username/.vimrc
C:\Documents and Settings\username\_vimrc

is a real file, no need for a symlink. 是一个真实的文件,不需要符号链接。 It contains only one line: 它只包含一行:

runtime vimrc

that tells vim to read, and execute, my vimrc . 告诉vim读取并执行我的vimrc

Because of how :runtime works, I don't need to use a real absolute path which would be different on Unix-like platforms and on Windows. 由于:runtime工作原理,我不需要使用真正的绝对路径,这在Unix类平台和Windows上都是不同的。

Setting up a new machine or user is as simple as cloning my repo and typing two easy to remember words. 设置新机器或用户就像克隆我的仓库并键入两个易于记忆的单词一样简单。

I also need to share config files for vim and other applications between multiple systems, and I found that git was not only overkill but also required manual syncing on each system to get the latest updates and to publish changes. 我还需要在多个系统之间共享vim和其他应用程序的配置文件,我发现git不仅过度,而且还需要在每个系统上进行手动同步以获取最新更新并发布更改。 A better solution for me is to put these config files into Dropbox, make all of my systems connect to my Dropbox account, and create symbolic links to these shared files. 对我来说更好的解决方案是将这些配置文件放入Dropbox,使我的所有系统连接到我的Dropbox帐户,并创建指向这些共享文件的符号链接。

For example, I put my vimrc file under Dropbox/conf/vimrc , and then did 例如,我把我的vimrc文件放在Dropbox/conf/vimrc ,然后做了

ln -s ~/Dropbox/conf/vimrc ~/.vimrc

You should be able to use Windows' mklink to similar effect to create a _vimrc symlink to that same file. 你应该能够使用Windows的mklink类似的效果来创建一个_vimrc符号链接到同一个文件。 In the same way, a common Dropbox/conf/vim directory could be linked to locally as .vim or .vimfiles or whatever your OS' vim executable prefers. 以同样的方式,一个普通的Dropbox/conf/vim目录可以在本地链接为.vim.vimfiles或者你的操作系统'vim可执行文件所喜欢的任何东西。

Dropbox keeps a history of changes over the last 30 days, which is enough to handle recovering from most problems for which I needed git. Dropbox保留了过去30天内的更改历史记录,足以处理从我需要git的大多数问题中恢复。 The cool thing is that you can add that new macro or setting to your .vimrc and it is automatically available on all your systems. 很酷的是,您可以将新的宏或设置添加到.vimrc并且它可以在您的所有系统上自动使用。

Of course this approach is also handy for your other config files, too ( .gitconfig , .gitignore , .bashrc , etc.). 当然,这种方法对于其他配置文件也很方便( .gitconfig.gitignore.bashrc等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM