zsh-workers
 help / color / mirror / code / Atom feed
* New completions for awk cut join sort - attached
@ 2008-05-13 15:55 Omari Norman
  2008-05-13 16:07 ` Stephane Chazelas
  2008-05-13 16:11 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Omari Norman @ 2008-05-13 15:55 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

Hi all,

I just wrote some completions for awk, cut, join, and sort. I was
surprised that zsh didn't include these already. The awk one isn't
perfect but it's a lot better than nothing. The awk one only completes
basic POSIX awk options (i.e. not gawk or mawk options) while cut, join,
and sort completions are for the GNU versions.

I find these helpful, particularly because these commands all use
different flags ("-F", "-t", and "-d") to do the exact same thing, even
though these commands will often appear in the same pipeline! awk often
trips me up in other ways, and this completion really helps with that
too.

I have attached the completions. Hopefully they can be included in the
next zsh release, though the awk completion could use some expert
attention (see comments in _awk). Thanks. --Omari


-- 
Though the bag does not inflate, oxygen is flowing.

[-- Attachment #2: _awk --]
[-- Type: text/plain, Size: 972 bytes --]

#compdef awk

# completions for awk
# This only aims to complete POSIX awk options, as described in
# awk(P). Most awk implementations, such as gawk and mawk, will have
# additional options that this does not complete. Also, currently
# this completion does not allow everything that POSIX allows. For
# example, awk(P) states that the user may specify assignments
# without using the -v option; this does not support that.
#
# In addition, the "program text" completion is not perfect. For
# instance, type "awk -" and then hit tab. You will be presented
# both with the dashed options and with the "program text" option.
# Fixing this is beyond my current _arguments expertise--help
# appreciated.

_arguments -S -s '-F[define input field separator to be an extended regular expression]:extended regular expression:' \
    '*-v[assign values to variables]:assignment:' \
    '(1)-f[program file]:program file:_files' \
    '1:program text:' \
    '*:input files:_files'

[-- Attachment #3: _cut --]
[-- Type: text/plain, Size: 1044 bytes --]

#compdef cut

# zsh completions for GNU cut version 5.97

local arguments

arguments=(
    '(-f --fields -b --bytes -c --characters)'{-b+,--bytes=}'[select only these bytes]:bytes:'
    '(-f --fields -b --bytes -c --characters)'{-c+,--characters=}'[select only these characters]:characters:'
    '(-f --fields -b --bytes -c --characters)'{-f+,--fields=}'[select only these fields; also print any line that contains no delimiter character, unless the -s option is specified]:fields:'
    '(-d --delimiter)'{-d+,--delimiter=}'[use delimiter instead of tab for field delimiter]:delimiter:'
    -n'[(ignored)]'
    --complement'[complement the set of selected bytes, characters or fields]'
    '(-s --only-delimited)'{-s+,--only-delimited=}'[do not print lines not containing delimiters]'
    '--output-delimiter=[use string as the output delimiter; the default is to use the input delimiter]:string:'
    --help'[display help and exit]'
    --version'[display version information and exit]'
    '*:filename:_files'
    )

_arguments -s $arguments

[-- Attachment #4: _join --]
[-- Type: text/plain, Size: 933 bytes --]

#compdef join

# completions for GNU join version 5.97

local arguments

arguments=(
    '-a+[print unpairable lines coming from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2]:file number:(1 2)'
    '-e+[replace missing input fields with EMPTY]:replacement string:'
    '(-i --ignore-case)'{-i,--ignore-case}'[ignore differences in case when comparing fields]'
    "-j+[equivalent to '-1 FIELD -2 FIELD']:field number:"
    '-o+[obey FORMAT while constructing output line]:format string:'
    '-t+[use CHAR as input and output field separator]:separator:'
    '-v+[like -a FILENUM, but suppress joined output lines]:file number:(1 2)'
    '-1+[join on this FIELD of file 1]:field number:'
    '-2+[join on this FIELD of file 2]:field number:'
    --help'[display help and exit]'
    --version'[output version information and exit]'
    '1:file 1:_files'
    '2:file 2:_files'
    )

_arguments -s $arguments

[-- Attachment #5: _sort --]
[-- Type: text/plain, Size: 2016 bytes --]

#compdef sort

# zsh completions for GNU sort version 5.97
# limitation: --key does not work exactly right
local arguments

arguments=(
    '(-b --ignore-leading-blanks)'{-b,--ignore-leading-blanks}'[ignore leading blanks]'
    '(-d --dictionary-order)'{-d,--dictionary-order}'[consider only blanks and alphanumeric characters]'
    '(-f --ignore-case)'{-f,--ignore-case}'[fold lower case to upper case characters]'
    '(-g --general-numeric-sort)'{-g,--general-numeric-sort}'[compare according to general numeric value]'
    '(-i --ignore-nonprinting)'{-i,--ignore-nonprinting}'[consider only printable characters]'
    '(-M --month-sort)'{-M,--month-sort}"[compare (unknown) < 'JAN' < ... < 'DEC']"
    '(-n --numeric-sort)'{-n,--numeric-sort}'[compare according to string numerical value]'
    '(-r --reverse)'{-r,--reverse}'[reverse the result of comparisons]'
    '(-c --check)'{-c,--check}'[check whether input is sorted; do not sort]'
    '(-k --key)'{-k+,--key=}'[start a key at POS1, end it as POS2 (origin 1)]:key:'
    '(-m --merge)'{-m,--merge}'[merge already sorted files; do not sort]'
    '(-o --output)'{-o+,--output=}'[write result to FILE instead of standard output]:filename:_files'
    '(-s --stable)'{-s+,--stable=}'[stabilize sort by disabling last-resort comparison]'
    '(-S --buffer-size)'{-S+,--buffer-size=}'[use SIZE for main memory buffer]:size:'
    '(-t --field-separator)'{-t+,--field-separator=}'[use SEP instead of non-blank to blank transition]:separator:'
    '(-T --temporary-directory)'{-T+,--temporary-directory=}'[use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories]:directory'
    '(-u --unique)'{-u,--unique}'[with -c, check for strict ordering; without -c, output only the first of an equal run]'
    '(-z --zero-terminated)'{-z,--zero-terminated}'[end lines with 0 byte, not newline]'
    --help'[display help and exit]'
    --version'[output version information and exit]'
    '*:filename:_files'
    )

_arguments -s $arguments

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: New completions for awk cut join sort - attached
  2008-05-13 15:55 New completions for awk cut join sort - attached Omari Norman
@ 2008-05-13 16:07 ` Stephane Chazelas
  2008-05-13 16:11 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Stephane Chazelas @ 2008-05-13 16:07 UTC (permalink / raw)
  To: Omari Norman; +Cc: zsh-workers

