Skip to content

Commit

Permalink
zsh/tmux: Show host/user/branch/path in tmux statusbar
Browse files Browse the repository at this point in the history
By setting the window title to a dynamic host/user/branch/path snippet
in zsh's precmd() we can shorten the prompt in tmux and display
important info only in the statusbar.
  • Loading branch information
Lokaltog committed Mar 20, 2012
1 parent b224b33 commit 7553181
Showing 1 changed file with 71 additions and 33 deletions.
104 changes: 71 additions & 33 deletions zshfiles/zshrc
Expand Up @@ -193,49 +193,87 @@
# }}}
# Prompt {{{
if [[ $TERM =~ '256color' ]]; then
# VCS info {{{
autoload -Uz vcs_info
autoload -Uz vcs_info

precmd () { vcs_info }
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' formats '%u%c|%s ⭠ %b'
zstyle ':vcs_info:*' actionformats '%c%u|%s@%a ⭠ %b'
zstyle ':vcs_info:*' branchformat '%b@%r'
zstyle ':vcs_info:*' unstagedstr "%{$fg_no_bold[red]%}"
zstyle ':vcs_info:*' stagedstr "%{$fg_no_bold[yellow]%}"
zstyle ':vcs_info:*' enable git hg svn

zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' formats ' %u%c|%s ⭠ %b '
zstyle ':vcs_info:*' actionformats ' %c%u|%s@%a ⭠ %b '
zstyle ':vcs_info:*' branchformat ' %b@%r '
zstyle ':vcs_info:*' unstagedstr "%{$fg_no_bold[red]%}"
zstyle ':vcs_info:*' stagedstr "%{$fg_no_bold[yellow]%}"
zstyle ':vcs_info:*' enable git hg svn
zstyle ':vcs_info:git*:*' formats '%s ⭠ %b'
zstyle ':vcs_info:git*:*' actionformats '%c%u|%s@%a:%b@%.5i'

zstyle ':vcs_info:git*:*' formats '%s ⭠ %b '
zstyle ':vcs_info:git*:*' actionformats ' %c%u|%s@%a:%b@%.5i '
# }}}
precmd () {
vcs_info

C_RESET='%{%}'
if [[ $TMUX != '' ]]; then
# Dynamic tmux status (path/branch stuff)
#
# This is a hack which sets window-specific stuff as the
# window's title, so the title gets useless in e.g. dwm's
# statusbar. This has to be done because tmux doesn't
# support custom dynamic variables in the statusbar.
STATUS=''
STATUS_USER_FG=153
STATUS_USER_BG=31

C_USER=$C_RESET'%{[1m[38;5;117m[48;5;31m%}'
C_USER_SEP=$C_RESET'%{[48;5;237m[38;5;31m%}'
C_PWD=$C_RESET'%{[38;5;248m[48;5;237m%}'
C_PWD_SEP=$C_RESET'%{[38;5;237m%}'
if [[ $UID == 0 ]]; then
STATUS_USER_FG=231
STATUS_USER_BG=160
fi

if [[ ! -z "$SSH_CLIENT" ]]; then
SSHPROMPT=$C_RESET'%{%} ⭤ %M %{%}'
if [[ ! -z "$SSH_CLIENT" ]]; then
STATUS=$STATUS"#[fg=colour220,bg=colour166] ⭤ `hostname` #[fg=colour166,bg=colour$STATUS_USER_BG]⮀"
fi

if [[ $UID == 0 ]]; then
SSHPROMPT=$SSHPROMPT'%{%}⮀'
else
SSHPROMPT=$SSHPROMPT'%{%}⮀'
STATUS=$STATUS"#[fg=colour$STATUS_USER_FG,bg=colour$STATUS_USER_BG,bold] `whoami` #[fg=colour$STATUS_USER_BG,bg=colour239,nobold]⮀"
if [[ $vcs_info_msg_0_ != '' ]]; then
STATUS=$STATUS" #[fg=colour248]${vcs_info_msg_0_}"
fi
STATUS=$STATUS"#[fg=colour231,bg=colour239,bold] `pwd` #[fg=colour239,bg=colour236,nobold]⮀"

# Set the status bar info as the window title
echo -n ']2;'$STATUS''
fi
fi
}

if [[ $UID == 0 ]]; then
# Highlight root user
C_USER=$C_RESET'%{%}'
C_USER_SEP=$C_RESET'%{%}'
if [[ $TMUX != '' ]]; then
# Show shorter prompt in tmux because the statusbar has path/branch info
if [[ $UID != 0 ]]; then
PROMPT='%{%}▶ %{%}'
else
PROMPT='%{%}▶ %{%}'
fi
else
C_RESET='%{%}'

C_USER=$C_RESET'%{%}'
C_USER_SEP=$C_RESET'%{%}'
C_PWD=$C_RESET'%{%}'
C_PWD_SEP=$C_RESET'%{%}'
if [[ ! -z "$SSH_CLIENT" ]]; then
SSHPROMPT=$C_RESET'%{%} ⭤ %M %{%}'

if [[ $UID == 0 ]]; then
SSHPROMPT=$SSHPROMPT'%{%}⮀'
else
SSHPROMPT=$SSHPROMPT'%{%}⮀'
fi
fi

if [[ $UID == 0 ]]; then
# Highlight root user
C_USER=$C_RESET'%{%}'
C_USER_SEP=$C_RESET'%{%}'
fi

PROMPT=$SSHPROMPT$C_USER' %n '$C_USER_SEP''$C_PWD' %3~ '$C_PWD_SEP''$C_RESET' '
RPROMPT='${vcs_info_msg_0_}'
fi

PROMPT=$SSHPROMPT$C_USER' %n '$C_USER_SEP''$C_PWD' %3~ '$C_PWD_SEP''$C_RESET' '
RPROMPT='${vcs_info_msg_0_}'
fi
# List prompt - don't ask 'do you want to see all ...' in menu selection {{{
LISTPROMPT=''
Expand Down

0 comments on commit 7553181

Please sign in to comment.