Skip to content

Commit

Permalink
Use local wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Dahan committed Aug 21, 2019
1 parent a48bb8b commit da36d6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions functions/geometry_exec_time.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions functions/geometry_git.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand All @@ -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"
}
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions geometry.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit da36d6d

Please sign in to comment.