diff --git a/functions/geometry_exec_time.zsh b/functions/geometry_exec_time.zsh index 21b6ad40..c674ea84 100644 --- a/functions/geometry_exec_time.zsh +++ b/functions/geometry_exec_time.zsh @@ -16,6 +16,7 @@ geometry_exec_time() { [[ -z "$GEOMETRY_EXEC_TIME_FILE" ]] && return [[ -f "$GEOMETRY_EXEC_TIME_FILE" ]] || return local atime=$(zstat +atime $GEOMETRY_EXEC_TIME_FILE) + local elapsed command rm -f $GEOMETRY_EXEC_TIME_FILE (( elapsed = $EPOCHSECONDS - $atime )) (( elapsed > $GEOMETRY_EXEC_TIME_PATIENCE )) && geometry::time $elapsed diff --git a/functions/geometry_git.zsh b/functions/geometry_git.zsh index 4b042e04..79cba414 100644 --- a/functions/geometry_git.zsh +++ b/functions/geometry_git.zsh @@ -12,8 +12,8 @@ geometry_git_time() { [[ -z "$last_commit" ]] && ansi ${GEOMETRY_COLOR_NO_TIME:="white"} ${GEOMETRY_GIT_NO_COMMITS_MESSAGE:="no-commits"} && return - now=$(date +%s) - seconds_since_last_commit=$((now - last_commit)) + local now=$(date +%s) + local seconds_since_last_commit=$((now - last_commit)) geometry::time $seconds_since_last_commit ${GEOMETRY_GIT_TIME_DETAILED:=false} } @@ -27,13 +27,13 @@ geometry_git_status() { : ${GEOMETRY_GIT_SYMBOL_DIRTY:="⬡"} : ${GEOMETRY_GIT_SYMBOL_CLEAN:="⬢"} command git rev-parse --git-dir > /dev/null 2>&1 || return - _status=$([[ -z "$(git status --porcelain --ignore-submodules HEAD)" ]] && [[ -z "$(git ls-files --others --modified --exclude-standard $(git rev-parse --show-toplevel))" ]] && echo CLEAN || echo DIRTY) + local _status=$([[ -z "$(git status --porcelain --ignore-submodules HEAD)" ]] && [[ -z "$(git ls-files --others --modified --exclude-standard $(git rev-parse --show-toplevel))" ]] && echo CLEAN || echo DIRTY) ansi ${(e):-\$GEOMETRY_GIT_COLOR_${_status}} ${(e):-\$GEOMETRY_GIT_SYMBOL_${_status}} } geometry_git_rebase() { : ${GEOMETRY_GIT_SYMBOL_REBASE:="®"} - git_dir=$(git rev-parse --git-dir) + local git_dir=$(git rev-parse --git-dir) [[ -d "$git_dir/rebase-merge" ]] || [[ -d "$git_dir/rebase-apply" ]] || return echo "$GEOMETRY_GIT_SYMBOL_REBASE" } @@ -44,12 +44,12 @@ geometry_git_remote() { : ${GEOMETRY_GIT_SYMBOL_CONFLICTS_SOLVED:="◆"} : ${GEOMETRY_GIT_SYMBOL_CONFLICTS_UNSOLVED:="◈"} - local_commit=$(git rev-parse "@" 2>/dev/null) - remote_commit=$(git rev-parse "@{u}" 2>/dev/null) + local local_commit=$(git rev-parse "@" 2>/dev/null) + local remote_commit=$(git rev-parse "@{u}" 2>/dev/null) [[ $local_commit == "@" || $local_commit == $remote_commit ]] && return - common_base=$(git merge-base "@" "@{u}" 2>/dev/null) # last common commit + local common_base=$(git merge-base "@" "@{u}" 2>/dev/null) # last common commit [[ $common_base == $remote_commit ]] && echo $GEOMETRY_GIT_SYMBOL_UNPUSHED && return [[ $common_base == $local_commit ]] && echo $GEOMETRY_GIT_SYMBOL_UNPULLED && return @@ -61,7 +61,7 @@ geometry_git_symbol() { echo ${(j: :):-$(geometry_git_rebase) $(geometry_git_rem geometry_git_conflicts() { : ${GEOMETRY_GIT_COLOR_CONFLICTS_UNSOLVED:=red} : ${GEOMETRY_GIT_COLOR_CONFLICTS_SOLVED:=green} - conflicts=$(git diff --name-only --diff-filter=U) + local conflicts=$(git diff --name-only --diff-filter=U) [[ -z "$conflicts" ]] && return @@ -71,14 +71,14 @@ geometry_git_conflicts() { (($+commands[ag])) && _grep="ag" (($+commands[rg])) && _grep="rg" - conflict_list=$(${GEOMETRY_GIT_GREP:-$_grep} -cH '^=======$' $conflicts) + local conflict_list=$(${GEOMETRY_GIT_GREP:-$_grep} -cH '^=======$' $conflicts) popd -q - raw_file_count="${#${(@f)conflict_list}}" - file_count=${raw_file_count##*( )} + local raw_file_count="${#${(@f)conflict_list}}" + local file_count=${raw_file_count##*( )} - raw_total=$(echo $conflict_list | cut -d ':' -f2 | paste -sd+ - | bc) - total=${raw_total##*( )} + local raw_total=$(echo $conflict_list | cut -d ':' -f2 | paste -sd+ - | bc) + local total=${raw_total##*( )} [[ -z "$total" ]] && ansi $GEOMETRY_GIT_COLOR_CONFLICTS_SOLVED $GEOMETRY_GIT_SYMBOL_CONFLICTS_SOLVED && return diff --git a/geometry.zsh b/geometry.zsh index 76e333ea..8d248aa8 100644 --- a/geometry.zsh +++ b/geometry.zsh @@ -54,9 +54,10 @@ geometry::wrap() { GEOMETRY_LAST_STATUS="$status" local -a outputs local pwd=$1 + local cmd setopt localoptions noautopushd; builtin cd -q $pwd shift - for cmd in $@; do output=$($cmd); (( $? )) || outputs+=$output; done + for cmd in $@; do local output=$($cmd); (( $? )) || outputs+=$output; done echo "${(ps.${GEOMETRY_SEPARATOR}.)outputs}" } @@ -84,7 +85,7 @@ add-zsh-hook precmd geometry::prompt geometry::info() { # draw info if no command is given [[ -n "$BUFFER" ]] && { zle accept-line && return; } - info="$(geometry::wrap $PWD $GEOMETRY_INFO)" + local info="$(geometry::wrap $PWD $GEOMETRY_INFO)" echo "${(%)info}" && geometry::prompt } zle -N buffer-empty geometry::info