Skip to content

Commit

Permalink
'main': Avoid triggering a zsh bug related to hashed commands.
Browse files Browse the repository at this point in the history
This manifested in completion of the form «./foo<TAB>» where there happened to
be a program called 'foo' in $PATH.

Fixes #354.
Closes #355.
  • Loading branch information
danielshahaf committed Aug 30, 2016
1 parent 11c9081 commit 51614ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ _zsh_highlight_main__type() {
REPLY=builtin
elif (( $+commands[(e)$1] )); then
REPLY=command
elif ! builtin type -w -- $1 >/dev/null 2>&1; then
# zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly
# runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo
# exists and is in $PATH). Avoid triggering the bug, at the expense of
# falling through to the $() below, incurring a fork. (Issue #354.)
#
# The second disjunct mimics the isrelative() C call from the zsh bug.
elif { is-at-least 5.3 || [[ $1 != */* ]] } &&
! builtin type -w -- $1 >/dev/null 2>&1; then
REPLY=none
fi
fi
Expand Down
2 changes: 2 additions & 0 deletions zsh-syntax-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,7 @@ add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
# Load zsh/parameter module if available
zmodload zsh/parameter 2>/dev/null || true

autoload -U is-at-least

# Initialize the array of active highlighters if needed.
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true

0 comments on commit 51614ca

Please sign in to comment.