Skip to content

Commit c198e95

Browse files
committed
Account for possibility that HOME is /
1 parent 0d73056 commit c198e95

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

agkozak-zsh-prompt.plugin.zsh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,23 @@ _agkozak_prompt_dirtrim() {
164164
*) print -Pn "%($(($1 + 1))/|.../%${1}d|%d)" ;;
165165
esac
166166
else
167+
local dir dir_count
168+
case $HOME in
169+
/) dir=${PWD} ;;
170+
*) dir=${PWD#$HOME} ;;
171+
esac
167172
# The number of directory elements is the number of slashes in ${PWD#$HOME}
168-
local dir_count=$((${#${PWD#$HOME}} - ${#${${PWD#HOME}//\//}}))
173+
dir_count=$((${#dir} - ${#${dir//\//}}))
169174

170175
if (( dir_count <= $1 )); then
171176
case $PWD in
172-
${HOME}*) printf '~%s' "${PWD#$HOME}" ;;
177+
${HOME}) printf '%s' '~' ;;
178+
${HOME}*) printf '~%s' "${dir}" ;;
173179
*) print -n "$PWD" ;;
174180
esac
175181
else
176182
local lopped_path i
177-
lopped_path=${PWD#$HOME}
183+
lopped_path=${dir}
178184
i=0
179185
while (( i != $1 )); do
180186
lopped_path=${lopped_path%\/*}

0 commit comments

Comments
 (0)