LoginSignup
1
0

zshでgitのブランチ名を表示する

Last updated at Posted at 2023-09-08

設定方法

ツールを追加するディレクトリを作成する。

$ mkdir ~/.zsh
$ cd ~/.zsh

補完に必要なツールを取得する。

# 補完用ツール
$ curl -L -O https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
# zsh用に補完用ツールを読み込むシェル、ファイル名を_gitに変更する
$ curl -L -o _git https://raw.github.com/git/git/master/contrib/completion/git-completion.zsh
# __git_ps1を提供するシェル
$ curl -L -O https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

下記を記載する。

$ vi ~/.zshrc
.zshrc
fpath=(~/.zsh $fpath)

if [ -f ${HOME}/.zsh/git-completion.bash ]; then
        zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fi
 
if [ -f ${HOME}/.zsh/git-prompt.sh ]; then
        source ${HOME}/.zsh/git-prompt.sh
fi
 
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWUPSTREAM=auto
 
setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
$ source ~/.zshrc

確認

ブランチのディレクトリを表示する

repository_name (issues/1_branch_name *%=)]$
1
0
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
1
0