From 05c467df79a48b5e45d2df72d202cb0b2d832263 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 13 Apr 2019 00:49:10 +0200 Subject: [PATCH 01/10] Split retrieving remote branch and general branch in vcs segment --- segments/vcs/vcs.p9k | 48 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/segments/vcs/vcs.p9k b/segments/vcs/vcs.p9k index de678514e..c91568fac 100644 --- a/segments/vcs/vcs.p9k +++ b/segments/vcs/vcs.p9k @@ -137,12 +137,19 @@ p9k::set_default P9K_VCS_ACTIONFORMAT_FOREGROUND "red" p9k::set_default P9K_VCS_HIDE_TAGS false p9k::set_default P9K_VCS_INTERNAL_HASH_LENGTH "8" # Default: Just display the first 8 characters of our changeset-ID. - p9k::set_default P9K_VCS_DIR_SHORTEN_DELIMITER $'\U2026' + p9k::set_default P9K_VCS_SHORTEN_DELIMITER $'\u2026' p9k::set_default P9K_VCS_SHOW_SUBMODULE_DIRTY true p9k::set_default P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH false p9k::set_default P9K_VCS_SHOW_CHANGESET false } +typeset -gAH __P9K_VCS_DATA +function +vi-git-gather-data() { + __P9K_VCS_DATA[branch]="${hook_com[branch]//\%/%%}" + # Reset the branch name for a fresh start. + hook_com[branch]='' +} + function +vi-git-untracked() { [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return @@ -168,48 +175,47 @@ function +vi-git-aheadbehind() { local -a gitstatus # for git prior to 1.7 - # ahead=$(command git rev-list origin/${hook_com[branch]}..HEAD | wc -l) - ahead=$(command git rev-list --count "${hook_com[branch]}"@{upstream}..HEAD 2>/dev/null) + # ahead=$(command git rev-list origin/${__P9K_VCS_DATA[branch]}..HEAD | wc -l) + ahead=$(command git rev-list --count "${__P9K_VCS_DATA[branch]}"@{upstream}..HEAD 2>/dev/null) (( ahead )) && gitstatus+=( " ${__P9K_ICONS[VCS_OUTGOING_CHANGES]}${ahead// /}" ) # for git prior to 1.7 - # behind=$(command git rev-list HEAD..origin/${hook_com[branch]} | wc -l) - behind=$(command git rev-list --count HEAD.."${hook_com[branch]}"@{upstream} 2>/dev/null) + # behind=$(command git rev-list HEAD..origin/${__P9K_VCS_DATA[branch]} | wc -l) + behind=$(command git rev-list --count HEAD.."${__P9K_VCS_DATA[branch]}"@{upstream} 2>/dev/null) (( behind )) && gitstatus+=( " ${__P9K_ICONS[VCS_INCOMING_CHANGES]}${behind// /}" ) hook_com[misc]+=${(j::)gitstatus} } -function +vi-git-remotebranch() { - local remote - local branch_name="${hook_com[branch]}" - - # Are we on a remote-tracking branch? - remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} +function +vi-git-branch() { + local branch="${__P9K_VCS_DATA[branch]}" + # Truncate the branch name, if it is too long if [[ -n "$P9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$P9K_VCS_SHORTEN_MIN_LENGTH" ]]; then - p9k::set_default P9K_VCS_SHORTEN_DELIMITER $'\u2026' - - if [ ${#hook_com[branch]} -gt ${P9K_VCS_SHORTEN_MIN_LENGTH} ] && [ ${#hook_com[branch]} -gt ${P9K_VCS_SHORTEN_LENGTH} ]; then + if [ ${#__P9K_VCS_DATA[branch]} -gt ${P9K_VCS_SHORTEN_MIN_LENGTH} ] && [ ${#__P9K_VCS_DATA[branch]} -gt ${P9K_VCS_SHORTEN_LENGTH} ]; then case "$P9K_VCS_SHORTEN_STRATEGY" in truncate_middle) - hook_com[branch]="${branch_name:0:$P9K_VCS_SHORTEN_LENGTH}${P9K_VCS_SHORTEN_DELIMITER}${branch_name: -$P9K_VCS_SHORTEN_LENGTH}" + branch="${__P9K_VCS_DATA[branch]:0:$P9K_VCS_SHORTEN_LENGTH}${P9K_VCS_SHORTEN_DELIMITER}${__P9K_VCS_DATA[branch]: -$P9K_VCS_SHORTEN_LENGTH}" ;; truncate_from_right) - hook_com[branch]="${branch_name:0:$P9K_VCS_SHORTEN_LENGTH}${P9K_VCS_SHORTEN_DELIMITER}" + branch="${__P9K_VCS_DATA[branch]:0:$P9K_VCS_SHORTEN_LENGTH}${P9K_VCS_SHORTEN_DELIMITER}" ;; esac fi fi - hook_com[branch]="${__P9K_ICONS[VCS_BRANCH]}${hook_com[branch]//\%/%%}" - # Always show the remote - #if [[ -n ${remote} ]] ; then + hook_com[branch]+="${__P9K_ICONS[VCS_BRANCH]}${branch}" +} + +function +vi-git-remotebranch() { + # Are we on a remote-tracking branch? + local remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} + # Only show the remote if it differs from the local if [[ -n ${remote} \ && ( \ "${P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH}" == 'true' \ - || "${remote#*/}" != "${branch_name#heads/}" \ + || "${remote#*/}" != "${__P9K_VCS_DATA[branch]#heads/}" \ ) ]]; then hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${${remote// /}//\%/%%}" fi @@ -389,7 +395,7 @@ __p9k_vcs_init() { # Hooks are places in vcs_info where you can run your own code. That code can communicate with the code that called it and through that, change the system’s behaviour. # For configuration, hooks change the style context: # :vcs_info:vcs-string+hook-name:user-context:repo-root-name - p9k::defined P9K_VCS_GIT_HOOKS || P9K_VCS_GIT_HOOKS=(vcs-detect-changes vcs-icon git-untracked git-aheadbehind git-stash git-remotebranch git-gitdir git-tagname) + p9k::defined P9K_VCS_GIT_HOOKS || P9K_VCS_GIT_HOOKS=(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch git-remotebranch git-gitdir git-tagname) zstyle ':vcs_info:git*+set-message:*' hooks ${P9K_VCS_GIT_HOOKS} p9k::defined P9K_VCS_HG_HOOKS || P9K_VCS_HG_HOOKS=(vcs-detect-changes vcs-icon hg-branch) zstyle ':vcs_info:hg*+set-message:*' hooks ${P9K_VCS_HG_HOOKS} From 3a84fafd73aa3c6e4fe15e00e04c0898c3f06b53 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 13 Apr 2019 01:11:24 +0200 Subject: [PATCH 02/10] Make remote name and remote branch better distinguishable --- segments/vcs/vcs.p9k | 7 ++++++- segments/vcs/vcs_git.spec | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/segments/vcs/vcs.p9k b/segments/vcs/vcs.p9k index c91568fac..2bb8ba852 100644 --- a/segments/vcs/vcs.p9k +++ b/segments/vcs/vcs.p9k @@ -138,6 +138,7 @@ p9k::set_default P9K_VCS_HIDE_TAGS false p9k::set_default P9K_VCS_INTERNAL_HASH_LENGTH "8" # Default: Just display the first 8 characters of our changeset-ID. p9k::set_default P9K_VCS_SHORTEN_DELIMITER $'\u2026' + p9k::set_default P9K_VCS_REMOTE_DELIMITER "@" p9k::set_default P9K_VCS_SHOW_SUBMODULE_DIRTY true p9k::set_default P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH false p9k::set_default P9K_VCS_SHOW_CHANGESET false @@ -217,7 +218,11 @@ function +vi-git-remotebranch() { "${P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH}" == 'true' \ || "${remote#*/}" != "${__P9K_VCS_DATA[branch]#heads/}" \ ) ]]; then - hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${${remote// /}//\%/%%}" + local remote_name=$(command git config branch.${__P9K_VCS_DATA[branch]#heads/}.remote) + # Remote Branch is the remote branch name, without the remote name. + # Additionally, remove trailing whitespace and escape percent signs. + local remote_branch=${${${remote#${remote_name}/}// /}//\%/%%} + hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${remote_branch}${P9K_VCS_REMOTE_DELIMITER}${remote_name}" fi } diff --git a/segments/vcs/vcs_git.spec b/segments/vcs/vcs_git.spec index e2815eefc..b963109b8 100755 --- a/segments/vcs/vcs_git.spec +++ b/segments/vcs/vcs_git.spec @@ -426,7 +426,7 @@ function testAlwaysShowRemoteBranch() { git clone . ../vcs-test2 1>/dev/null 2>&1 cd ../vcs-test2 - assertEquals "%K{002} %F{000} master→origin/master %k%F{002}%f " "$(__p9k_build_left_prompt)" + assertEquals "%K{002} %F{000} master→master@origin %k%F{002}%f " "$(__p9k_build_left_prompt)" local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='false' assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)" From 724ce4cb16b9dc179a039ef626d51f611fcd143f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 13 Apr 2019 01:14:22 +0200 Subject: [PATCH 03/10] Fix documentation --- segments/vcs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/segments/vcs/README.md b/segments/vcs/README.md index 0125e1d99..918eb1977 100644 --- a/segments/vcs/README.md +++ b/segments/vcs/README.md @@ -67,8 +67,8 @@ Customizations available are: |----------|---------------|-------------| |`P9K_VCS_SHORTEN_LENGTH`|None|This field determines how many characters to show.| |`P9K_VCS_SHORTEN_MIN_LENGTH`|None|This field determines minimum branch length. Branch name will be truncated if its length greater than this field.| -|`P9K_VCS_DIR_SHORTEN_STRATEGY`|None|This field determines how branch name should be truncated. See the table below for more information.| -|`P9K_DIR_SHORTEN_DELIMITER`|`...`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| +|`P9K_VCS_SHORTEN_STRATEGY`|None|This field determines how branch name should be truncated. See the table below for more information.| +|`P9K_VCS_SHORTEN_DELIMITER`|`...`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.| | Strategy Name | Description | |---------------|-------------| @@ -79,8 +79,8 @@ For example, if you want to truncate `1234-super_super_long_branch_name` to `123 ```zsh P9K_VCS_SHORTEN_LENGTH=4 P9K_VCS_SHORTEN_MIN_LENGTH=11 -P9K_VCS_DIR_SHORTEN_STRATEGY="truncate_from_right" -P9K_VCS_DIR_SHORTEN_DELIMITER=".." +P9K_VCS_SHORTEN_STRATEGY="truncate_from_right" +P9K_VCS_SHORTEN_DELIMITER=".." ``` ### Advanced features From ab3a6ede52a663b2b79eaf1d2306df3b9cff3c95 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 13 Apr 2019 01:20:40 +0200 Subject: [PATCH 04/10] Add documentation about git-gather-data and git-branch hooks --- segments/vcs/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/segments/vcs/README.md b/segments/vcs/README.md index 918eb1977..099bcbbef 100644 --- a/segments/vcs/README.md +++ b/segments/vcs/README.md @@ -27,7 +27,7 @@ customization is provided via: |`P9K_VCS_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| |`P9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.| |`P9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.| -|`P9K_VCS_GIT_HOOKS`|`(vcs-detect-changes vcs-icon git-untracked git-aheadbehind git-stash git-remotebranch git-gitdir git-tagname)`|Layout of the segment for git repositories.| +|`P9K_VCS_GIT_HOOKS`|`(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch git-remotebranch git-gitdir git-tagname)`|Layout of the segment for git repositories.| |`P9K_VCS_HG_HOOKS`|`(vcs-detect-changes)`|Layout of the segment for Mercurial repositories.| |`P9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.| |`P9K_VCS_ACTIONFORMAT_FOREGROUND`|`red`|The color of the foreground font during actions (e.g., `REBASE`).| @@ -94,9 +94,11 @@ Git hooks (`P9K_VCS_GIT_HOOKS`): |--------------------|----------------------------------------------------| | vcs-detect-changes | General check for changed files and responsible for selecting a proper icon according to the remote url. | | vcs-icon | Detects the icon base on the remote url. E.g. shows the Github icon for a repository cloned from Github. If no remote given, it uses the default icon from `P9K_VCS_GIT_ICON`. | +| git-gather-data | Internal hook, that saves the branch name in an internal array. Necessary for showing the local/remote branch. | | git-untracked | Check for untracked files. | | git-aheadbehind | Check for commits ahead/behind the repo. This does not request changes from the remote repo. Only interacts with the local repo. | | git-stash | Check for stashes. | +| git-branch | Display the local branch and truncates it, if configured. | | git-remotebranch | Checks the remote branch, and displays it, if it differs from local branch name. | | git-gitdir | Responsible to find out if we are in a clobbered checkout. | | git-tagname | Get the tagname, if we are on a tag. | From c77d3104e2f5797813c6c7ec7f634de9adb0fe2c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 13 Apr 2019 01:25:15 +0200 Subject: [PATCH 05/10] Add documentation for P9K_VCS_REMOTE_DELIMITER --- segments/vcs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/segments/vcs/README.md b/segments/vcs/README.md index 099bcbbef..c7d739cdf 100644 --- a/segments/vcs/README.md +++ b/segments/vcs/README.md @@ -32,6 +32,7 @@ customization is provided via: |`P9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.| |`P9K_VCS_ACTIONFORMAT_FOREGROUND`|`red`|The color of the foreground font during actions (e.g., `REBASE`).| |`P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH`|`false`|Set to true If you would to always see the remote branch.| +|`P9K_VCS_REMOTE_DELIMITER`|`@`|This delimits the remote name from the remote branch. E.g. `master@origin`.| ### vcs symbols From ceb4dd3958c68b0de7916c7ecd03fa6bbe947707 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 23 Apr 2019 00:49:57 +0200 Subject: [PATCH 06/10] Improve tests --- segments/vcs/vcs_git.spec | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/segments/vcs/vcs_git.spec b/segments/vcs/vcs_git.spec index b963109b8..354e7ea3f 100755 --- a/segments/vcs/vcs_git.spec +++ b/segments/vcs/vcs_git.spec @@ -415,7 +415,7 @@ function testRemoteBranchNameIdenticalToTag() { function testAlwaysShowRemoteBranch() { P9K_LEFT_PROMPT_ELEMENTS=(vcs) - local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='true' + local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='false' local P9K_VCS_HIDE_TAGS='true' source "${P9K_HOME}/segments/vcs/vcs.p9k" @@ -426,10 +426,14 @@ function testAlwaysShowRemoteBranch() { git clone . ../vcs-test2 1>/dev/null 2>&1 cd ../vcs-test2 - assertEquals "%K{002} %F{000} master→master@origin %k%F{002}%f " "$(__p9k_build_left_prompt)" - - local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='false' assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)" + + git remote rename origin some/remote + local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='true' + assertEquals "%K{002} %F{000} master→master@some/remote %k%F{002}%f " "$(__p9k_build_left_prompt)" + + git branch -m master new/ref/master + assertEquals "%K{002} %F{000} new/ref/master→master@some/remote %k%F{002}%f " "$(__p9k_build_left_prompt)" } function testGitDirClobber() { From 1f54ede5c94818e9cd053f7912794d69b9fd56e8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 May 2019 00:45:25 +0200 Subject: [PATCH 07/10] Switch remote and local branch --- segments/vcs/vcs.p9k | 12 ++++++++---- segments/vcs/vcs_git.spec | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/segments/vcs/vcs.p9k b/segments/vcs/vcs.p9k index 2bb8ba852..22da66053 100644 --- a/segments/vcs/vcs.p9k +++ b/segments/vcs/vcs.p9k @@ -138,7 +138,7 @@ p9k::set_default P9K_VCS_HIDE_TAGS false p9k::set_default P9K_VCS_INTERNAL_HASH_LENGTH "8" # Default: Just display the first 8 characters of our changeset-ID. p9k::set_default P9K_VCS_SHORTEN_DELIMITER $'\u2026' - p9k::set_default P9K_VCS_REMOTE_DELIMITER "@" + p9k::set_default P9K_VCS_REMOTE_DELIMITER ":" p9k::set_default P9K_VCS_SHOW_SUBMODULE_DIRTY true p9k::set_default P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH false p9k::set_default P9K_VCS_SHOW_CHANGESET false @@ -188,6 +188,10 @@ function +vi-git-aheadbehind() { hook_com[misc]+=${(j::)gitstatus} } +function +vi-git-branch-icon() { + hook_com[branch]+="${__P9K_ICONS[VCS_BRANCH]}" +} + function +vi-git-branch() { local branch="${__P9K_VCS_DATA[branch]}" @@ -205,7 +209,7 @@ function +vi-git-branch() { fi fi - hook_com[branch]+="${__P9K_ICONS[VCS_BRANCH]}${branch}" + hook_com[branch]+="${branch}" } function +vi-git-remotebranch() { @@ -222,7 +226,7 @@ function +vi-git-remotebranch() { # Remote Branch is the remote branch name, without the remote name. # Additionally, remove trailing whitespace and escape percent signs. local remote_branch=${${${remote#${remote_name}/}// /}//\%/%%} - hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${remote_branch}${P9K_VCS_REMOTE_DELIMITER}${remote_name}" + hook_com[branch]+="${remote_name}${P9K_VCS_REMOTE_DELIMITER}${remote_branch}${__P9K_ICONS[VCS_REMOTE_BRANCH]}" fi } @@ -400,7 +404,7 @@ __p9k_vcs_init() { # Hooks are places in vcs_info where you can run your own code. That code can communicate with the code that called it and through that, change the system’s behaviour. # For configuration, hooks change the style context: # :vcs_info:vcs-string+hook-name:user-context:repo-root-name - p9k::defined P9K_VCS_GIT_HOOKS || P9K_VCS_GIT_HOOKS=(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch git-remotebranch git-gitdir git-tagname) + p9k::defined P9K_VCS_GIT_HOOKS || P9K_VCS_GIT_HOOKS=(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch-icon git-remotebranch git-branch git-gitdir git-tagname) zstyle ':vcs_info:git*+set-message:*' hooks ${P9K_VCS_GIT_HOOKS} p9k::defined P9K_VCS_HG_HOOKS || P9K_VCS_HG_HOOKS=(vcs-detect-changes vcs-icon hg-branch) zstyle ':vcs_info:hg*+set-message:*' hooks ${P9K_VCS_HG_HOOKS} diff --git a/segments/vcs/vcs_git.spec b/segments/vcs/vcs_git.spec index 354e7ea3f..1c0288e07 100755 --- a/segments/vcs/vcs_git.spec +++ b/segments/vcs/vcs_git.spec @@ -430,10 +430,10 @@ function testAlwaysShowRemoteBranch() { git remote rename origin some/remote local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='true' - assertEquals "%K{002} %F{000} master→master@some/remote %k%F{002}%f " "$(__p9k_build_left_prompt)" + assertEquals "%K{002} %F{000} some/remote:master→master %k%F{002}%f " "$(__p9k_build_left_prompt)" git branch -m master new/ref/master - assertEquals "%K{002} %F{000} new/ref/master→master@some/remote %k%F{002}%f " "$(__p9k_build_left_prompt)" + assertEquals "%K{002} %F{000} some/remote:master→new/ref/master %k%F{002}%f " "$(__p9k_build_left_prompt)" } function testGitDirClobber() { From 6f43bb994d284640c43b515e3c53286bf67b91bd Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 May 2019 00:57:37 +0200 Subject: [PATCH 08/10] Show the local branch name first --- segments/vcs/vcs.p9k | 4 ++-- segments/vcs/vcs_git.spec | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/segments/vcs/vcs.p9k b/segments/vcs/vcs.p9k index 22da66053..6b6914f3f 100644 --- a/segments/vcs/vcs.p9k +++ b/segments/vcs/vcs.p9k @@ -226,7 +226,7 @@ function +vi-git-remotebranch() { # Remote Branch is the remote branch name, without the remote name. # Additionally, remove trailing whitespace and escape percent signs. local remote_branch=${${${remote#${remote_name}/}// /}//\%/%%} - hook_com[branch]+="${remote_name}${P9K_VCS_REMOTE_DELIMITER}${remote_branch}${__P9K_ICONS[VCS_REMOTE_BRANCH]}" + hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${remote_name}${P9K_VCS_REMOTE_DELIMITER}${remote_branch}" fi } @@ -404,7 +404,7 @@ __p9k_vcs_init() { # Hooks are places in vcs_info where you can run your own code. That code can communicate with the code that called it and through that, change the system’s behaviour. # For configuration, hooks change the style context: # :vcs_info:vcs-string+hook-name:user-context:repo-root-name - p9k::defined P9K_VCS_GIT_HOOKS || P9K_VCS_GIT_HOOKS=(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch-icon git-remotebranch git-branch git-gitdir git-tagname) + p9k::defined P9K_VCS_GIT_HOOKS || P9K_VCS_GIT_HOOKS=(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch-icon git-branch git-remotebranch git-gitdir git-tagname) zstyle ':vcs_info:git*+set-message:*' hooks ${P9K_VCS_GIT_HOOKS} p9k::defined P9K_VCS_HG_HOOKS || P9K_VCS_HG_HOOKS=(vcs-detect-changes vcs-icon hg-branch) zstyle ':vcs_info:hg*+set-message:*' hooks ${P9K_VCS_HG_HOOKS} diff --git a/segments/vcs/vcs_git.spec b/segments/vcs/vcs_git.spec index 1c0288e07..662af6830 100755 --- a/segments/vcs/vcs_git.spec +++ b/segments/vcs/vcs_git.spec @@ -430,10 +430,10 @@ function testAlwaysShowRemoteBranch() { git remote rename origin some/remote local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='true' - assertEquals "%K{002} %F{000} some/remote:master→master %k%F{002}%f " "$(__p9k_build_left_prompt)" + assertEquals "%K{002} %F{000} master→some/remote:master %k%F{002}%f " "$(__p9k_build_left_prompt)" git branch -m master new/ref/master - assertEquals "%K{002} %F{000} some/remote:master→new/ref/master %k%F{002}%f " "$(__p9k_build_left_prompt)" + assertEquals "%K{002} %F{000} new/ref/master→some/remote:master %k%F{002}%f " "$(__p9k_build_left_prompt)" } function testGitDirClobber() { From be390fe744e819cdcd8ac3bf38559485498b95f3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 May 2019 08:17:30 +0200 Subject: [PATCH 09/10] Show branch icon only if there is a branch --- segments/vcs/vcs.p9k | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/segments/vcs/vcs.p9k b/segments/vcs/vcs.p9k index 6b6914f3f..e3581168f 100644 --- a/segments/vcs/vcs.p9k +++ b/segments/vcs/vcs.p9k @@ -189,7 +189,7 @@ function +vi-git-aheadbehind() { } function +vi-git-branch-icon() { - hook_com[branch]+="${__P9K_ICONS[VCS_BRANCH]}" + [[ -n "${__P9K_VCS_DATA[branch]}" ]] && hook_com[branch]+="${__P9K_ICONS[VCS_BRANCH]}" } function +vi-git-branch() { From 77b43b4c08f14528a78657648b392d17a6b209ab Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 9 May 2019 08:18:00 +0200 Subject: [PATCH 10/10] Add documentation about git-branch-icon hook --- segments/vcs/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/segments/vcs/README.md b/segments/vcs/README.md index c7d739cdf..7b28ac2a9 100644 --- a/segments/vcs/README.md +++ b/segments/vcs/README.md @@ -27,7 +27,7 @@ customization is provided via: |`P9K_VCS_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| |`P9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.| |`P9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.| -|`P9K_VCS_GIT_HOOKS`|`(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch git-remotebranch git-gitdir git-tagname)`|Layout of the segment for git repositories.| +|`P9K_VCS_GIT_HOOKS`|`(vcs-detect-changes vcs-icon git-gather-data git-untracked git-aheadbehind git-stash git-branch-icon git-branch git-remotebranch git-gitdir git-tagname)`|Layout of the segment for git repositories.| |`P9K_VCS_HG_HOOKS`|`(vcs-detect-changes)`|Layout of the segment for Mercurial repositories.| |`P9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.| |`P9K_VCS_ACTIONFORMAT_FOREGROUND`|`red`|The color of the foreground font during actions (e.g., `REBASE`).| @@ -99,6 +99,7 @@ Git hooks (`P9K_VCS_GIT_HOOKS`): | git-untracked | Check for untracked files. | | git-aheadbehind | Check for commits ahead/behind the repo. This does not request changes from the remote repo. Only interacts with the local repo. | | git-stash | Check for stashes. | +| git-branch-icon | Shows an icon for the branch. | | git-branch | Display the local branch and truncates it, if configured. | | git-remotebranch | Checks the remote branch, and displays it, if it differs from local branch name. | | git-gitdir | Responsible to find out if we are in a clobbered checkout. |