From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5641 invoked by alias); 18 Jan 2016 02:47:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37665 Received: (qmail 7506 invoked from network); 18 Jan 2016 02:47:58 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=fcP LAH0fAGkPLUjV5W6PRfmGABg=; b=m3d8bXHrJNsvJewCVK26crF760eNfhz3a+Z 7DIZ+9x/Nt6N3Dcm7AYMTws8+CVBch3F4VMGDhtSbj4IWPGrqMfNRdP1WOyeec0Y z0jVE6dcajs3I0jsEgWso6DePhOsJTtJURNOUEpRfrS4SXyffpC3vngVc9gYZ1Ty 04CD/nbI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=fc PLAH0fAGkPLUjV5W6PRfmGABg=; b=ZHYsu9N+ewOj0LkccaUisiJZ0y8LlHM+TZ bqRoJPzuHgETjPL5iKvK76mSa/3dA9+b3yOt4DPXtL5lmPLQgVbaSp1+DvjP2kL9 0b/W6iePvF0sk4R04yD6M3YNpAhQgORbEjct0OlobYcPbvfXJft9qSimtPsL9io/ QISl8+Eac= X-Sasl-enc: jWoKdydWnCP0qt5SPeSUhul8GWQfoQskcWNoXkNBecoG 1453084621 Date: Mon, 18 Jan 2016 02:36:59 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 2/3] Completion: New helper _absolute_command_paths. Message-ID: <20160118023659.GC1880@tarsus.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) --- Completion/Unix/Command/_git | 8 ++++---- Completion/Unix/Type/_absolute_command_paths | 29 ++++++++++++++++++++++++++++ Doc/Zsh/compsys.yo | 6 ++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 Completion/Unix/Type/_absolute_command_paths diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 2a124c1..ce35219 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -1941,7 +1941,7 @@ _git-config () { 'branch.*.pushremote:what remote git push should push to::__git_remotes' 'branch.*.rebase:rebase on top of fetched branch::->bool:false' 'browser.*.cmd:browser command to use:browser:_cmdstring' - 'browser.*.path:path to use for the browser:absolute browser path:_files -g "*(*)"' + 'browser.*.path:path to use for the browser:absolute browser path:_absolute_command_paths' clean.requireForce:'require --force for git clean to actually do something::->bool:true' color.branch:'color output of git branch::->color-bool:false' color.branch.current:'color of the current branch::->color' @@ -2013,7 +2013,7 @@ _git-config () { diff.suppressBlankEmpty:'inhibit printing space before empty output lines::->bool:false' diff.tool:'diff tool to use::__git_difftools' 'difftool.*.cmd:command to invoke for the diff tool::_cmdstring' - 'difftool.*.path:path to use for the diff tool:absolute diff tool path:_files -g "*(*)"' + 'difftool.*.path:path to use for the diff tool:absolute diff tool path:_absolute_command_paths' difftool.prompt:'prompt before each invocation of the diff tool::->bool:true' diff.wordRegex:'regex used to determine what a word is when performing word-by-word diff:regular expression:->string' diff.guitool:'diff tool with gui to use::__git_difftools' @@ -2180,7 +2180,7 @@ _git-config () { mailmap.file:'augmenting mailmap file:mailmap file:_files' man.viewer:'man viewer to use for help in man format::__git_man_viewers' 'man.*.cmd:the command to invoke the specified man viewer:man command:_cmdstring' - 'man.*.path:path to use for the man viewer:absolute man tool path:_files -g "*(*)"' + 'man.*.path:path to use for the man viewer:absolute man tool path:_absolute_command_paths' merge.branchdesc:'populate the log message with the branch description text as well::->bool:false' merge.conflictstyle:'style used for conflicted hunks::->merge.conflictstyle:merge' merge.defaultToUpstream:'merge the upstream branches configured for the current branch by default::->bool:true' @@ -2194,7 +2194,7 @@ _git-config () { 'merge.*.name:human-readable name for custom low-level merge driver:name:->string' 'merge.*.driver:command that implements a custom low-level merge driver:merge command:_cmdstring' 'merge.*.recursive:low-level merge driver to use when performing internal merge between common ancestors::__git_builtin_merge_drivers' - 'mergetool.*.path:path to use for the merge tool:absolute merge tool path:_files -g "*(*)"' + 'mergetool.*.path:path to use for the merge tool:absolute merge tool path:_absolute_command_paths' 'mergetool.*.cmd:command to invoke for the merge tool:merge command:_cmdstring' 'mergetool.*.trustExitCode:trust the exit code of the merge tool::->bool:false' mergetool.keepBackup:'keep the original file with conflict markers::->bool:true' diff --git a/Completion/Unix/Type/_absolute_command_paths b/Completion/Unix/Type/_absolute_command_paths new file mode 100644 index 0000000..e9ab170 --- /dev/null +++ b/Completion/Unix/Type/_absolute_command_paths @@ -0,0 +1,29 @@ +#autoload + +# This function completes 'ls' to '/bin/ls' +_hashed_absolute_command_paths() { + local -aU set_of_dirs_of_hashed_commands=( ${^commands%/*}/ ) + local i + integer ret=1 + for i in $set_of_dirs_of_hashed_commands + do + compadd -M "l:|=$i" "$expl[@]" -a 'commands[(R)${~i}[^/]#]' + ret=0 + done + return ret +} + +# This function completes absolute pathnames of executables, e.g., /etc/rc.local +_typed-in_absolute_command_paths() { + # TODO: the description "full path to an executable" and tag in the caller are ignored by _path_files + _path_files -/ -g '*(-*)' -P / -W / +} + +_absolute_command_paths() { + _alternative \ + 'commands:hashed command by absolute path:_hashed_absolute_command_paths' \ + 'commands:full path to an executable:_typed-in_absolute_command_paths' +} + + +_absolute_command_paths "$@" diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 9954f30..2aa0740 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3461,6 +3461,12 @@ completion has been tried. A function will only be called once unless it explicitly reinserts itself into the array. startitem() +findex(_absolute_command_paths) +item(tt(_absolute_command_paths))( +This function completes external commands as absolute paths (unlike +tt(_command_names -e) which completes their basenames). It takes no +arguments. +) findex(_all_labels) item(tt(_all_labels) [ tt(-x) ] [ tt(-12VJ) ] var(tag) var(name) var(descr) [ var(command) var(arg) ... ])( This is a convenient interface to the tt(_next_label) function below, -- 2.1.4