diff --git a/README b/README index 4257001..179dce3 100644 --- a/README +++ b/README @@ -58,7 +58,7 @@ NOTES Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd your- self. Set $_Z_EXCLUDE_DIRS to an array of directories to exclude. - (These settings should go in .bashrc/.zshrc before the lines + (These settings should go in .bashrc/.zshrc before the line added above.) Install the provided man page z.1 somewhere like /usr/local/man/man1. diff --git a/z.1 b/z.1 index 4d2a607..97459de 100644 --- a/z.1 +++ b/z.1 @@ -82,7 +82,7 @@ Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself. Set \fB$_Z_EXCLUDE_DIRS\fR to an array of directories to exclude. .RE .RS -(These settings should go in .bashrc/.zshrc before the lines added above.) +(These settings should go in .bashrc/.zshrc before the line added above.) .RE .RS Install the provided man page \fBz.1\fR somewhere like \fB/usr/local/man/man1\fR. diff --git a/z.sh b/z.sh index d470701..51e4d48 100644 --- a/z.sh +++ b/z.sh @@ -78,7 +78,7 @@ _z() { if [ $? -ne 0 -a -f "$datafile" ]; then env rm -f "$tempfile" else - env mv -f "$tempfile" "$datafile" || env rm -f "$tmpfile" + env mv -f "$tempfile" "$datafile" || env rm -f "$tempfile" fi # tab completion @@ -103,7 +103,7 @@ _z() { else # list/go while [ "$1" ]; do case "$1" in - --) while [ "$1" ]; do shift; local fnd="$fnd $1";done;; + --) while [ "$1" ]; do shift; local fnd="$fnd${fnd:+ }$1";done;; -*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in c) local fnd="^$PWD $fnd";; h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;; @@ -112,7 +112,7 @@ _z() { r) local typ="rank";; t) local typ="recent";; esac; opt=${opt:1}; done;; - *) local fnd="$fnd $1";; + *) local fnd="$fnd${fnd:+ }$1";; esac; local last=$1; shift; done [ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1 @@ -218,7 +218,9 @@ if compctl >/dev/null 2>&1; then _z --add "${PWD:A}" } fi - precmd_functions+=(_z_precmd) + [[ -n "${precmd_functions[(r)_z_precmd]}" ]] || { + precmd_functions[$(($#precmd_functions+1))]=_z_precmd + } } _z_zsh_tab_completion() { # tab completion @@ -233,7 +235,7 @@ elif complete >/dev/null 2>&1; then complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z} [ "$_Z_NO_PROMPT_COMMAND" ] || { # populate directory list. avoid clobbering other PROMPT_COMMANDs. - grep -q "_z --add" <<< "$PROMPT_COMMAND" || { + grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || { PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;' } }