zsh-workers
 help / color / mirror / code / Atom feed
From: Clint Adams <clint@zsh.org>
To: zsh-workers@sunsite.dk
Subject: PATCH: _mkdir
Date: Tue, 31 Oct 2006 22:01:45 -0500	[thread overview]
Message-ID: <20061101030145.GA31646@scowler.net> (raw)

Another from R.Ramkumar.

Index: Completion/Unix/Command/_mkdir
===================================================================
RCS file: Completion/Unix/Command/_mkdir
diff -N Completion/Unix/Command/_mkdir
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Command/_mkdir	1 Nov 2006 03:00:02 -0000
@@ -0,0 +1,70 @@
+#compdef mkdir
+
+local curcontext="$curcontext" line state \
+  args args_zsh args_cmd variant expl ret=1
+typeset -a opt_args
+
+args=(
+  '(-m --mode=)'{-m,--mode=}'[set permission mode]:numeric mode'
+  '(-p --parents)'{-p,--parents}'[make parent directories as needed]'
+  )
+
+args_zsh=('(-)*: :->dir')
+
+args_cmd=(
+  '(-v --verbose)'{-v,--verbose}'[print message for each created directory]'
+  '(- :)--help[display help information]'
+  '(- :)--version[display version information]'
+  '*: :->dir'
+  )
+
+case "$OSTYPE" in
+  linux*)
+    args_cmd=(
+      '(-Z --context=)'{-Z,--context=}'[set SELinux context]:SELinux context'
+      $args_cmd)
+    ;;
+esac
+
+_pick_variant -r variant gnu=gnu zsh='\(eval\)' unix --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
+
+if [[ $variant == zsh ]]; then
+  args+=($args_zsh)
+else
+  args+=($args_cmd)
+fi
+
+# remove long options?
+[[ $variant != gnu ]] && args=( ${${${args:#(|*\))--*}//--[^ )]#/}/\( #\)/} )
+
+_arguments -C -s $args && ret=0
+
+case "$state" in
+  dir)
+    if (( $ret )) && [[ ! -prefix - ]] || \
+      [[ $variant == zsh && ${#${${words[2,-1]}:#-*}} -gt 0 ]]; then
+      _wanted parent-directory expl \
+	'parent directory (alternatively specify name of directory)' \
+	_path_files -/ || _message 'name of directory'
+      ret=0
+    fi
+    ;;
+esac
+
+return ret


                 reply	other threads:[~2006-11-01  3:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20061101030145.GA31646@scowler.net \
    --to=clint@zsh.org \
    --cc=zsh-workers@sunsite.dk \
    /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).