From 51614ca2c994486dc0a41ec0737a97f0af16a505 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 30 Aug 2016 02:56:23 +0000 Subject: [PATCH] 'main': Avoid triggering a zsh bug related to hashed commands. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This manifested in completion of the form «./foo» where there happened to be a program called 'foo' in $PATH. Fixes #354. Closes #355. --- highlighters/main/main-highlighter.zsh | 9 ++++++++- zsh-syntax-highlighting.zsh | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b120bf2..f6194cf 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -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 diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 9de8d61..c20751b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -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