設定ファイルを複数マシンで共有する
前半はLinuxのドットファイルをgithubで同期させてる話で後半はPowerShellのプロファイルをDropboxで同期させてる話です。
Linuxのドットファイルを同期させる
Linuxのドットファイルをgithubで同期する方法があちこちに書かれていたので同じ様にやってみました。
登録してあるリポジトリは下記のURLです。
dotfiles
作り方もあちこちに書いてありますが、自分用にメモしておきます。
適当なディレクトリを作成して、そこに現在のドットファイルを移動する
# cd ~ # mkdir dotfiles # mv ./.profile ./dotfiles/ # mv ./.screenrc ./dotfiles/ # mv ./.vimrc ./dotfiles/
移動したファイルからホームディレクトリにシンボリックリンクを作成するスクリプトを作成する。
# cd ~/dotfiles # touch dotfileslink.sh # chmod +x dotfileslink.sh # nano dotfileslink.sh
#!/bin/sh # ln -sf ~/dotfiles/.profile ~/.profile # ln -sf ~/dotfiles/.vimrc ~/.vimrc # ln -sf ~/dotfiles/.screenrc ~/.screenrc
# ./dotfileslink.sh # git init # git add -A # git commit -a -m "Initial commit" # git remote add origin %githubのURL% # git push origin master
PowerShellのプロファイルも同期してみた
こちらはgithubではなくてDropboxにリポジトリを作成しています。
~\Dropbox\git\psprofileを作成して設定します。
> New-Item -Type Directory ~/Dropbox/git/psprofile > Set-Location ~/Dropbox/git/psprofile > git init --bare --share=true
プロファイルがあるディレクトリに移動して適当なディレクトリを作成します。
> Set-Location ~/Documents/WindowsPowerShell > New-Item -Type Directory dotfiles
既に存在しているプロファイルを作成したディレクトリに移動します。
名称も変更しているのは別のマシンで取り込む時に必要そうだったからです。
移動した後は新しいディレクトリ内のスクリプトをプロファイルに取り込むためのプロファイルスクリプトを作成します。
> Move-Item Microsoft.PowerShell_profile.ps1 ./dotfiles/psprofile.ps1 > Write-Output ". ~\dotfiles\psprofile.ps1" > $PROFILE > Copy-Item $PROFILE ./dotfiles
ここまでできたらDropboxのリポジトリに突っ込んでおきます。
> Set-Location ./dotfiles > git init > git add -A > git commit -a -m "Initial commit" > git remote add origin ~/Dropbox/git/psprofile > git push origin master
こんな感じで。
新しいマシンでの取り込み
もちろんgitを入れてパスの設定までしておかないといけませんし、Dropboxを入れて同期が完了していないといけません。
> New-Item -Type File -Force $PROFILE > Set-Location ~/Documents/WindowsPowerShell > git clone ~/Dropbox/git/psprofile > Set-Location ./dotfiles > Copy-Item ./Microsoft.PowerShell_profile.ps1 ../
これでPowerShellを立ち上げ直せば他のマシンと同じプロファイルが使えるはずです。
PowerShellの場合git入れるのが面倒だったり、設定ファイル一つならコピーしちゃってもいいんですけどね。