From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31405 invoked from network); 8 Dec 2021 23:17:30 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Dec 2021 23:17:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ZkR+aYZ/y1V+PCTc8Ne/5OnUia9dDtGEL6PLFYwc02o=; b=pwnOUwd9MatWId4ynPNLj0trDZ eeTSKis+HJjkbkSxX5Y6ODanvzxwxz83A7x5PfzaYHucR4y1HC7f1aBpjq9BLqfSIz04xWOK+LZJz rswq11Z69IVcgK1i4yax2LZzEgBIaaBs41SinQyc5Xc6W2p8oDc7eg08vBjNoKlgH+wvZpsQK0ihS qSVA8xNC+UQeHXmRhG1WRUaJjn+5Ci4Z9DdeCF65WRT8ZY/g5ppTrq8cS7bDHVlhu4zxGeWwsqFn8 J28rY2dRbVdGny4yh89s3vlmLXYFEOqNkVdaG3MWthGgaT7YrQPUYvXRwWFS0J4OuNgCtBOTAgGVv h40E+r4Q==; Received: from authenticated user by zero.zsh.org with local id 1mv6Bl-000Ihu-Th; Wed, 08 Dec 2021 23:17:29 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mv6BD-000IQU-DB; Wed, 08 Dec 2021 23:16:55 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.94.2) (envelope-from ) id 1mv6BC-000Grv-AI; Thu, 09 Dec 2021 00:16:54 +0100 cc: Zsh hackers list In-reply-to: From: Oliver Kiddle References: To: Marlon Richert Subject: Re: [FEATURE][PATCH] Complete local executables with ./ prefix, if prefix-needed is false MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <64845.1639005414.1@hydra> Date: Thu, 09 Dec 2021 00:16:54 +0100 Message-ID: <64846-1639005414.316056@22FL.WcIa.VGfN> X-Seq: 49643 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Marlon Richert wrote: > This allows local executables to be completed more easily, without the > need for . in $path. This is the type of thing which often can already be achieved with styles and, where not, a few tweaks may enable it. The nearest example from my own config involves using the fake style and a matcher to ignore the prefix. But that's for a more specific context[1]. In this case for the style context, the tag 'commands' is used for a lot of commands that aren't external Unix commands. The 'executables' tag is better but guarded by a condition that will evaluate to false: [[ -n "$path[(r).]" || $PREFIX = */* ]] && defs+=( 'executables:executable file:_files -g \*\(-\*\)' The fake style is looked up in _description so a dummy call to it is one option. The patch below adds that but I'd be interested in any thoughts on that. With caveats[2], that allows: zstyle -e ':completion:*:executables' fake 'reply=( ./*(-*) )' zstyle ':completion:*:executables' matcher 'b:=./' There is a command-path style looked up by _command_names to override $path. But that doesn't entirely help for a couple of reasons. External commands are completed based on keys of the commands association but that will not contain commands based on relative directories listed in $path. Even if it did, they can't be identified to add back a ./ prefix so that they actually work. In the patch below, I do change it to use path=( $cmdpath:A ) when the command-path style is set. That resolves only the first of these issues and allows for relative paths in the command-path style to work as intended, even if that isn't especially useful. Oliver [1] If anyone's interested, that example is for ssh public keys. Just the fake and matcher style are needed but it looks like this: zstyle -e ':completion:*:((ssh|scp|sftp):*:option-i-1|ssh-add:*:argument-rest)' fake '[[ -prefix - ]] || reply=( ~/.ssh/id^*.pub(-.) )' zstyle -e ':completion:*:((ssh|scp|sftp):*:option-i-1|ssh-add:*:argument-rest)' matcher '[[ -prefix - ]] || reply=( "l:|=*" )' zstyle ':completion:*:((ssh|scp|sftp):*:option-i-1|ssh-add:*:argument-rest)' menu yes=0 search zstyle ':completion:*:((ssh|scp|sftp):*:option-i-1|ssh-add:*:argument-rest)' list-colors "=(#b)(*/)(*)==38;5;208=0" [2] With the fake style in general, the return status of the calling completion function doesn't account for fake matches which may mean unwanted later completers are invoked (e.g. _approximate). diff --git a/Completion/Zsh/Type/_command_names b/Completion/Zsh/Type/_command_names index b1c35f013..12cbd69c1 100644 --- a/Completion/Zsh/Type/_command_names +++ b/Completion/Zsh/Type/_command_names @@ -4,7 +4,7 @@ # complete only external commands and executable files. This and a # `-' as the first argument is then removed from the arguments. -local args defs ffilt +local args defs expl ffilt zstyle -t ":completion:${curcontext}:commands" rehash && rehash @@ -16,8 +16,12 @@ defs=( 'commands:external command:_path_commands' ) -[[ -n "$path[(r).]" || $PREFIX = */* ]] && - defs+=( 'executables:executable file:_files -g \*\(-\*\)' ) +if [[ -n "$path[(r).]" || $PREFIX = */* ]]; then + defs+=( 'executables:executable file:_files -g \*\(-\*\)' ) +else + # this is ignored but exists to facilitate the use of the fake style + _description executables expl 'executable file' +fi if [[ "$1" = -e ]]; then shift @@ -58,7 +62,7 @@ fi if (( $#cmdpath )); then local -a +h path local -A +h commands - path=( $cmdpath ) + path=( $cmdpath:A ) fi _alternative -O args "$defs[@]"