From 126f58b201a9dc919ef072c25fec0ae6b915bb55 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 31 Aug 2016 15:08:49 +0000 Subject: [PATCH 1/2] Declare variables global/local --- zshrc.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/zshrc.sh b/zshrc.sh index d4010c1e..d88f5c36 100644 --- a/zshrc.sh +++ b/zshrc.sh @@ -24,7 +24,7 @@ add-zsh-hook precmd precmd_update_git_vars function preexec_update_git_vars() { case "$2" in git*|hub*|gh*|stg*) - __EXECUTED_GIT_COMMAND=1 + typeset -g __EXECUTED_GIT_COMMAND=1 ;; esac } @@ -43,6 +43,7 @@ function chpwd_update_git_vars() { function update_current_git_vars() { unset __CURRENT_GIT_STATUS + local _GIT_STATUS if [[ "$GIT_PROMPT_EXECUTABLE" == "python" ]]; then local gitstatus="$__GIT_PROMPT_DIR/gitstatus.py" _GIT_STATUS=`python ${gitstatus} 2>/dev/null` @@ -50,21 +51,22 @@ function update_current_git_vars() { if [[ "$GIT_PROMPT_EXECUTABLE" == "haskell" ]]; then _GIT_STATUS=`git status --porcelain --branch &> /dev/null | $__GIT_PROMPT_DIR/src/.bin/gitstatus` fi - __CURRENT_GIT_STATUS=("${(@s: :)_GIT_STATUS}") - GIT_BRANCH=$__CURRENT_GIT_STATUS[1] - GIT_AHEAD=$__CURRENT_GIT_STATUS[2] - GIT_BEHIND=$__CURRENT_GIT_STATUS[3] - GIT_STAGED=$__CURRENT_GIT_STATUS[4] - GIT_CONFLICTS=$__CURRENT_GIT_STATUS[5] - GIT_CHANGED=$__CURRENT_GIT_STATUS[6] - GIT_UNTRACKED=$__CURRENT_GIT_STATUS[7] + + typeset -ga __CURRENT_GIT_STATUS=("${(@s: :)_GIT_STATUS}") + typeset -g GIT_BRANCH=$__CURRENT_GIT_STATUS[1] + typeset -g GIT_AHEAD=$__CURRENT_GIT_STATUS[2] + typeset -g GIT_BEHIND=$__CURRENT_GIT_STATUS[3] + typeset -g GIT_STAGED=$__CURRENT_GIT_STATUS[4] + typeset -g GIT_CONFLICTS=$__CURRENT_GIT_STATUS[5] + typeset -g GIT_CHANGED=$__CURRENT_GIT_STATUS[6] + typeset -g GIT_UNTRACKED=$__CURRENT_GIT_STATUS[7] } git_super_status() { precmd_update_git_vars if [ -n "$__CURRENT_GIT_STATUS" ]; then - STATUS="$ZSH_THEME_GIT_PROMPT_PREFIX$ZSH_THEME_GIT_PROMPT_BRANCH$GIT_BRANCH%{${reset_color}%}" + local STATUS="$ZSH_THEME_GIT_PROMPT_PREFIX$ZSH_THEME_GIT_PROMPT_BRANCH$GIT_BRANCH%{${reset_color}%}" if [ "$GIT_BEHIND" -ne "0" ]; then STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND$GIT_BEHIND%{${reset_color}%}" fi From 3f1d7b258ff6ac54fd5a02a61aa8f36c7901aa2b Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 11 Sep 2016 20:57:51 +0000 Subject: [PATCH 2/2] typeset more global variables These aren't in functions so won't cause warnings normally, but they can do if zshrc.sh is sourced from inside a function --- zshrc.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/zshrc.sh b/zshrc.sh index d88f5c36..6ee7e2af 100644 --- a/zshrc.sh +++ b/zshrc.sh @@ -95,16 +95,16 @@ git_super_status() { } # Default values for the appearance of the prompt. Configure at will. -ZSH_THEME_GIT_PROMPT_PREFIX="(" -ZSH_THEME_GIT_PROMPT_SUFFIX=")" -ZSH_THEME_GIT_PROMPT_SEPARATOR="|" -ZSH_THEME_GIT_PROMPT_BRANCH="%{$fg_bold[magenta]%}" -ZSH_THEME_GIT_PROMPT_STAGED="%{$fg[red]%}%{●%G%}" -ZSH_THEME_GIT_PROMPT_CONFLICTS="%{$fg[red]%}%{✖%G%}" -ZSH_THEME_GIT_PROMPT_CHANGED="%{$fg[blue]%}%{✚%G%}" -ZSH_THEME_GIT_PROMPT_BEHIND="%{↓%G%}" -ZSH_THEME_GIT_PROMPT_AHEAD="%{↑%G%}" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{…%G%}" -ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_PREFIX="(" +typeset -g ZSH_THEME_GIT_PROMPT_SUFFIX=")" +typeset -g ZSH_THEME_GIT_PROMPT_SEPARATOR="|" +typeset -g ZSH_THEME_GIT_PROMPT_BRANCH="%{$fg_bold[magenta]%}" +typeset -g ZSH_THEME_GIT_PROMPT_STAGED="%{$fg[red]%}%{●%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_CONFLICTS="%{$fg[red]%}%{✖%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_CHANGED="%{$fg[blue]%}%{✚%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_BEHIND="%{↓%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_AHEAD="%{↑%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_UNTRACKED="%{…%G%}" +typeset -g ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}"