zsh-workers
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: [PATCH] new completion for jot
Date: Thu, 3 Nov 2016 04:23:09 +0900	[thread overview]
Message-ID: <AAF946F6-0348-4F53-BB6B-F0BE26AB8711@kba.biglobe.ne.jp> (raw)

A new completion for jot command (BSD and macOS).


diff --git a/Completion/BSD/Command/_jot b/Completion/BSD/Command/_jot
new file mode 100644
index 0000000..67116d3
--- /dev/null
+++ b/Completion/BSD/Command/_jot
@@ -0,0 +1,80 @@
+#compdef jot
+
+local curcontext="$curcontext" state state_descr line ret=1
+local -A opt_args
+
+_arguments -s -C : \
+  '(-b)-r[generate random data instead of the default sequential data]' \
+  '(-c -p -r -w)-b+[just print the specified word repeatedly]:word:' \
+  '(-b -c -p)-w+[specify output format as in printf]:output format:->format' \
+  '(-b -p -w)-c[same as -w %c]' \
+  '-s+[separate the data by the specified string instead of newline]:string:' \
+  '-n[do not print the final newline]' \
+  '(-b -c -w)-p+[specify number of digits after decimal point]:precision:' \
+  '(-)1: :_guard "^-*" "number of data"' \
+  '2::lower bound:' \
+  '3::upper bound:' \
+  '4:: :->lastarg' && ret=0
+
+case $state in
+  (format)
+    local -a flags digits conversions
+    flags=(
+      '#:alternative form'
+      ' :leave a blank before a positive number'
+      '+:always place a sign before a number'
+      '-:left adjust'
+    )
+    digits=(0 1 2 3 4 5 6 7 8 9 .)
+    conversions=(
+      {d,i}':signed decimal'
+      'o:unsigned octal'
+      'u:unsigned decimal'
+      {x,X}':unsigned hexadecimal'
+      'l'{d,i}':long signed decimal'
+      'lo:long unsigned octal'
+      'lu:long unsigned decimal'
+      'l'{x,X}':long unsigned hexadecimal'
+      'f:double number'
+      {e,E}':double number in scientific notation'
+      {g,G}':use %f or %e, whichever is more appropriate'
+      'c:character'
+    )
+
+    if compset -P '[^%]#%'; then
+      # flags: (|\#)(| )(|+|-)
+      compset -P '(\#|\\\#)' && flags=( ${(@)flags:#\#*} )
+      compset -P '( |\\ )' && flags=( ${(@)flags:#(\#| )*} )
+      compset -P '(+|-)' || compset -P '[0-9]##' && flags=()
+      # width.precision: [0-9]#(|.[0-9]#)
+      if compset -P '.'; then
+	flags=()
+	digits=( ${(@)digits:#.} )
+      fi
+      compset -P '[0-9]#'
+      # conversion specifier: ((|l)[diouxX]|[feEgGc])
+      if compset -P '((|l)[diouxX]|[feEgGc])'; then
+	_message -e format-rest 'rest of the format' && ret=0
+      else
+	(( $#flags )) && _describe -t flags 'flag' flags -S '' && ret=0
+	_describe -t width-precision 'width.precision' digits -S ''  && ret=0
+	_describe -t conversion-specifiers 'conversion specifier' \
+				conversions -S '' && ret=0
+      fi
+    else
+      local expl
+      compset -P '*'
+      _wanted start-specification expl 'start specification' \
+				compadd -S '' % && ret=0
+    fi
+    ;;
+  (lastarg)
+    if (( $+opt_args[-r] )); then
+      _message -e seeds 'random number seed' && ret=0
+    else
+      _message -e steps 'step size' && ret=0
+    fi
+    ;;
+esac
+
+return ret





             reply	other threads:[~2016-11-02 20:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02 19:23 Jun T. [this message]
2016-11-07 10:20 ` Jun T.

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=AAF946F6-0348-4F53-BB6B-F0BE26AB8711@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).