Skip to content

Commit d5c1109

Browse files
author
Jonathan Dahan
committed
hide some internal variables in GEOMETRY array, fixes #270
1 parent 75b6a1b commit d5c1109

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Accidental export of local `fun` variable
1313
- extra "'" in separator for geometry_hg
1414
- Quoting for zsh 5.0.0 - thanks @psprint
15+
- Hid GEOMETRY_TIME_COLOR_SHORT, NEUTRAL, LONG, ROOT, EXEC_TIME_FILE, and LAST_STATUS under GEOMETRY array
16+
- Renamed PCFD to GEOMETRY_ASYNC_FD
1517

1618
## 2.0.2 - 2019-09-04
1719

functions/geometry_exec_time.zsh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
autoload -U add-zsh-hook
66
zmodload zsh/datetime zsh/stat
77

8-
: ${GEOMETRY_EXEC_TIME_FILE:=$(mktemp)}
8+
: ${GEOMETRY[EXEC_TIME_FILE]:=$(mktemp)}
99
: ${GEOMETRY_EXEC_TIME_PATIENCE:=5} # seconds before showing
1010

1111
# Begin to track the EPOCHSECONDS since this command is executed
12-
geometry::time_command_begin() { touch $GEOMETRY_EXEC_TIME_FILE; }
12+
geometry::time_command_begin() { touch $GEOMETRY[EXEC_TIME_FILE]; }
1313
add-zsh-hook preexec geometry::time_command_begin
1414

1515
geometry_exec_time() {
1616
local atime
1717
local elapsed
18-
[[ -z "$GEOMETRY_EXEC_TIME_FILE" ]] && return
19-
[[ -f "$GEOMETRY_EXEC_TIME_FILE" ]] || return
20-
atime=$(zstat +atime $GEOMETRY_EXEC_TIME_FILE)
21-
command rm -f $GEOMETRY_EXEC_TIME_FILE
18+
[[ -z "$GEOMETRY[EXEC_TIME_FILE]" ]] && return
19+
[[ -f "$GEOMETRY[EXEC_TIME_FILE]" ]] || return
20+
atime=$(zstat +atime $GEOMETRY[EXEC_TIME_FILE])
21+
command rm -f $GEOMETRY[EXEC_TIME_FILE]
2222
(( elapsed = $EPOCHSECONDS - $atime ))
2323
(( elapsed > $GEOMETRY_EXEC_TIME_PATIENCE )) && geometry::time $elapsed
2424
}

functions/geometry_exitcode.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# geometry_exitcode - show the exit code of the last status
22

33
geometry_exitcode() {
4-
(( $GEOMETRY_LAST_STATUS )) && ansi ${GEOMETRY_EXITCODE_COLOR:-red} $GEOMETRY_LAST_STATUS
4+
(( $GEOMETRY[LAST_STATUS] )) && ansi ${GEOMETRY_EXITCODE_COLOR:-red} $GEOMETRY[LAST_STATUS]
55
}

