From 059958b05df78c658fb4fd6b350cfaeb1756b799 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2013 16:40:44 +0200 Subject: [PATCH] zsh/rc: Display staged/unstaged info next to cwd in prompt. In addition to the more detailed vcs_info string on the top right. --- zsh/rc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/zsh/rc b/zsh/rc index 734040f..c669178 100644 --- a/zsh/rc +++ b/zsh/rc @@ -234,9 +234,11 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) || if [[ $ZSH_VERSION == (4.3.<11->*|4.<4->*|<5->*) || -d ~/.zsh/functions/vcs_info ]]; then zstyle ':vcs_info:*' formats \ - "(${green}%b%u%c${default}:${blue}%s${default})" + "(${green}%b%u%c${default}:${blue}%s${default})" \ + "${green}%u%c${default}" zstyle ':vcs_info:*' actionformats \ - "(${green}%b%u%c${default}/${red}%a${default}:${blue}%s${default})" + "(${green}%b%u%c${default}/${red}%a${default}:${blue}%s${default})" \ + "${green}%u%c${default}" else # In older versions %u and %c are not defined yet and are not # correctly expanded. @@ -367,6 +369,7 @@ zshrc_prompt_precmd() { vcs_info else vcs_info_msg_0_= + vcs_info_msg_1_= fi # Setup. Create variables holding the formatted content. @@ -374,6 +377,9 @@ zshrc_prompt_precmd() { # Current directory in yellow, truncated if necessary (WIDTH is replaced # below). local directory="${yellow}%WIDTH<..<%~%<<${default}" + # Minimal information about the VCS, only displayed if there are + # unstaged/staged changes. + local vcs_staged="${vcs_info_msg_1_}" # Information about the VCS in this directory. local vcs="${vcs_info_msg_0_}" @@ -400,20 +406,25 @@ zshrc_prompt_precmd() { # Combine them to create the prompt. + local top_left="${vcs_staged}" local top_right="${vcs}(${seconds})" local width_top_prefix=${#${(S%%)top_prefix//$~zero/}} + local width_top_left=${#${(S%%)top_left//$~zero/}} local width_top_right=${#${(S%%)top_right//$~zero/}} # Calculate the maximum width of ${top_left}. -2 are the braces of # ${top_left}, -1 is one separator from ${top_separator} (we want at least # one between left and right parts). local top_left_width_max=$(( - COLUMNS - $width_top_prefix - 2 - 1 - $width_top_right + COLUMNS - $width_top_prefix + - $width_top_left - 2 + - 1 + - $width_top_right )) # Truncate directory if necessary. - local top_left="(${directory/WIDTH/${top_left_width_max}})" - local width_top_left=${#${(S%%)top_left//$~zero/}} + top_left="(${directory/WIDTH/${top_left_width_max}})${top_left}" + width_top_left=${#${(S%%)top_left//$~zero/}} # Calculate the width of the top prompt to fill the middle with "-". local width=$(( -- 2.45.2