On Tue, May 13, 2008 at 11:55:32AM -0400, Omari Norman wrote:
[...]
> # completions for awk
> # This only aims to complete POSIX awk options, as described in
> # awk(P). Most awk implementations, such as gawk and mawk, will have
> # additional options that this does not complete. Also, currently
> # this completion does not allow everything that POSIX allows. For
> # example, awk(P) states that the user may specify assignments
> # without using the -v option; this does not support that.
> #
> # In addition, the "program text" completion is not perfect. For
> # instance, type "awk -" and then hit tab. You will be presented
> # both with the dashed options and with the "program text" option.
> # Fixing this is beyond my current _arguments expertise--help
> # appreciated.
> 
> _arguments -S -s '-F[define input field separator to be an extended regular expression]:extended regular expression:' \
>     '*-v[assign values to variables]:assignment:' \
>     '(1)-f[program file]:program file:_files' \
>     '1:program text:' \
>     '*:input files:_files'
[...]

Note that the remaining arguments of awk can also be awk
variable assignments or the special string "-" to specify stdin.

regards,
Stéphane


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: New completions for awk cut join sort - attached
  2008-05-13 15:55 New completions for awk cut join sort - attached Omari Norman
  2008-05-13 16:07 ` Stephane Chazelas
@ 2008-05-13 16:11 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2008-05-13 16:11 UTC (permalink / raw)
  To: Omari Norman; +Cc: zsh-workers

Omari Norman wrote:
> I just wrote some completions for awk, cut, join, and sort. I was
> surprised that zsh didn't include these already. The awk one isn't
> perfect but it's a lot better than nothing. The awk one only completes
> basic POSIX awk options (i.e. not gawk or mawk options) while cut, join,
> and sort completions are for the GNU versions.

Thanks, we've now got a completion for cut but I've added the others.
Patches to these from anyone are welcome.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-13 16:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-13 15:55 New completions for awk cut join sort - attached Omari Norman
2008-05-13 16:07 ` Stephane Chazelas
2008-05-13 16:11 ` Peter Stephenson

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).