LoginSignup
16
17

More than 5 years have passed since last update.

vcshを使ってdotfilesを$HOMEに置いたままgit管理する

Last updated at Posted at 2014-02-23

概要

vcshを使ってdotfilesをgitで管理します。
.vim関連ファイル(NeoBundle利用)と.bash関連ファイルを管理する例を示します。
vcshを使う利点としては以下のようなものがあります。

  • dotfiles用のディレクトリを作らずに$HOMEに置いたままdotfilesを管理できる
  • $HOMEに置いたまま、複数のレポジトリを管理できる
    • 例えば、.vim用のレポジトリ、.screen系のレポジトリ、tmux用のレポジトリ、、、といった分け方をすることができるため、あるマシンではvimとscreenのdotfilesのみ使う、別のマシンではvimとtmuxのdotfilesのみ使うといったことが可能になります。

使い方

インストール

vcshのインストール
git clone git://github.com/RichiH/vcsh.git
cd vcsh
sudo ln -s /path/to/clone_dir/vcsh /usr/local/bin/vcsh

.vim用のレポジトリを作成

.vim用レポジトリを作成
# vcshのレポジトリ初期化
vcsh init vim

# vimのレポジトリに入る。
# これ以降のgitcommandはvimレポジトリに対して行われる。
vcsh enter vim

# リモートレポジトリ(github上で事前に作成する)を設定する
git remote add origin https://hogehoge@github.com/hogehoge/vim.git

# gitコマンドでファイルをadd、commit、pushする
git add .vimrc
git commit -m 'Initial Commit for vim settings'
git push -u origin master

.vimrcだけならここまででOKです。
今回はNeoBundleで管理しているプラグインもgitで管理するため、neobundleのレポジトリをsubtree addします。
subtreeコマンドは古いgitでは使えないのでご注意下さい。

neobundleをsubtreeaddする
git subtree add -P .vim/bundle/neobundle.vim --squash https://github.com/Shougo/neobundle.vim master
# 自分の場合、手動プラグインやプラグイン用の個別ファイル(snipetファイル等)を
# manualディレクトリに入れているため、それらもgit管理します
git add .vim/bundle/manual
git commit -m 'add neobundle and manual bundle'
git push -u origin master

こうすることで、不必要なプラグインファイルをgitレポジトリに上げなくて済みます。
別のマシンでこのvimのレポジトリを持ってきた場合、NeoBundleInstallで.vimrcに書かれた全てのプラグインがインストールできます。

別のマシンでpullする

git管理したファイル群を別のマシンで使う場合、以下のようにします。

別のマシンでpullする
vcsh init vim
vcsh enter vim
git remote add origin https://hogehoge@github.com/hogehoge/vim.git
git pull -u origin master

.bash関連用レポジトリを作成

最初のマシンに戻って別のレポジトリを作ってみます。
とりあえず.bash関連のファイルを管理してみます。

.bash関連用レポジトリの作成
vcsh init bash
vcsh enter bash
git remote add origin https://hogehoge@github.com/hogehoge/bash.vim
git add .bash_profile .bashrc .bash_logout
git commit -m 'initial commit for bash envs'
git push -u origin master

pullするときも同様のため省略します。

vcshサブコマンドでgitコマンドを実行する

vcsh enter <レポジトリ名>を使わずにvcsh <レポジトリ名> サブコマンドのようにvcshのサブコマンドでgitコマンドを実行することも可能です。

vcshサブコマンドの例
vcsh vim add .vimrc
vcsh vim commit -m "commit hogehoge"
vcsh vim push -u origin master

全レポジトリpush/pull

レポジトリは1つずつpush/pullする必要はなく、全レポジトリまとめてpush/pullできます。

全レポジトリのpush/pull
# push
vcsh push

# pull
vcsh pull

vcshのページにはmrと連携してvcsh管理以外のgit管理レポジトリもまとめてpush/pullする方法が書かれています。

追記(2014/10/16)

結局vcshは使わずdotfilesディレクトリ切って管理することにしましたw
1箇所で管理できた方が良いなぁって言うのとdotfilesの管理のための一個ツール入れるのが見合ってないかなぁと。。。
ごめんなさいw

16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17