* [PATCH] Completion: Improve _column
@ 2019-02-21 22:19 dana
2019-02-21 22:55 ` dana
0 siblings, 1 reply; 2+ messages in thread
From: dana @ 2019-02-21 22:19 UTC (permalink / raw)
To: zsh workers
Some improvements to column completion:
* Support Debian's customised BSD column (it doesn't use util-linux)
* Fix misdocumented behaviour of BSD `column -x`
* Don't do permutation on non-Debian/util-linux column
* Change -E spec to -E+
* Fix inconsistent state names (doesn't actually matter right now, but it
might confuse someone in the future)
dana
diff --git a/Completion/Unix/Command/_column b/Completion/Unix/Command/_column
index a81684dba..9c95ac692 100644
--- a/Completion/Unix/Command/_column
+++ b/Completion/Unix/Command/_column
@@ -1,16 +1,27 @@
#compdef column
-local ret=1
-local -a context state line expl args columns MATCH
+local variant ret=1
+local -a context state line expl args columns MATCH aopts=( -A '-*' )
local -i MBEGIN MEND
local -A opt_args
-case $OSTYPE in
- linux-gnu)
+# Debian and its derivatives (as of 2019) ship with a slightly customised
+# version of the BSD column instead of the util-linux one. It can be identified
+# by the presence of the custom option -n in the synopsis
+_pick_variant -r variant \
+ util-linux='(#i)util-linux' \
+ debian='\[-[A-Za-z]#n[A-Za-z]#\]' \
+ $OSTYPE \
+--version
+
+case $variant in
+ util-linux)
+ aopts=()
args=(
'(info json -c --output-width)'{-c+,--output-width=}'[format output to fit display of specified width]:width'
'(info)'{-L,--table-empty-lines}"[don't ignore empty lines]"
+ fill
+ # Yes, util-linux `column -x` does the exact opposite of BSD `column -x`
'(info table text json -x --fillrows)'{-x,--fillrows}'[fill rows before filling columns]'
+ table
'(info fill -t --table)'{-t,--table}'[create a table]'
@@ -20,14 +31,14 @@ case $OSTYPE in
'(info fill -H --table-hide)'{-H+,--table-hide=}"[don't print specified columns]: :->columns"
+ text
'(info fill json -d --table-noheadings)'{-d,--table-noheadings}"[don't print header]"
- '(info fill json -E --table-noextreme)'{-E,--table-noextreme}"[specify columns where length can be ignored]: :->columns"
+ '(info fill json -E --table-noextreme)'{-E+,--table-noextreme}"[specify columns where length can be ignored]: :->columns"
'(info fill json -e --table-header-repeat)'{-e,--table-header-repeat}'[repeat header for each page]'
'(info fill json -R --table-right)'{-R+,--table-right=}'[right align text in these columns]: :->columns'
'(info fill json -T --table-truncate)'{-T+,--table-truncate=}'[truncate text in the columns when necessary]: :->columns'
'(info fill json -W --table-wrap)'{-W+,--table-wrap=}'[wrap text in the columns when necessary]: :->columns'
- '(info fill json -r --tree)'{-r+,--tree=}'[specify column to format tree-like]: :->column'
- '(info fill json -i --tree-id)'{-i+,--tree-id=}'[specify column containing ID for child-parent relations]: :->column'
- '(info fill json -p --tree-parent)'{-p+,--tree-parent=}'[specify column containing reference to parent]: :->column'
+ '(info fill json -r --tree)'{-r+,--tree=}'[specify column to format tree-like]: :->columns'
+ '(info fill json -i --tree-id)'{-i+,--tree-id=}'[specify column containing ID for child-parent relations]: :->columns'
+ '(info fill json -p --tree-parent)'{-p+,--tree-parent=}'[specify column containing reference to parent]: :->columns'
+ json
'(info fill text -n --table-name -c --output-width)'{-n+,--table-name=}'[specify table name for JSON output]:name'
'(info fill text -J --json -c --output-width)'{-J,--json}'[use JSON output format for table]'
@@ -36,17 +47,24 @@ case $OSTYPE in
'(- *)'{-V,--version}'[display version information]'
)
;;
- *)
+ debian)
+ aopts=()
args=(
+ "(-x)-n[don't merge multiple adjacent delimiters]"
+ "-e[don't ignore empty lines]"
+ )
+ ;& # FALL THROUGH
+ *)
+ args+=(
'(-t -s)-c+[format output to fit display of specified width]:width'
'(-c -x)-t[create a table]'
'(-c -x)-s+[specify column delimiters in input data]:delimiters'
- '(-t -s)-x[fill rows before filling columns]'
+ '(-n -t -s)-x[fill columns before filling rows]'
)
;;
esac
-_arguments -s -S '*:file:_files' $args && ret=0
+_arguments -s -S $aopts '*:file:_files' $args && ret=0
if [[ -n $state ]]; then
columns=( ${(s.,.)${(Q)${opt_args[table--N]:-$opt_args[table---table-columns]}//(#m)\\([\\:])/${MATCH[2]}}} )
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Completion: Improve _column
2019-02-21 22:19 [PATCH] Completion: Improve _column dana
@ 2019-02-21 22:55 ` dana
0 siblings, 0 replies; 2+ messages in thread
From: dana @ 2019-02-21 22:55 UTC (permalink / raw)
To: zsh workers
On 21 Feb 2019, at 16:19, dana <dana@dana.is> wrote:
>Some improvements to column completion:
Sorry, after sending this i noticed two things:
* The function was missing the options -H and -o from util-linux column; i've
added those
* It wasn't right to say that util-linux `column -x` has the opposite
behaviour from BSD `column -x`. It's *documented* that way, but i think the
actual behaviour is the same. The two projects might be using the word
'fill' differently. I guess i'll leave my description change, so that it
matches the documentation, but i've fixed my bogus comment
dana
diff --git a/Completion/Unix/Command/_column b/Completion/Unix/Command/_column
index a81684dba..55f8f66a0 100644
--- a/Completion/Unix/Command/_column
+++ b/Completion/Unix/Command/_column
@@ -1,33 +1,48 @@
#compdef column
-local ret=1
-local -a context state line expl args columns MATCH
+local variant ret=1
+local -a context state line expl args columns MATCH aopts=( -A '-*' )
local -i MBEGIN MEND
local -A opt_args
-case $OSTYPE in
- linux-gnu)
+# Debian and its derivatives (as of 2019) ship with a slightly customised
+# version of the BSD column instead of the util-linux one. It can be identified
+# by the presence of the custom option -n in the synopsis
+_pick_variant -r variant \
+ util-linux='(#i)util-linux' \
+ debian='\[-[A-Za-z]#n[A-Za-z]#\]' \
+ $OSTYPE \
+--version
+
+case $variant in
+ util-linux)
+ aopts=()
args=(
'(info json -c --output-width)'{-c+,--output-width=}'[format output to fit display of specified width]:width'
'(info)'{-L,--table-empty-lines}"[don't ignore empty lines]"
+ fill
+ # The wording here implies that this has the opposite behaviour from BSD
+ # `column -x`, but it doesn't seem to. We'll keep the descriptions
+ # matching the projects' respective documentation, in any case
'(info table text json -x --fillrows)'{-x,--fillrows}'[fill rows before filling columns]'
+ table
'(info fill -t --table)'{-t,--table}'[create a table]'
+ '(info fill -o --output-separator)'{-o+,--output-separator=}'[specify column separator for table output]:separator [two spaces]'
'(info fill -s --separator)'{-s+,--separator=}'[specify column delimiters in input data]:delimiters'
'(info fill -O --table-order)'{-O+,--table-order=}'[specify order of output columns]: :->columns'
'(info fill -N --table-columns)'{-N+,--table-columns=}'[specify column names]:names'
'(info fill -H --table-hide)'{-H+,--table-hide=}"[don't print specified columns]: :->columns"
+ text
'(info fill json -d --table-noheadings)'{-d,--table-noheadings}"[don't print header]"
- '(info fill json -E --table-noextreme)'{-E,--table-noextreme}"[specify columns where length can be ignored]: :->columns"
+ '(info fill json -E --table-noextreme)'{-E+,--table-noextreme}"[specify columns where length can be ignored]: :->columns"
'(info fill json -e --table-header-repeat)'{-e,--table-header-repeat}'[repeat header for each page]'
+ '(info fill json -H --table-hide)'{-H+,--table-hide=}"[don't print specified columns]: :->columns"
'(info fill json -R --table-right)'{-R+,--table-right=}'[right align text in these columns]: :->columns'
'(info fill json -T --table-truncate)'{-T+,--table-truncate=}'[truncate text in the columns when necessary]: :->columns'
'(info fill json -W --table-wrap)'{-W+,--table-wrap=}'[wrap text in the columns when necessary]: :->columns'
- '(info fill json -r --tree)'{-r+,--tree=}'[specify column to format tree-like]: :->column'
- '(info fill json -i --tree-id)'{-i+,--tree-id=}'[specify column containing ID for child-parent relations]: :->column'
- '(info fill json -p --tree-parent)'{-p+,--tree-parent=}'[specify column containing reference to parent]: :->column'
+ '(info fill json -r --tree)'{-r+,--tree=}'[specify column to format tree-like]: :->columns'
+ '(info fill json -i --tree-id)'{-i+,--tree-id=}'[specify column containing ID for child-parent relations]: :->columns'
+ '(info fill json -p --tree-parent)'{-p+,--tree-parent=}'[specify column containing reference to parent]: :->columns'
+ json
'(info fill text -n --table-name -c --output-width)'{-n+,--table-name=}'[specify table name for JSON output]:name'
'(info fill text -J --json -c --output-width)'{-J,--json}'[use JSON output format for table]'
@@ -36,17 +51,24 @@ case $OSTYPE in
'(- *)'{-V,--version}'[display version information]'
)
;;
- *)
+ debian)
+ aopts=()
args=(
+ "(-x)-n[don't merge multiple adjacent delimiters]"
+ "-e[don't ignore empty lines]"
+ )
+ ;& # FALL THROUGH
+ *)
+ args+=(
'(-t -s)-c+[format output to fit display of specified width]:width'
'(-c -x)-t[create a table]'
'(-c -x)-s+[specify column delimiters in input data]:delimiters'
- '(-t -s)-x[fill rows before filling columns]'
+ '(-n -t -s)-x[fill columns before filling rows]'
)
;;
esac
-_arguments -s -S '*:file:_files' $args && ret=0
+_arguments -s -S $aopts '*:file:_files' $args && ret=0
if [[ -n $state ]]; then
columns=( ${(s.,.)${(Q)${opt_args[table--N]:-$opt_args[table---table-columns]}//(#m)\\([\\:])/${MATCH[2]}}} )
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-21 22:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 22:19 [PATCH] Completion: Improve _column dana
2019-02-21 22:55 ` 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).