Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: completion for a few more coreutils things
- X-seq: zsh-workers 41823
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: completion for a few more coreutils things
- Date: Sat, 07 Oct 2017 00:16:44 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1507328205; bh=utLjMmujS2QpOyzACYWhspXugP1aiyWpFagHlZv4MMY=; h=From:To:Subject:Date:From:Subject; b=f1lCygH8JJKtvdPwt84SrbOIiBc+HiJfJGY95wSQ4xPNMr8rTVxUVTHH5PqphmdW/2btZNFF6hAz8nqAy1gqMY/tbmSLzSyvXwzGjuTse2am7v3DQImcnXHSzIfaCeBQVntHTsHKhroqxPj0O1bWTU36EFy50WXKsRNV2uBl23CQ2Nep2/2fWEPzh4EXNwt1YQpSKHqUv4fYBW/e2qk2YSnt9/BpRV85cy5lMabrcWOi1c2c8+sJTzc+0wjTaYGaTlyprqFrOyY8vUSOfDa5NxO9NNPJU7UovCmTGCoHOu5Ykdvz2dm6eVL/3sSp42rS0tQk890sAusdaFXVp4IB6g==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
There's still a surprising number of utilities in GNU coreutils for
which we still don't have a completion function. For many, a completion
wouldn't be much use - there's lots of variants of sum, commands that
don't really have any options, things that aren't so relevant today
(e.g. pr) and a few oddities that aren't so well known (e.g. ptx).
However coreutils tend to be the sort of thing you'd expect to have a
completion for so I've picked out a few which seemed useful or for which
_gnu_generic doesn't do a great job:
expand, mv, numfmt, seq, split, stdbuf, timeout
There's also minor tweaks to _cp and _unexpand that I noticed in the
process.
As usual, I've also handled Solaris and the usual cluster of BSDs.
Oliver
diff --git a/Completion/Unix/Command/_cp b/Completion/Unix/Command/_cp
index 5c3f37983..88750b330 100644
--- a/Completion/Unix/Command/_cp
+++ b/Completion/Unix/Command/_cp
@@ -55,7 +55,7 @@ else
'netbsd*' "-N[don't copy file flags]" \
'(darwin|dragonfly|freebsd|netbsd)*' '-a[archive mode, same as -RpP]' \
'(dragonfly|freebsd)*' '-l[link files instead of copying]' \
- '(darwin|dragonfly|freebsd|netbsd)*' '-v[show file names as they are copied]' \
+ '(darwin|dragonfly|*bsd)*' '-v[show file names as they are copied]' \
'darwin*' "-X[don't copy extended attributes or resource forks]" \
'(dragonfly|freebsd)*' "-x[don't traverse file systems]" \
'freebsd<10->.*' '-s[make symbolic links instead of copies of non-directories]'
diff --git a/Completion/Unix/Command/_expand b/Completion/Unix/Command/_expand
index e69de29bb..3f297dce2 100644
--- a/Completion/Unix/Command/_expand
+++ b/Completion/Unix/Command/_expand
@@ -0,0 +1,16 @@
+#compdef expand gexpand
+
+local -a args
+
+if _pick_variant gnu=GNU unix --version; then
+ args=(
+ '(-i --initial --help)'{-i,--initial}"[don't convert tabs after non blanks]"
+ '(-t --tabs --version)'{-t+,--tabs=}'[specify tab width]:list of tab positions'
+ '(* -)--help[display usage information]'
+ '(* -)--version[output version information]'
+ )
+else
+ args=( -A "-*" '(-t --tabs)'{-t+,--tabs=}'[specify tab width]:list of tab positions' )
+fi
+
+_arguments -s -S "$args[@]" '*:file:_files'
diff --git a/Completion/Unix/Command/_mv b/Completion/Unix/Command/_mv
index e69de29bb..3592efee6 100644
--- a/Completion/Unix/Command/_mv
+++ b/Completion/Unix/Command/_mv
@@ -0,0 +1,42 @@
+#compdef mv gmv
+
+local args
+if _pick_variant gnu=GNU unix --version; then
+ args=(
+ '(-b --backup -n --no-clobber)--backup=[make a backup of each existing destination file]: : _values "backup type"
+ {none,off}"[never make backups]"
+ {numbered,t}"[make numbered backups]"
+ {existing,nil}"[numbered backups, if they already exist]"
+ {simple,never}"[always make simple backups]"'
+ '(-b --backup -n --no-clobber)-b[make a backup of each existing destination file]'
+ '(-f --force -i --interactive -n --no-clobber)'{-f,--force}"[don't prompt before overwriting]"
+ '(-f --force -i --interactive -n --no-clobber)'{-i,--interactive}'[prompt before overwriting existing file]'
+ '--strip-trailing-slashes[remove any trailing slashes from each source argument]'
+ '(-S --suffix)'{-S+,--suffix=}'[specify the backup suffix]:backup suffix [~]'
+ '(-t --target-directory)'{-t+,--target-directory=}'[move all source arguments into specified directory]:directory:_directories'
+ '(-T --no-target-directory)'{-T,--no-target-directory}'[treat final argument as a normal file]'
+ '(-u --update)'{-u,--update}'[move only when destination file is older or missing]'
+ '(-v --verbose)'{-v,--verbose}'[show file names after they are moved]'
+ '(- *)--help[display usage information]'
+ '(- *)--version[display version information]'
+ )
+ [[ $OSTYPE = linux* ]] && args+=(
+ '(-Z --context)'{-Z,--context}'[set SELinux security context of destination file to default type]'
+ )
+else
+ local pattern arg
+ args=(
+ "(-i -n)-f[don't prompt before overwriting]"
+ '(-f -n)-i[prompt before overwriting existing file]'
+ )
+ for pattern arg in \
+ '(darwin|dragonfly|freebsd)*' "(-f -i)-n[don't overwrite existing file]" \
+ '(darwin|dragonfly|*bsd)*' '-v[show file names after they are moved]' \
+ '(dragonfly|freebsd)*' "-h[if target is a symlink to a directory, don't follow it]"
+ do
+ [[ $OSTYPE = $~pattern ]] && args+=( $arg )
+ done
+fi
+
+_arguments -s -S $args \
+ '*:file:_files'
diff --git a/Completion/Unix/Command/_numfmt b/Completion/Unix/Command/_numfmt
index e69de29bb..999c412a1 100644
--- a/Completion/Unix/Command/_numfmt
+++ b/Completion/Unix/Command/_numfmt
@@ -0,0 +1,24 @@
+#compdef numfmt gnumfmt
+
+local units="((auto\:1K\ =\ 1000,\ 1Ki\ =\ 1024 si\:1K\ =\ 1000 iec\:1K\ =\ 1024 iec-i\:1Ki\ =\ 1024))"
+
+_arguments -S \
+ '(H)--debug[print warnings about invalid input]' \
+ '(H -z --zero-terminated -d --delimiter)'{-d+,--delimiter=}'[use specified field delimiter instead of whitespace]:delimiter' \
+ '(H)--field=[replace numbers in specified input fields]:fields [1]' \
+ '(H)--format=[use printf style floating-point format]:format' \
+ "(H)--from=[auto-scale input numbers to specified units]:unit [none]:$units" \
+ '(H)--from-unit=[specify the input unit size]:unit size [1]' \
+ '(H)--grouping[use locale-defined digit grouping e.g. 1,000,000]' \
+ '(H)--header=-[print (without converting) initial header lines]::header lines [1]' \
+ '(H)--invalid=[specify failure mode for invalid numbers]:mode [abort]:(abort fail warn ignore)' \
+ '(H)--padding=[pad the output to specified width]:width; positive - right-align; negative - left-align' \
+ '(H)--round=[use specified method for rounding when scaling]:method [from-zero]:(up down from-zero towards-zero nearest)' \
+ '(H)--suffix=[add suffix to output numbers and accept optional suffix in input numbers]:suffix' \
+ "(H)--to=[auto-scale output numbers to specified unit]:unit:$units" \
+ '(H)--to-unit=[specify output unit size]:unit size [1]' \
+ '(H -z --zero-terminated -d --delimiter)'{-z,--zero-terminated}'[line delimiter is NUL, not newline]' \
+ '(H)*: :_guard "^-*" number' \
+ + 'H' \
+ '(- *)--help[display usage information]' \
+ '(- *)--version[display version information]'
diff --git a/Completion/Unix/Command/_seq b/Completion/Unix/Command/_seq
index e69de29bb..5b825675f 100644
--- a/Completion/Unix/Command/_seq
+++ b/Completion/Unix/Command/_seq
@@ -0,0 +1,28 @@
+#compdef seq gseq
+
+local variant args
+
+_pick_variant -r variant gnu=GNU $OSTYPE --version
+
+args=( ':: :_guard "^-[^0-9]*" '{first,step,last} )
+case $variant in
+ gnu)
+ args+=(
+ '(--help --version)'{-f+,--format=}'[use printf style floating-point format]:format'
+ '(--help --version -s --separator)'{-s+,--separator=}'[use specified separator for numbers]:separator [\n]'
+ '(--help --version -w --equal-width)'{-w,--equal-width}'[equalize width by padding with leading zeroes]'
+ '(- 1 2 3)--help[display usage information]'
+ '(- 1 2 3)--version[display version information]'
+ )
+ ;;
+ *)
+ args+=(
+ '-f+[use printf style floating-point format]:format'
+ '-s+[use specified separator for numbers]:separator [\n]'
+ '-t+[use specified string to terminate numbers]:string [\n]'
+ '-w[equalize width by padding with leading zeroes]'
+ )
+ ;;
+esac
+
+_arguments -s -A '-[^1-9]*' $args
diff --git a/Completion/Unix/Command/_split b/Completion/Unix/Command/_split
index e69de29bb..25b5aec2d 100644
--- a/Completion/Unix/Command/_split
+++ b/Completion/Unix/Command/_split
@@ -0,0 +1,64 @@
+#compdef split gsplit
+
+local curcontext="$curcontext" variant ret=1
+local -A opt_args
+local -a state line args
+
+_pick_variant -r variant gnu=GNU $OSTYPE --version
+
+args=(
+ '-a+[generate suffixes of specified length]:length [2]' \
+ '(-l -p -n)-b+[put specified size in bytes in each output file]:size (bytes)' \
+ '(-b -p -n)-l+[put specified number of lines/records in each output file]:lines' \
+ '1:file:_files' \
+ '2: :_guard "^-*" "prefix [x]"'
+)
+
+case $variant in
+ gnu)
+ args=( -C
+ '(H -a --suffix-length)'{-a+,--suffix-length=}'[generate suffixes of specified length]:length [2]'
+ '(H)--additional-suffix=[append an additional suffix to file names]:suffix'
+ '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-b+,--bytes=}'[put specified size in bytes in each output file]:size (bytes)'
+ '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-C+,--line-bytes=}'[put whole lines/records up to size limit in each output file]:size (bytes)'
+ '(H --numeric-suffixes -x --hex-suffixes)-d[use numeric suffixes starting at 0]'
+ '(H -d -x --hex-suffixes)--numeric-suffixes=-[use numeric suffixes]::start value [0]'
+ '(H -d --numeric-suffixes --hex-suffixes)-x[use hex suffixes starting at 0]'
+ '(H -d --numeric-suffixes -x)--hex-suffixes=-[use hex suffixes]::start value [0]'
+ '(H -e --elide-empty-files)'{-e,--elide-empty-files}"[don't generate empty output files with '-n']"
+ '(H)--filter=[write to shell command; filename is in $FILE]:command:_cmdstring'
+ '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-l+,--lines=}'[put specified number of lines/records in each output file]:lines'
+ '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-n+,--number=}'[generate specified number of output files]:chunks:->chunks'
+ '(H -t --separator)'{-t+,--separator=}'[use specified record separator instead of newline]:separator'
+ '(H -u --unbuffered)'{-u,--unbuffered}"[immediately copy input to output with '-n r/...']"
+ '(H)--verbose[print a diagnostic just before each output file is opened]'
+ '(H)1:file:_files'
+ '(H)2: :_guard "^-*" "prefix [x]"'
+ + 'H'
+ '(- 1 2)--help[display usage information]'
+ '(- 1 2)--version[display version information]'
+ )
+ ;;
+ (free|net)bsd*)
+ args+=( '(-b -l -p)-n+[generate specified number of output files]:output files' )
+ ;|
+ freebsd*)
+ args+=(
+ '-d[use numeric suffixes]'
+ '(-b -l -n)-p+[split the file whenever a line matches specified pattern]:pattern'
+ )
+ ;;
+esac
+
+_arguments -s -S $args && ret=0
+
+if [[ $state = chunks ]]; then
+ if [[ ! -prefix *[0-9/]* ]]; then
+ _alternative 'modifiers: :_values -s/ "modifier" "l[don'\''t split lines/records]" "r[round robin distribution]"' \
+ 'lines: :_guard "[0-9/]#" lines' && ret=0
+ else
+ _message -e lines lines
+ fi
+fi
+
+return ret
diff --git a/Completion/Unix/Command/_stdbuf b/Completion/Unix/Command/_stdbuf
index e69de29bb..3bce3d0a7 100644
--- a/Completion/Unix/Command/_stdbuf
+++ b/Completion/Unix/Command/_stdbuf
@@ -0,0 +1,30 @@
+#compdef stdbuf
+
+local -a short long buf args
+local i opt gnu=0
+
+short=( -e -i -o )
+long=( --error --output --input )
+buf=( err in out )
+
+opt='[set initial buffering for std${buf[i]}]:mode or size:((0\:unbuffered L\:line\ buffered'
+if _pick_variant gnu=GNU freebsd --version; then
+ gnu=1
+ args=(
+ '(- *)--help[display usage information]'
+ '(- *)--version[display version information]'
+ )
+else
+ opt+=' B\:fully\ buffered'
+fi
+opt+='))'
+
+for ((i=1;i<=3;i++)); do
+ args+=( "(${long[i]})${short[i]}+${(e)opt}" )
+ (( gnu )) && args+=(
+ "(${short[i]})${long[i]}=${(e)opt}"
+ )
+done
+(( CURRENT > 2 )) && args+=( '*::command:_normal' )
+
+_arguments -s -S $args
diff --git a/Completion/Unix/Command/_timeout b/Completion/Unix/Command/_timeout
index e69de29bb..0e6d057b3 100644
--- a/Completion/Unix/Command/_timeout
+++ b/Completion/Unix/Command/_timeout
@@ -0,0 +1,19 @@
+#compdef timeout gtimeout
+
+local args
+
+if [[ $service = g* || $OSTYPE != *bsd* ]]; then
+ # GNU coreutils as opposed to Free/NetBSD implementation
+ args=(
+ '(- *)--help[display usage information]'
+ '(- *)--version[display version information]'
+ )
+fi
+
+_arguments -S -A "-" $args \
+ '--preserve-status[always exit with the same status as command even if it times out]' \
+ "--foreground[don't propagate timeout to the command children]" \
+ '(-s --signal)'{-s,--signal}'[specify the signal to send on timeout]:signal:_signals' \
+ '(-k --kill-after)'{-k,--kill-after}'[followup first signal with SIGKILL if command persists after specified time]:time:time' \
+ '1: :_guard "[0-9.]#([smhd]|)" duration' \
+ '*:::command:_normal'
diff --git a/Completion/Unix/Command/_unexpand b/Completion/Unix/Command/_unexpand
index c983c628f..b1d646231 100644
--- a/Completion/Unix/Command/_unexpand
+++ b/Completion/Unix/Command/_unexpand
@@ -1,4 +1,4 @@
-#compdef unexpand
+#compdef unexpand gunexpand
local all tabs ret=1
local -a args
@@ -7,7 +7,7 @@ all="convert all whitespace, instead of just initial whitespace"
tabs="use comma separated list of tab positions"
args=(
"(--all)-a[$all]"
- "(--tabs)-t[$tabs]:tablist"
+ "(--tabs)-t+[$tabs]:tablist"
"*:file:_files"
)
@@ -21,6 +21,6 @@ if _pick_variant gnu="Free Soft" unix --version; then
)
fi
-_arguments "$args[@]" && ret=0
+_arguments -s -S "$args[@]" && ret=0
return ret
Messages sorted by:
Reverse Date,
Date,
Thread,
Author