LoginSignup
0
2

More than 5 years have passed since last update.

tmuxステータスラインにホームディレクトリのdotfilesのカレントブランチを表示したい

Last updated at Posted at 2018-03-27

gitのブランチ一覧を見るとき

gitブランチ一覧
$ git branch
develop
* master
feature/test_config

gitでカレントブランチ名だけ切り出すとき

gitカレントブランチのみ
$ git branch | grep '*' | cut -d ' ' -f2
master

#(git branch | grep '*' | cut -d ' ' -f2)をセットしてtmuxのステータスラインにホームディレクトリのブランチを表示する

set -g status-left "#[fg=colour233,bg=colour125,bold] #H #[fg=colour125,bg=colour240,nobold]#[fg=colour233,bg=colour240] #(git branch | grep '*' | cut -d ' ' -f2) #[fg=colour240,bg=colour235]#[fg=colour240,bg=colour235] ###S W#I P#P #[fg=colour235,bg=colour233,nobold]"

Screenshot from 2018-03-27 23-59-22.png
tmuxステータスラインの左から二番目(archlinux.vagrant.vmの隣)がdevelopブランチを表示

Screenshot from 2018-03-28 00-29-28.png
tmuxステータスラインの左から二番目(archlinux.vagrant.vmの隣)がmasterブランチを表示

Screenshot from 2018-03-28 00-32-22.png
developブランチであるディレクトリに移動してもホームディレクトリのdotfilesはmasterブランチなのでステータスラインはmasterを表示

tmuxステータスラインはjimeh/tmux-themepack
zshプロンプトはbhilburn/powerlevel9kをそれぞれカスタムして使用しています。
u1and0/dotfiles

追記

Gitのブランチ名を返すエイリアスを設定したら地味に捗ったより、

$ alias brname='git symbolic-ref --short HEAD'

とエイリアス設定することで

$ echo $(brname)
master

とかいうように現在のブランチを返してくれます。

$ git branch | grep '*' | cut -d ' ' -f2

と同じ結果ですが、パイプをはさまない純粋gitサブコマンドなので、お好みで使うとよいでしょう。

0
2
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
0
2