Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 982
Screenack Avatar asked Jul 20 '12 09:07

Screenack


3 Answers

You don't need to configure Git, just tell Vim to use ~/.vim for Windows, too, by putting the following fragment into your ~/.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
like image 149
Ingo Karkat Avatar answered Nov 15 '22 08:11

Ingo Karkat


My setup is very simple.

On Mac, the versioned directory is:

/Users/username/.vim

On Linux, it is:

/home/username/.vim

On Windows XP (yes), it is:

C:\Documents and Settings\username\vimfiles

They all point to the same GitHub repository.

My settings are stored in a vimrc (no . or _) file located at the root of the repository. Therefore its versioned and commited/pushed/pulled like all the rest.

The actual default user-specific 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.

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.

Setting up a new machine or user is as simple as cloning my repo and typing two easy to remember words.

like image 45
romainl Avatar answered Nov 15 '22 08:11

romainl


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. 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.

For example, I put my vimrc file under Dropbox/conf/vimrc, and then did

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. 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 keeps a history of changes over the last 30 days, which is enough to handle recovering from most problems for which I needed 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.

Of course this approach is also handy for your other config files, too (.gitconfig, .gitignore, .bashrc, etc.).

like image 34
GaryWSmith Avatar answered Nov 15 '22 07:11

GaryWSmith