zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH 2/2] _mkdir: Honour the 'command' and 'builtin' precommand modifiers.
Date: Tue, 29 Aug 2017 02:28:10 +0000	[thread overview]
Message-ID: <20170829022810.485-2-danielsh@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20170829022810.485-1-danielsh@tarpaulin.shahaf.local2>

---
Hi,

This patch implements the "once a way is found out" comment that it removes.

It works correctly on linux:

% mkdir <TAB>
DEBUG: variant=gnu
% zmodload zsh/files
% mkdir <TAB>
DEBUG: variant=zsh

... but it would be good if someone could confirm that it still works on
$OSTYPE == (freebsd|dragonfly)* as well: the code special-cases those
$OSTYPE's.

Thanks,

Daniel

 Completion/Unix/Command/_mkdir | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/Completion/Unix/Command/_mkdir b/Completion/Unix/Command/_mkdir
index b104d3d60..7e8ff121a 100644
--- a/Completion/Unix/Command/_mkdir
+++ b/Completion/Unix/Command/_mkdir
@@ -9,22 +9,21 @@ args=(
   '(-)*: :->directories'
 )
 
-_pick_variant -r variant gnu=gnu zsh='\(eval\)' $OSTYPE --help
 # It can still happen that there is a precommand command or builtin in the line.
 # In such cases, the variant has to be modified suitably, after further checking
 # the variant of the _command_ mkdir.
-
-# I currently don't know of any way to find out what precommands are present on
-# the line. The variant should be modified like this once a way is found out:
-
-# if [[ $variant == zsh ]]; then
-#   if [[ $precommand = *command* ]]; then
-#     _mkdir_command () { command mkdir "$@" }
-#     _pick_variant -c _mkdir_command -r variant gnu=gnu unix --help
-#   fi
-# elif [[ $precommand = *builtin* ]]; then
-#   variant=zsh
-# fi
+# 
+# $precommands is defined in _main_complete
+if (( ${+precommands[(r)command]} )); then
+  _mkdir_command () { command mkdir "$@" }
+  _pick_variant -c _mkdir_command -r variant gnu=gnu unix --help
+  unfunction _mkdir_command
+elif (( ${+precommands[(r)builtin]} )) || (( ${+builtins[mkdir]} )) || [[ "$(type -w mkdir)" == "*: builtin" ]]; then
+  variant=zsh
+else
+  _pick_variant -r variant gnu=gnu zsh='\(eval\)' $OSTYPE --help
+fi
+# Now $variant is set.
 
 case $variant in
   gnu|freebsd*|dragonfly*)


  reply	other threads:[~2017-08-29  2:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29  2:28 [PATCH 1/2] _mkdir: Don't offer a linux-specific optiont in the 'zsh' variant Daniel Shahaf
2017-08-29  2:28 ` Daniel Shahaf [this message]
2017-08-29 11:06 ` Oliver Kiddle
2017-08-30  0:19   ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170829022810.485-2-danielsh@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).