Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare variables global/local #90

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions zshrc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -43,28 +43,30 @@ 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`
fi
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}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an error on this line: no matches found: __CURRENT_GIT_STATUS=(). I don't know enough zsh to understand that...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olivierverdier Python or Haskell?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is this is happening because _GIT_STATUS is empty, but I can't see why this change would have affected that…

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
Expand Down Expand Up @@ -93,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%}"