Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

New completions for awk cut join sort - attached



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.
#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'
#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
#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
#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


Messages sorted by: Reverse Date, Date, Thread, Author