Skip to content

Commit 7e245c6

Browse files
author
jedahan
committed
Prefix builtin for bindkey, echo, print, shift, return, zle, autoload
Defensive in case there are aliases and whatnot
1 parent 75a2aeb commit 7e245c6

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

geometry.zsh

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

7-
typeset -gA GEOMETRY; GEOMETRY[ROOT]=${0:A:h}
7+
builtin typeset -gA GEOMETRY; GEOMETRY[ROOT]=${0:A:h}
88

99
(($+GEOMETRY_PROMPT)) || GEOMETRY_PROMPT=(geometry_echo geometry_status geometry_path)
1010
(($+GEOMETRY_RPROMPT)) || GEOMETRY_RPROMPT=(geometry_exec_time geometry_git geometry_hg geometry_jj geometry_echo)
@@ -13,7 +13,7 @@ typeset -gA GEOMETRY; GEOMETRY[ROOT]=${0:A:h}
1313
(($+GEOMETRY_CMDTITLE)) || GEOMETRY_CMDTITLE=(geometry_cmd geometry_hostname)
1414
(($+GEOMETRY_PATH_TRUNCATE)) || GEOMETRY_PATH_TRUNCATE=3
1515

16-
autoload -U add-zsh-hook
16+
builtin autoload -U add-zsh-hook
1717

1818
function {
1919
local fun
@@ -40,9 +40,9 @@ for fun (
4040
) . "${GEOMETRY[ROOT]}"/functions/$fun
4141
}
4242

43-
(( $+functions[ansi] )) || ansi() { (($# - 2)) || echo -n "%F{$1}$2%f"; }
44-
(( $+functions[deansi] )) || deansi() { (($# - 1)) || echo -n "$(echo "$1" | sed s/$(echo "\033")\\\[\[0-9\]\\\{1,2\\\}m//g)"; }
45-
(( $+functions[geometry_cmd])) || geometry_cmd() { echo $GEOMETRY_LAST_CMD }
43+
(( $+functions[geometry_cmd])) || geometry_cmd() { builtin echo $GEOMETRY_LAST_CMD; }
44+
(( $+functions[ansi] )) || ansi() { (($# - 2)) || builtin echo -n "%F{$1}$2%f"; }
45+
(( $+functions[deansi] )) || deansi() { (($# - 1)) || builtin echo -n "$(echo "$1" | sed s/$(builtin echo "\033")\\\[\[0-9\]\\\{1,2\\\}m//g)"; }
4646

4747
# Takes number of seconds and formats it for humans
4848
# from https://github.com/sindresorhus/pretty-time-zsh
@@ -68,8 +68,8 @@ geometry::time() {
6868
# Generate a color based on hostname.
6969
geometry::hostcolor() {
7070
if (( ${+GEOMETRY_HOST_COLOR} )); then
71-
echo ${GEOMETRY_HOST_COLOR}
72-
return
71+
builtin echo ${GEOMETRY_HOST_COLOR}
72+
builtin return
7373
fi
7474

7575
if (( ${+GEOMETRY_HOST_COLORS} )); then
@@ -79,22 +79,22 @@ geometry::hostcolor() {
7979
(($(echotc Co) == 256)) && colors+=({17..230})
8080
fi
8181

82-
local sum=0; for c in ${(s::)^HOST}; do ((sum += $(print -f '%d' "'$c"))); done
82+
local sum=0; for c in ${(s::)^HOST}; do ((sum += $(builtin print -f '%d' "'$c"))); done
8383
local index="$(($sum % ${#colors}))"
8484

8585
[[ "$index" -eq 0 ]] && index = 1
8686

87-
echo ${colors[${index}]}
87+
builtin echo ${colors[${index}]}
8888
}
8989

9090
# set cmd title (while command is running)
9191
geometry::set_cmdtitle() {
9292
# Make command title available for optional consumption by geometry_cmd
9393
GEOMETRY_LAST_CMD=$2
94-
local ansiCmdTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_CMDTITLE))
94+
local ansiCmdTitle=$(builtin print -P $(geometry::wrap $PWD $GEOMETRY_CMDTITLE))
9595
local cmdTitle=$(deansi "$ansiCmdTitle")
9696

97-
echo -ne "\e]1;$cmdTitle\a"
97+
builtin echo -ne "\e]1;$cmdTitle\a"
9898
}
9999
add-zsh-hook preexec geometry::set_cmdtitle
100100

@@ -103,7 +103,7 @@ geometry::set_title() {
103103
local ansiTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_TITLE))
104104
local title=$(deansi "$ansiTitle")
105105

106-
echo -ne "\e]1;$title\a"
106+
builtin echo -ne "\e]1;$title\a"
107107
}
108108
add-zsh-hook precmd geometry::set_title
109109

@@ -112,26 +112,26 @@ geometry::wrap() {
112112
setopt localoptions noautopushd; builtin cd -q $1
113113
local -a outputs
114114
local cmd output
115-
shift
115+
builtin shift
116116
for cmd in $@; do output=$($cmd); ( (( $? )) || [[ -z "${output// }" ]] ) || outputs+=$output; done
117117

118-
echo "${(ej.${GEOMETRY_SEPARATOR:- }.)outputs}"
118+
builtin echo "${(ej.${GEOMETRY_SEPARATOR:- }.)outputs}"
119119
}
120120

121121
geometry::rprompt::set() {
122122
if [[ -z "$2" || "$2" == "hup" ]]; then
123123
read -r -u "$GEOMETRY_ASYNC_FD" RPROMPT
124-
zle reset-prompt
124+
builtin zle reset-prompt
125125
exec {1}<&-
126126
fi
127-
zle -F "$1"
127+
builtin zle -F "$1"
128128
}
129129

130130
geometry::rprompt() {
131-
typeset -g GEOMETRY_ASYNC_FD=
131+
builtin typeset -g GEOMETRY_ASYNC_FD=
132132
RPROMPT=
133133
exec {GEOMETRY_ASYNC_FD}< <(geometry::wrap $PWD $GEOMETRY_RPROMPT)
134-
zle -F "$GEOMETRY_ASYNC_FD" geometry::rprompt::set
134+
builtin zle -F "$GEOMETRY_ASYNC_FD" geometry::rprompt::set
135135
}
136136

137137
geometry::prompt() {
@@ -144,11 +144,11 @@ add-zsh-hook precmd geometry::prompt
144144
add-zsh-hook precmd geometry::rprompt
145145

146146
geometry::info() { # draw info if no command is given
147-
[[ -n "$BUFFER" ]] && { zle accept-line && return; }
148-
[[ -z "$GEOMETRY_INFO" ]] && { zle accept-line && return; }
149-
echo ${(%):-$(geometry::wrap $PWD $GEOMETRY_INFO)}
147+
[[ -n "$BUFFER" ]] && { builtin zle accept-line && builtin return; }
148+
[[ -z "$GEOMETRY_INFO" ]] && { builtin zle accept-line && builtin return; }
149+
builtin echo ${(%):-$(geometry::wrap $PWD $GEOMETRY_INFO)}
150150
geometry::prompt
151151
}
152-
zle -N buffer-empty geometry::info
153-
bindkey '^M' buffer-empty
152+
builtin zle -N buffer-empty geometry::info
153+
builtin bindkey '^M' buffer-empty
154154
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=buffer-empty

0 commit comments

Comments
 (0)