From 594ad21b326550c946a88f0fc5a868e76443d31c Mon Sep 17 00:00:00 2001 From: Jacob Olson Date: Wed, 6 Mar 2024 13:54:44 -0700 Subject: [PATCH 1/4] enabled showing number of stashes for themes --- lib/git.zsh | 19 ++++++++++++++++--- themes/af-magic.zsh-theme | 8 +++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index f049f73c2..e220d83bb 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -19,7 +19,6 @@ function git_prompt_info() { local ref ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \ - || ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \ || ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \ || return 0 @@ -36,6 +35,8 @@ function git_prompt_info() { # Checks if working tree is dirty function parse_git_dirty() { local STATUS + local STASH_STATUS + local STASH_VALID=false local -a FLAGS FLAGS=('--porcelain') if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then @@ -53,11 +54,23 @@ function parse_git_dirty() { ;; esac STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1) + STASH_STATUS="$(git stash list | wc -l)" + fi + if [[ ! -z ${ZSH_THEME_GIT_PROMPT_STASH} && ! -z ${ZSH_THEME_GIT_PROMPT_STASH_DIRTY} && ! -z ${ZSH_THEME_GIT_RESET_COLOR} ]]; then + STASH_VALID=true fi if [[ -n $STATUS ]]; then - echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + if [[ ! -z ${STASH_STATUS} && ${STASH_STATUS} != 0 && ${STASH_VALID} == true ]]; then + echo "${ZSH_THEME_GIT_PROMPT_STASH_DIRTY}${STASH_STATUS}${ZSH_THEME_GIT_RESET_COLOR}" + else + echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + fi else - echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + if [[ ! -z ${STASH_STATUS} && ${STASH_STATUS} != 0 && ${STASH_VALID} ]]; then + echo "$ZSH_THEME_GIT_PROMPT_STASH${STASH_STATUS}${ZSH_THEME_GIT_RESET_COLOR}" + else + echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + fi fi } diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme index 70549d01f..9e8b1b11f 100644 --- a/themes/af-magic.zsh-theme +++ b/themes/af-magic.zsh-theme @@ -6,12 +6,11 @@ # dashed separator size function afmagic_dashes { # check either virtualenv or condaenv variables - local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" - local python_env="${python_env_dir##*/}" + local python_env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" # if there is a python virtual environment and it is displayed in # the prompt, account for it when returning the number of dashes - if [[ -n "$python_env" && "$PS1" = *\(${python_env}\)* ]]; then + if [[ -n "$python_env" && "$PS1" = \(* ]]; then echo $(( COLUMNS - ${#python_env} - 3 )) else echo $COLUMNS @@ -34,6 +33,9 @@ RPS1+=" ${FG[237]}%n@%m%{$reset_color%}" ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[075]}(${FG[078]}" ZSH_THEME_GIT_PROMPT_CLEAN="" ZSH_THEME_GIT_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_STASH="${FG[214]}\$" +ZSH_THEME_GIT_RESET_COLOR="%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_STASH_DIRTY="${FG[214]}*\$" ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}" # hg settings From 7e9fa1a5f8f0fc15a7eba3693e222a3500ceeca7 Mon Sep 17 00:00:00 2001 From: Jacob Olson Date: Wed, 6 Mar 2024 14:05:02 -0700 Subject: [PATCH 2/4] I dont know why these changes were showing up. but I reverted them --- lib/git.zsh | 1 + themes/af-magic.zsh-theme | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index e220d83bb..7e6fdae65 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -19,6 +19,7 @@ function git_prompt_info() { local ref ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \ + || ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \ || ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \ || return 0 diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme index 9e8b1b11f..b7113d2d3 100644 --- a/themes/af-magic.zsh-theme +++ b/themes/af-magic.zsh-theme @@ -6,8 +6,8 @@ # dashed separator size function afmagic_dashes { # check either virtualenv or condaenv variables - local python_env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" - + local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" + local python_env="${python_env_dir##*/}" # if there is a python virtual environment and it is displayed in # the prompt, account for it when returning the number of dashes if [[ -n "$python_env" && "$PS1" = \(* ]]; then From 80d1f26501b9f111681e5e4ac0d6600a8c5f896b Mon Sep 17 00:00:00 2001 From: Jacob Olson Date: Wed, 6 Mar 2024 14:06:53 -0700 Subject: [PATCH 3/4] mend --- themes/af-magic.zsh-theme | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme index b7113d2d3..5c883a3e6 100644 --- a/themes/af-magic.zsh-theme +++ b/themes/af-magic.zsh-theme @@ -6,11 +6,12 @@ # dashed separator size function afmagic_dashes { # check either virtualenv or condaenv variables - local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" - local python_env="${python_env_dir##*/}" + local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" + local python_env="${python_env_dir##*/}" + # if there is a python virtual environment and it is displayed in # the prompt, account for it when returning the number of dashes - if [[ -n "$python_env" && "$PS1" = \(* ]]; then + if [[ -n "$python_env" && "$PS1" = *\(${python_env}\)* ]]; then echo $(( COLUMNS - ${#python_env} - 3 )) else echo $COLUMNS From 489ead1c25a61d0b78b14e9d5e2cd7dab61ebf3a Mon Sep 17 00:00:00 2001 From: Jacob Olson Date: Wed, 6 Mar 2024 14:07:52 -0700 Subject: [PATCH 4/4] mend --- themes/af-magic.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme index 5c883a3e6..73204afa3 100644 --- a/themes/af-magic.zsh-theme +++ b/themes/af-magic.zsh-theme @@ -8,7 +8,7 @@ function afmagic_dashes { # check either virtualenv or condaenv variables local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" local python_env="${python_env_dir##*/}" - + # if there is a python virtual environment and it is displayed in # the prompt, account for it when returning the number of dashes if [[ -n "$python_env" && "$PS1" = *\(${python_env}\)* ]]; then