wata.dev

tips: コマンドプロンプトにブランチ名を表示する

Milla, a Dist::Zilla profile that doesn’t suck (screencast) を見ていて、コマンドプロンプトに git のブランチ名表示させてんのどうやるんだろう?と思って調べてみたら、.bashrc に以下のように書いて有効化したらいけました。

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\033[037;041m\]\u@\h: \w\$(parse_git_branch)$ \[\033[00m\]"

これは便利!

元ネタ: http://martinfitzpatrick.name/article/add-git-branch-name-to-terminal-prompt-mac

ブログの記事一覧