LoginSignup
2
3

More than 5 years have passed since last update.

.zshrc や .tmux.conf などをGitHubで管理している時のインストールスクリプト

Last updated at Posted at 2018-03-13

.zshrc などの設定ファイルをGitHubで管理している人は多いと思う。けれども複数PC間で使うために、リポジトリをcloneした後に手動でファイルをホームディレクトリに移動させたり、シンボリックリンクを張るのは面倒だ。シェルスクリプトでやってしまおう。

install.sh
# リポジトリがあるpath
DOTFILES=$(cd $(dirname $0); pwd)
# バックアップ用のタイムスタンプ
now=$(date '+%Y%m%d%H%M%S')

cd ~/

function copy_file() {
 # すでにファイルが存在する場合はバックアップを作る
  if [[ -e $1 ]]; then
    # .zshrc_20180314010755 のような名前でバックアップをとる
    mv $1 $1_$now
  fi
  # シンボリックリンクを張る
  ln -fs $DOTFILES/$1
}

# 引数にリンクを張りたいファイル名を与えてあげる
copy_file '.gitconfig'
copy_file '.zshrc'

O K 💃

2
3
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
2
3