Software development of explosion! -夢の破片(カケラ)たちの日々-

ソフトウェア開発を中心としたコンピューター関連のネタを扱ったブログです

Software development is passion and explosion!

zshでgit switchが補完されるようにする

前回の記事で、Ubuntuzshをインストールしたはいいが、git switch が補完されずに困っていた。 poad1010.hatenablog.com

調べてみると、こんなIssue が! github.com

どうやら、gitリポジトリのmasterにあるgit-completionを使えば良さそう。

mkdir -p ~/.zsh
curl -o ~/.zsh/git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o ~/.zsh/_git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh

echo "# Load completion files from the ~/.zsh directory." >> ~/.zshrc
echo "zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash" >> ~/.zshrc
echo "fpath=(~/.zsh $fpath)" >> ~/.zshrc

echo "autoload -Uz compinit && compinit" >> ~/.zshrc

これでzshを立ち上げ直したら、見事!git switch が保管できた!

ちなみに、git switchは、最近、checkout -b ではなく、switch -c を使えだとか、checkoutの代わりにswitchを使えという流れみたいなので、gitをアップデートして、switchコマンドに慣れておいた方がいい。

この辺を読めば、Ubuntu bionicでも最新のgitが使える。 text.baldanders.info