LoginSignup
5
8

More than 5 years have passed since last update.

dotfiles(設定ファイル)をまとめよう!!

Last updated at Posted at 2018-04-04

dotfiles(設定ファイル)とは

ホームディレクトリにある
.から始まるファイルのことである
.vimrcとか.gitconfigsなどである
それらのファイルをgithubにて管理をするというのが今回のお話なのである

今回の事前事項

  • git(github)
    前回説明した通り
  • .gitnore
    gitにpushするときに範囲外にするものを書き並べたもの

dotfilesのバックアップを取ろう

まずは前回と同じようにgithubでdotfilesという名前のレポジトリを作ってください

$ git clone [作成したレポジトリ]

そしたらdotfilesというファイルができます
その中に保存するファイルを入れておきます

cd ~/
mv .vimrc dotfiles
mv .gitconfigs dotfiles

そしたらまたvimが.vimrc参照しなくなるので~/に移動させた.vimrcのシンボリックリンクを置きます
そのため以下のようなファイルを作ります
~/dotfiles/dots.sh

dots.sh
#!/bin/bash

set -u
cd ~/dotfiles
# 実行場所のディレクトリを取得
THIS_DIR=$(cd $(dirname $0); pwd)

cd $THIS_DIR
git submodule init
git submodule update

echo "start setup..."
for f in .??*; do
    [ "$f" = ".git" ] && continue
    [ "$f" = ".gitconfig.local.template" ] && continue
    [ "$f" = ".require_oh-my-zsh" ] && continue
    [ "$f" = ".gitmodules" ] && continue

    ln -snfv ~/dotfiles/"$f" ~/
done

[ -e ~/.gitconfig.local ] || cp ~/dotfiles/.gitconfig.local.template ~/.gitconfig.local

cat << END

**************************************************
DOTFILES SETUP FINISHED! bye.
**************************************************

END

その後dotfilesないでsh dots.shで起動させたら自動的にリンクを貼ってくれます
ではこの状態でgitにpushしておきましょう

git add -A
git commit -m".vimrcなどを追加またシンボリックリンク作成用のシェルスクリプトをついか"
git push origin master

また.vimなどもまとめてみる

$ cd ~/
$ rm -rf .vim
$ cd ~/dotfiles
$ git clone [自分の.vimのレポジトリ]

.vimrcの中身も書き換える

.vimrc
set encoding=utf-8
scriptencoding utf-8
set runtimepath+=~/dotfiles/.vim
runtime! configs/users/*.vim
runtime! configs/plugins/*.vim

pluginのインストール場所も変更するためにplugins.vimも書き換える

plugins.vim
"プラグインが実際にインストールされるディレクトリ                                                                                                                               
let s:dein_dir = expand('~/dotfiles/.vim/dein')
" dein.vim 本体
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'

" dein.vim がなければ github から落としてくる
if &runtimepath !~# '/dein.vim'
 if !isdirectory(s:dein_repo_dir)
  execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
 endif
 execute 'set runtimepath^=' . s:dein_repo_dir
endif

" 設定開始
if dein#load_state(s:dein_dir)
 call dein#begin(s:dein_dir)

 " プラグインリストを収めた TOML ファイル
 " ~/.vim/rc/dein.toml,deinlazy.tomlを用意する
 let g:rc_dir    = expand('~/dotfiles/.vim/configs/plugins/install')
 let s:toml      = g:rc_dir . '/dein.toml'
 let s:lazy_toml = g:rc_dir . '/dein_lazy.toml'

 " TOML を読み込み、キャッシュしておく
 call dein#load_toml(s:toml,      {'lazy': 0})
 call dein#load_toml(s:lazy_toml, {'lazy': 1})

 " 設定終了
 call dein#end()
 call dein#save_state()
endif

" もし、未インストールものものがあったらインストール
if dein#check_install()
 call dein#install()
endif

filetype plugin indent on

最後に起動用スクリプトを書いておく

install.sh
cd ~/dotfiles
git clone [自分の.vimのレポジトリ]
sh dots.sh

一応自分用の設定ファイルです
.vim
初期設定
dotfiles

5
8
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
5
8