functions/geometry_status.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
geometry_status() {
44
local root; [[ $UID = 0 || $EUID = 0 ]] && root=true || root=false
5-
local error; (( $GEOMETRY_LAST_STATUS )) && error=true || error=false
5+
local error; (( $GEOMETRY[LAST_STATUS] )) && error=true || error=false
66

77
local color=${GEOMETRY_STATUS_COLOR:-default}
88

geometry.zsh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
# pure: https://github.com/sindresorhus/pure
55
# mnml: https://github.com/subnixr/minimal
66

7-
GEOMETRY_ROOT=${0:A:h}
8-
: ${GEOMETRY_SEPARATOR:=" "}
7+
typeset -A GEOMETRY
8+
GEOMETRY[ROOT]=${0:A:h}
9+
: ${GEOMETRY[SEPARATOR]:=" "}
910

1011
(($+GEOMETRY_PROMPT)) || GEOMETRY_PROMPT=(geometry_echo geometry_status geometry_path)
1112
(($+GEOMETRY_RPROMPT)) || GEOMETRY_RPROMPT=(geometry_exec_time geometry_git geometry_hg geometry_echo)
1213
(($+GEOMETRY_INFO)) || GEOMETRY_INFO=(geometry_hostname geometry_jobs)
1314

1415
autoload -U add-zsh-hook
1516

16-
function { local fun; for fun ("${GEOMETRY_ROOT}"/functions/geometry_*.zsh(N.)) . $fun }
17+
function { local fun; for fun ("${GEOMETRY[ROOT]}"/functions/geometry_*.zsh(N.)) . $fun }
1718

1819
(( $+functions[ansi] )) || ansi() { (($# - 2)) || echo -n "%F{$1}$2%f"; }
1920

20-
: ${GEOMETRY_TIME_COLOR_SHORT:=green}
21-
: ${GEOMETRY_TIME_COLOR_NEUTRAL:=default}
22-
: ${GEOMETRY_TIME_COLOR_LONG:=red}
21+
: ${GEOMETRY[TIME_COLOR_SHORT]:=green}
22+
: ${GEOMETRY[TIME_COLOR_NEUTRAL]:=default}
23+
: ${GEOMETRY[TIME_COLOR_LONG]:=red}
2324

2425
# Takes number of seconds and formats it for humans
2526
# from https://github.com/sindresorhus/pretty-time-zsh
@@ -34,10 +35,10 @@ geometry::time() {
3435
m=$(( seconds / 60 % 60 ))
3536
s=$(( seconds % 60 ))
3637

37-
(( d > 0 )) && human+="${d}d" && color=$GEOMETRY_TIME_COLOR_LONG
38-
(( h > 0 )) && human+="${h}h" && : ${color:=$GEOMETRY_TIME_COLOR_NEUTRAL}
38+
(( d > 0 )) && human+="${d}d" && color=$GEOMETRY[TIME_COLOR_LONG]
39+
(( h > 0 )) && human+="${h}h" && : ${color:=$GEOMETRY[TIME_COLOR_NEUTRAL]}
3940
(( m > 0 )) && human+="${m}m"
40-
(( s > 0 )) && human+="${s}s" && : ${color:=$GEOMETRY_TIME_COLOR_SHORT}
41+
(( s > 0 )) && human+="${s}s" && : ${color:=$GEOMETRY[TIME_COLOR_SHORT]}
4142

4243
${2:-false} && ansi $color ${(j: :)human} || ansi $color $human[1]
4344
}
@@ -62,21 +63,21 @@ geometry::wrap() {
6263

6364
geometry::rprompt::set() {
6465
if [[ -z "$2" || "$2" == "hup" ]]; then
65-
read -r -u "$PCFD" RPROMPT
66+
read -r -u "$GEOMETRY_ASYNC_FD" RPROMPT
6667
zle reset-prompt
6768
exec {1}<&-
6869
fi
6970
zle -F "$1"
7071
}
7172

7273
geometry::rprompt() {
73-
typeset -g PCFD
74-
exec {PCFD}< <(geometry::wrap $PWD $GEOMETRY_RPROMPT)
75-
zle -F "$PCFD" geometry::rprompt::set
74+
typeset -g GEOMETRY_ASYNC_FD
75+
exec {GEOMETRY_ASYNC_FD}< <(geometry::wrap $PWD $GEOMETRY_RPROMPT)
76+
zle -F "$GEOMETRY_ASYNC_FD" geometry::rprompt::set
7677
}
7778

7879
geometry::prompt() {
79-
GEOMETRY_LAST_STATUS="$status"
80+
GEOMETRY[LAST_STATUS]="$status"
8081
PROMPT="$(geometry::wrap $PWD $GEOMETRY_PROMPT)$GEOMETRY_SEPARATOR"
8182
geometry::rprompt
8283
}

0 commit comments

Comments
 (0)