Ubuntuへのzsh設定メモ

Zsh

zshは高機能のシェル。補完とかイロイロ機能があってステキ。

zshのインストール

$ sudo apt-get install zsh

デフォルトシェルの切り替え

$ chsh

変更するshellの入力を求められたらzshへのパスを入力する

/bin/zsh

ターミナルから抜け、再度入り直すとデフォルトシェルが変更される。

$ echo $SHELL
/bin/zsh

oh-my-zsh のインストール

$ curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh

プラグインの利用(必要に応じて)

~/.zshrc の以下を

plugins=(git)

書き換える

plugins=(git ruby bundler rails )

テーマの適用

~/.zsh

ZSH_THEME="robbyrussell"

robbyrussell を 好みのテーマに置き換える

テーマは以下を参照

Gitコマンドの補完

git-completion.bashzshを取得(zshでもbashファイルに依存する為、両方必要)

$ mkdir ~/.zsh/completion/
$ cd ~/.zsh/completion/
$ curl -O https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
$ curl -O https://raw.github.com/git/git/master/contrib/completion/git-completion.zsh

git-completion.zshを_gitにリネーム

$ mv git-completion.zsh _git

補完定義ファイルの読み込み

~/.zshrcに以下を追記

fpath=(~/.zsh/completion $fpath)

autoload -U compinit
compinit -u

zcompdumpをリビルド

$ rm -f ~/.zcompdump
$ compinit

git,git-flowのインストールと設定のまとめ

入社以来ずっとSVN使ってきたけど、gitの環境に変わったのでgitの導入手順とか設定をまとめておく。

gitのインストールと設定

$ sudo yum install git
$ apt-get install git


ユーザ設定


基本的な設定

$ git config --global user.name "hoge"
$ git config --global user.email "hoge@example.com"

色やエイリアスの設定

$ git config --global color.ui auto
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.br branch
$ git config --global alias.hist 'log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short'

自分用のgitignore設定

  • .swpとか除外しとく
$ git config --global core.excludesfile ~/.gitignore

git-flowのインストール

$ wget --no-check-certificate -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sudo bash

git-flowは、ブランチモデルを補助する機能を提供してくれる。
git-flowの使い方はgit flow でのチーム開発ワークショップ資料 - Yamashiro0217の日記を参考にすると分かりやすい。

コマンド補完


git

gitインストール時にgit-completion.bashという設定ファイルも落としてきているので、それを読み込ませれば補完が効くようになる。

  • ~/.bashrcに以下の様にgit-completion.bashを読み込ませる記述を追記
source gitインストールディレクトリ/contrib/completion/git-completion.bash

git-flow

git-flow用のcompletion.bashは、git-flowには用意されていないので別に取得する。

$ wget -O /etc/bash_completion.d/git-flow-completion.bash https://raw.github.com/bobthecow/git-flow-completion/master/git-flow-completion.bash

gitと同じように、~/.bashrcにgit-flow-completion.bashを読み込ませる記述を追記

source 任意の保存ディレクトリ/git-flow-completion.bash

ターミナルに現在のbranchを表示する


~/.bashrcに以下を追記

PS1="[\u:\W\$(__git_ps1)]\$ " 

最後に忘れずに、.bashrcを読み込んで設定を反映させる。

$ source ~/.bashrc


これで当面やってみる。
なにかオススメの設定とかあれば、教えてください!


参考

見えないチカラ: A successful Git branching model を翻訳しました

git flow でのチーム開発ワークショップ資料 - Yamashiro0217の日記

Gitコマンドをタブキーで補完できるようにする | mawatari.jp

git-flowのインストールとタブキーによるコマンド補完 | mawatari.jp