LoginSignup
9
10

More than 5 years have passed since last update.

dotfilesの初期化用スクリプト

Posted at

はじめに

dotfiles、便利ですよね。
でも環境が変わるごとにシンボリックリンク貼ったり、大変ですよね。
しかも環境が変わるってのは普通はあんまりないですし、何すればいいんだっけ?ってなりますよね。よね??
私はなります。

対象者

  • すでにdotfilesを運用してるひと
  • NeoBundleでVimプラグインを管理しているひと
  • 毎回いちいち設定するのめんどくせえってひと

一括処理しよう

一度、バッチ処理するシェルプログラム書いておけば安心ですね。
はい、書きました。

init_dotfiles.sh
#!/bin/sh

# current dir
cd $(dirname $0)

# download neobundle files
if [ -e ~/dotfiles/vimfiles/bundle/neobundle.vim ]; then
    echo "neobundle found"
    is_existed=true
else
    echo "install neobundle"
    mkdir -p ~/dotfiles/vimfiles/bundle/
    git clone https://github.com/Shougo/neobundle.vim ~/dotfiles/vimfiles/bundle/neobundle.vim
    is_existed=false
fi

# make symlink
for dotfiles in .?*; do
    case $dotfiles in 
        ..)
            continue;;
        .git)
            continue;;
        *)
            ln -Fis "$PWD/$dotfiles" $HOME;;
    esac
done
if [ -e ~/.vim ]; then
    echo ".vim found. rename .vim dir"
else
    ln -vFis ~/dotfiles/vimfiles ~/.vim;
fi

# install & update NeoBundle plugins
if [ "${is_existed}" == true ]; then
    echo "running NeoBundleUpdate...\n"
    vim -u ~/.vimrc -i NONE -c "try | NeoBundleUpdate! | finally | q! | endtry" -e -s -V1
else
    echo "running NeoBundleInstall...\n"
    vim -u ~/.vimrc -i NONE -c "try | NeoBundleInstall! | finally | q! | endtry" -e -s -V1
fi
echo "\ncompleted!"

動作環境

CentOS 6.5, OS X 10.9.5のみ確認済みです。
想定する構成は

dotfiles
  │  .vimrc
  │  .bashrc
  ~
  │  init_dotfiles.sh
  └─ vimfiles
      └─ bundle

のような感じです。

運用

非常に簡単です。

$ cd ~
$ git clone https://github.com/your_account/dotfiles.git
$ sh init_dotfiles.sh

以上です。ね、簡単でしょ?
ちなみにすでに環境がある状態で

$ sh init_dotfiles.sh

とするとプラグインのアップデートがかかります(NeoBundleUpdate)

おわりに

注意点がいくつかあります。

  • Gitで2段階認証している場合はMacからだとPushできない可能性があります。
  • vimfiles/bundle/以下がgitignoreされていない場合、何か良くないことが起こりそうな気もします
  • ルートディレクトリの.vim/や.bashrcは事前に移動か削除しておく必要があると思います。

以上です。
Enjoy! XD

9
10
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
9
10