* [PATCH] Completion: Add _shuf, _tac, _uptime
@ 2018-06-02 23:07 dana
2018-06-03 4:58 ` dana
0 siblings, 1 reply; 2+ messages in thread
From: dana @ 2018-06-02 23:07 UTC (permalink / raw)
To: Zsh workers
Since i'm in the ML mood anyway, here are three trivial completion functions
i've had sitting in my untracked for quite a while. These relate to shuf and tac
(from GNU Coreutils), and uptime (specifically the procps and GNU variants).
I feel like i had 10 or 20 more of these to send in, but i got discouraged, and
i guess Oliver, Martin, and Jun have taken care of several of them since then.
I'll try to sort through what i had left over and submit the rest soon.
dana
diff --git a/Completion/Unix/Command/_shuf b/Completion/Unix/Command/_shuf
new file mode 100644
index 000000000..83f42e6d3
--- /dev/null
+++ b/Completion/Unix/Command/_shuf
@@ -0,0 +1,28 @@
+#compdef shuf gshuf
+
+local ret=1
+local -a context line state state_descr
+local -A opt_args
+
+_arguments -s -S : \
+ '(: -)--help[display help information]' \
+ '(: -)--version[display version information]' \
+ '(-n --head-count)'{-n+,--head-count=}'[limit output to specified number of lines]:output line limit' \
+ '(-o --output)'{-o+,--output=}'[write result to specified file]:output file:_files' \
+ '--random-source=[use specified file as source of random bytes]: :_files' \
+ '(-r --repeat)'{-r,--repeat}'[allow output lines to repeat]' \
+ '(-z --zero-terminated)'{-z,--zero-terminated}'[use NUL as line delimiter]' \
+ '(-i --input-range)*: :->operands' \
+ + '(excl)' \
+ {-e,--echo}'[treat operands as input lines]' \
+ '(:)'{-i+,--input-range=}'[treat specified numbers as input lines]:number range (x-y)' \
+&& ret=0
+
+[[ $state == operands ]] &&
+if [[ -n ${opt_args[(i)excl-(-e|--echo)]} ]]; then
+ _message 'input line' && ret=0
+else
+ _files && ret=0
+fi
+
+return ret
diff --git a/Completion/Unix/Command/_tac b/Completion/Unix/Command/_tac
new file mode 100644
index 000000000..c2fbf9c6b
--- /dev/null
+++ b/Completion/Unix/Command/_tac
@@ -0,0 +1,9 @@
+#compdef tac gtac
+
+_arguments -s -S : \
+ '(: -)--help[display help information]' \
+ '(: -)--version[display version information]' \
+ '(-b --before)'{-b,--before}'[attach separator before instead of after]' \
+ '(-r --regex)'{-r,--regex}'[treat separator as regular expression (with -s)]' \
+ '(-s --separator)'{-s+,--separator=}'[use specified separator instead of newline]:separator' \
+ '*: :_files'
diff --git a/Completion/Unix/Command/_uptime b/Completion/Unix/Command/_uptime
new file mode 100644
index 000000000..58b4d991b
--- /dev/null
+++ b/Completion/Unix/Command/_uptime
@@ -0,0 +1,26 @@
+#compdef uptime guptime
+
+local variant
+
+_pick_variant -r variant procps=procps gnu='Free Soft' unix --version
+
+case $variant in
+ procps)
+ _arguments -s -S : \
+ '(: -)'{-h,--help}'[display help information]' \
+ '(: -)'{-V,--version}'[display version information]' \
+ + '(excl)' \
+ {-p,--pretty}'[display uptime in pretty format]' \
+ {-s,--since}'[display date/time of system boot]'
+ return
+ ;;
+ gnu)
+ _arguments -S : \
+ '(: -)--help[display help information]' \
+ '(: -)--version[display version information]' \
+ '1:utmp/wtmp file:_files'
+ return
+ ;;
+ # *BSD, Darwin, Solaris, BusyBox
+ *) _message 'no more arguments'; return 1 ;;
+esac
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Completion: Add _shuf, _tac, _uptime
2018-06-02 23:07 [PATCH] Completion: Add _shuf, _tac, _uptime dana
@ 2018-06-03 4:58 ` dana
0 siblings, 0 replies; 2+ messages in thread
From: dana @ 2018-06-03 4:58 UTC (permalink / raw)
To: Zsh workers
On 2 Jun 2018, at 18:07, dana <dana@dana.is> wrote:
>tac (from GNU Coreutils)
Martin alerted me to the fact that NetBSD has recently gained its own version of
tac. Sorry, i should have checked more thoroughly. Anyway, we might as well
support it properly if we're adding stuff — here's a new patch. (The other two
are still fine.)
dana
diff --git a/Completion/Unix/Command/_tac b/Completion/Unix/Command/_tac
new file mode 100644
index 000000000..7a15bffff
--- /dev/null
+++ b/Completion/Unix/Command/_tac
@@ -0,0 +1,19 @@
+#compdef tac gtac
+
+local variant
+
+_pick_variant -r variant gnu='Free Soft' unix --version
+
+# NetBSD (at least) has its own bare-bones version of this tool
+[[ $variant == gnu ]] || {
+ _default
+ return
+}
+
+_arguments -s -S : \
+ '(: -)--help[display help information]' \
+ '(: -)--version[display version information]' \
+ '(-b --before)'{-b,--before}'[attach separator before instead of after]' \
+ '(-r --regex)'{-r,--regex}'[treat separator as regular expression (with -s)]' \
+ '(-s --separator)'{-s+,--separator=}'[use specified separator instead of newline]:separator' \
+ '*: :_files'
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-03 4:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-02 23:07 [PATCH] Completion: Add _shuf, _tac, _uptime dana
2018-06-03 4:58 ` dana
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).