From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12413 invoked from network); 31 Jan 2022 14:33:39 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Jan 2022 14:33:39 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1643639619; b=AgTu5KeLZWX/DFCENbaAc657suvBhYQOySrw0xF6y2VtN2t+6OiNuq5AY6FHJqJMTcKiz/OAMP XwztRIJcswAq5o4pTHO+0M1Zbf3bekZcNoYlciuaZuEoAzXZgoSqwmPoEh8fVpELoeOD0m5Qef 5fP7bKd3vM7h4nlqcQWYeoEeLyQ9RPJOBG6mnhyZSIkoKHaJGCKGilq8ssPY2H2jiERiratW3b IsA2U8vmk+pIJAJK8qUKvV8lL6+8uBzEFRiLaM0g3qQ9rGYBAr/tjp7Wq/V/wWytwj2Y7Wl+y2 N3B8yJEEpHXZlAtSDu09HVagN8XiCR5NCTy9S4nJBhqsNg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (snd01007-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.23; dmarc=none header.from=kba.biglobe.ne.jp; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1643639619; bh=y9SlP41HU/+zSIwxeUc7ClvIauAam/hHfdOWfmFS1Pc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:Date:Message-ID:Subject:MIME-Version: Content-Transfer-Encoding:Content-Type:From:DKIM-Signature; b=Wl/871aC5eoZ2ZIBBf+UInWgPmdYMIXLkYF+PKePUDWZ0GAQmdG5HiCXBxWEXtwsHINFTMGOqY g0kIZUfy1Izknu9eoLFmvKtAmctqRK2Zs1dBuPTAvEf3jE7BmkeTFzo8f7JncedRW55JCPW2r7 6RXMzjt6GL30x7XJ4iJH/9d9TYRRqO3oQOMtRbDtPCenWfZOZL6BaImz31dYAY0Ocm7qM3VFbJ eF7j8IXBt2d8E9+uuFyce/j6InG4lQnvhu1rWhNUPxRGOwBOrH7V5J41xoeDnk4URSpCm16JX4 O2TBQaKa9IFeNglEIPbBWXAgObSNmv/0fRnqlm+jWpD1dg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:To:Date:Message-Id:Subject: Mime-Version:Content-Transfer-Encoding:Content-Type:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=vgf35wiJknt/hYLvszCb4ZbhRl+A4f2mNO0i4AZCEDI=; b=sfwZUfPgQ3u8d1mSIL1chfoNox aCHvzZr9liY4wY0RDseD5I8qy+7t8qGndAAE3q5NuySc6q8J3LWnwDepQyxihwbNspYEvAfme4fqL 9lq8ELylMURwBsAZuIWAcw51aHvXdlCKiGMFromVvih2G8WaFmt744iHq/kc9qTfG/gn7WYQifwI5 0FY0fHbxNsfwdptabri/fL7o4YVFIJFDqWEQcfBCjX+oDEOMoyM/NupSTT5316zv8qSIRkZxRbUEp izy64MFWF54mkNe7Ksh61yCbN+QVLnMiMwoR4odPCMczVrpuaCCPTzetxS6rmWQrixQ5pkJFG2UCk k7nXEHnw==; Received: from authenticated user by zero.zsh.org with local id 1nEXkP-000Msd-F2; Mon, 31 Jan 2022 14:33:37 +0000 Authentication-Results: zsh.org; iprev=pass (snd01007-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.23; dmarc=none header.from=kba.biglobe.ne.jp; arc=none Received: from snd01007-bg.im.kddi.ne.jp ([27.86.113.23]:52768 helo=dfmta1016.biglobe.ne.jp) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1nEXjo-000MXO-V5; Mon, 31 Jan 2022 14:33:02 +0000 Received: from mail.biglobe.ne.jp by omta1016.biglobe.ne.jp with ESMTP id <20220131143254753.REOR.85532.mail.biglobe.ne.jp@biglobe.ne.jp> for ; Mon, 31 Jan 2022 23:32:54 +0900 From: "Jun. T" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: [PATCH] new completions for csplit, pr, ptx, truncate Message-Id: <4439FFCD-2139-4DFA-B7A1-C7F06BD4230B@kba.biglobe.ne.jp> Date: Mon, 31 Jan 2022 23:32:54 +0900 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Biglobe-Sender: takimoto-j@kba.biglobe.ne.jp X-Seq: 49730 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: These commands are in GNU coreutils, but there are non-GNU variants = also. pr accepts -2 -3 -4 ... for specifying number of columns. The _pr below offers only -2 and -3, but I think it's enough. pr also accepts +page_number to start printing from the specified page. It is taken care of before calling _arguments. csplit, pr and ptx accept a single '-' as a file name (to read from = stdin). For non-GNU variant (i.e., for BSD variant) we need to use _argument -A '-?*' (or -A '[-+]?*' for pr) to stop completing options for 'csplit - -'. diff --git a/Completion/Unix/Command/_csplit = b/Completion/Unix/Command/_csplit new file mode 100644 index 000000000..5f72232bb --- /dev/null +++ b/Completion/Unix/Command/_csplit @@ -0,0 +1,51 @@ +#compdef csplit + +local curcontext=3D$curcontext cnt_info ret=3D1 +local -a state state_descr line specs optA +typeset -A opt_args + +# common specs +specs=3D( + '(hv -f --prefix)'{-f+,--prefix=3D}'[specify prefix for output file = names]:prefix [xx]: ' + '(hv -n --digits -b --suffix-format)'{-n+,--digits=3D}'[specify = number of digits in output file names]:number [2]: ' + '(hv -k --keep-files)'{-k,--keep-files}'[do not remove output files = on errors]' + '(hv -s --quiet --silent)'{-s,--quiet,--silent}'[do not print counts = of output file sizes]' + '(hv)1: :_files' + '(hv)*: :->patterns' +) + +if _pick_variant gnu=3DGNU unix --version; then + # GNU coreutils 8.32 + specs+=3D( + '(hv -b --suffix-format -n = --digits)'{-b+,--suffix-format=3D}'[specify format for numbers in output = file names]:format [%%02d]: ' + '(hv)--suppress-matched[suppress the lines matching the pattern]' + '(hv -z --elide-empty)'{-z,--elide-empty-files}'[remove empty = output files]' + + hv + '(: * -)--help[display help and exit]' + '(: * -)--version[output version information and exit]' + ) + cnt_info=3D"(integer or '*')" +else + # POSIX ({Free,Open}BSD, DragonFly, macOS) + specs=3D( ${specs:#(|*\))--*} ) # remove long options + optA=3D( -A '-?*' ) # a single '-' is a valid file name (stdin) +fi + +_arguments -C -s -S $optA : $specs && ret=3D0 + +case $state in + patterns) + if compset -P '(/?*/|%?*%)'; then + _message '[+|-]offset' && ret=3D0 + elif compset -P '[/%]'; then + _message 'regex' && ret=3D0 + elif compset -P '(|\\){'; then + _message "count $cnt_info" && ret=3D0 + elif compset -P '[0-9]*'; then + _message 'line number' && ret=3D0 + elif [[ ${words[CURRENT]} !=3D -* ]] then + _message "line_number, '/regex/[offset]', '%%regex%%[offset]', or = '{count}'" && ret=3D0 + fi +esac + +return ret diff --git a/Completion/Unix/Command/_pr b/Completion/Unix/Command/_pr new file mode 100644 index 000000000..2aeeb13b3 --- /dev/null +++ b/Completion/Unix/Command/_pr @@ -0,0 +1,103 @@ +#compdef pr + +local curcontext=3D$curcontext variant msg ret=3D1 +local -a state state_descr line specs optA +typeset -A opt_args + +# take care of '+FIRST_PAGE[:LAST_PAGE]' (GNU) or '+FIRST_PAGE' (POSIX) +if _pick_variant -r variant gnu=3DGNU $OSTYPE --version; then + msg=3D'FIRST_PAGE[:LAST_PAGE]' +else + msg=3D'first page' +fi + +if [[ $words[CURRENT] =3D +* ]]; then + _message "$msg" && return +fi + +if (( ! ${words[(I)+[0-9]*]} )); then + # if +number is not on the command line + specs=3D( '(hv)--pages=3D[specify first and last page numbers]: : = _message $msg' ) +fi + +# common specs +specs+=3D( + '(hv -a --across)'{-a,--across}'[with multi-column output, print = columns across rather than down]' + '(hv -d --double-space)'{-d,--double-space}'[double space the = output]' + '(hv -e --expand-tabs)'{-e-,--expand-tabs=3D-}'[expand tab (or = specified char) with specified number of spaces]::number of spaces = [8]:->char_number' + '(hv -h --header -t --omit-header)'{-h+,--header=3D}'[specify text = used in header]:header: ' + '(hv -i --output-tabs)'{-i-,--output-tabs=3D-}'[replace specified = number of spaces with tab (or specified char)]::number of spaces = [8]:->char_number' + '(hv -l --length)'{-l+,--length=3D}'[specify the page length]:number = of lines [66]: ' + '(hv -m --merge)'{-m,--merge}'[print all files in parallel, one in = each column]' + '(hv -n --number-lines)'{-n-,--number-lines=3D-}'[number lines with = specified separator and width]::number of digits [5]:->char_number' + '(hv -o --indent)'{-o+,--indent=3D}'[specify left margin]:margin [0]: = ' + '(hv -r -no-file-warnings)'{-r,--no-file-warnings}'[omit warning when = a file cannot be opened]' + '(hv -s --separator)'{-s-,--separator=3D-}'[specify column separator = character]:character [tab]: ' + '(hv -t --omit-header -h --header)'{-t,--omit-header}'[omit page = headers and trailers]' + '(hv -w --width)'{-w+,--width=3D}'[specify page width for = multi-column output]:number of characters [72]: ' + '(hv)*: :_files' +) +# XXX: pr accepts -2 -3 -4 ... for specifying the number of columns. +# Here we offer only -2 and -3, and do so only if there is no +# -2 -3 -4 ... or --columns on the command line. +if (( ! ${words[(I)-([0-9]##*|-columns*)]} )); then + specs+=3D( {-2,-3}'[specify number of columns]' ) +fi + +if [[ $variant =3D gnu ]]; then + # GNU coreutils 8.32 + specs+=3D( + '(hv -c --show-control-chars)'{-c,--show-control-chars}'[use hat = (^G) and octal backslash notation]' + '(hv -D --date-format)'{-D+,--date-format=3D}'[specify format for = the header date]: :_date_formats' + '(hv -f -F --form-feed)'{-f,-F,--form-feed}'[use form feeds instead = of newlines to separate pages]' + '(hv -J --join-lines)'{-J,--join-lines}'[merge full lines in = multi-column output]' + '(hv -N --first-line-number)'{-N+,--first-line-number=3D}'[specify = the line number of the 1st line]:number: ' + '(hv -S --sep-string)'{-S-,--sep-string=3D-}'[specify column = separator string]:string: ' + '(hv -T --omit-pagination)'{-T,--omit-pagination}'[omit page = headers and trailers, eliminate any pagination]' + '(hv -v --show-nonprinting)'{-v,--show-nonprinting}'[use octal = backslash notation]' + '(hv -W --page-width)'{-W+,--page-width=3D}'[specify page width = always]:number of characters [72]: ' + ) + if (( ! ${words[(I)-[0-9]##*]} )); then + # if -2 -3 -4 ... are not on the command line + specs+=3D( + '(hv)--columns=3D[specify number of columns]:number of columns: ' + + hv + '(- *)--help[display help and exit]' + '(- *)--version[output version information and exit]' + ) + fi +else + specs=3D( ${specs:#(|*\))--*} ) # remove long options + case $variant in + freebsd*|dragonfly*|darwin*|netbsd*) + specs+=3D( + '(-f)-F[use form feeds instead of newlines to separate pages]' + '(-F)-f[same as -F but pause before the 1st page if stdout is = terminal]' + '-p[pause before each page if stdout is terminal]' + ) + ;| + freebsd*|dragonfly*|darwin*) + specs+=3D( '-L+[specify locale to use]: :_locales' ) + ;; + openbsd*) + specs+=3D( '(-f -F)'{-f,-F}'[use form feeds instead of newlines = to separate pages]' ) + ;; + esac + optA=3D( -A '[-+]?*' ) # a single '-' is a valid file name (stdin) +fi + +_arguments -C -s -S $optA : $specs && ret=3D0 + +case $state in + char_number) + # argument for option -e (and -i, -n) can be -e. -e10 or -e.10 + # where . is any non-digit character + if compset -p 1; then + _message "$state_descr" && ret=3D0 + else + _message "a character [tab] (optional), and $state_descr" && = ret=3D0 + fi + ;; +esac + +return ret diff --git a/Completion/Unix/Command/_ptx b/Completion/Unix/Command/_ptx new file mode 100644 index 000000000..12f1d2c9a --- /dev/null +++ b/Completion/Unix/Command/_ptx @@ -0,0 +1,54 @@ +#compdef ptx + +local -a specs optA + +# common specs +specs=3D( + '(hv -b --break-file)'{-b+,--break-file=3D}'[use characters in = specified file as word separators]:break file:_files' + '(hv -f --ignore-case)'{-f,--ignore-case}'[fold lower case to upper = case for sorting]' + '(hv -g --gap-size)'{-g+,--gap-size=3D}'[specify gap size between = output fields]:number of chars [3]: ' + '(hv -i --ignore-file)'{-i+,--ignore-file=3D}'[ignore keywords listed = in specified file]:ignore file:_files' + '(hv -o --only-file)'{-o+,--only-file=3D}'[use only the keywords = listed in specified file]:only file:_files' + '(hv -r --references)'{-r,--references}'[first field of each line is = a reference]' + '(hv -w --width)'{-w+,--width=3D}'[specify page width, reference = excluded]:number of characters [72]: ' +) + +if _pick_variant gnu=3DGNU unix --version; then + # GNU coreutils 8.32 + specs+=3D( + '(hv -A --auto-reference)'{-A,--auto-reference}'[output = automatically generated references]' + '(hv -G --traditional)'{-G,--traditional}"[behave more like System = V 'ptx']" + '(hv -F --flag-truncation)'{-F+,--flag-truncation=3D}'[specify = string for flagging line truncations]:string [/]: ' + '(hv -M --macro-name)'{-M+,--macro-name=3D}"[specify macro name to = use instead of 'xx']:macro name: " + '(hv)-O[generate output as roff directives]' + '(hv -R --right-side-refs)'{-R,--right-side-refs}'[put references = at right, not counted in -w]' + '(hv -S --sentence-regexp)'{-S+,--sentence-regexp=3D}'[specify = regexp for end of lines/sentences]:regexp: ' + '(hv)-T[generate output as TeX directives]' + '(hv -W --word-regexp -b = --break-file)'{-W+,--word-regexp=3D}'[specify regexp to match each = keyword]:regexp: ' + '(hv)--format=3D[specify the output format]:format:(roff tex)' + !{-t,--typeset-mode}'[not implemented]' + + hv + '(: * -)--help[display help and exit]' + '(: * -)--version[output version information and exit]' + ) + if (( $words[(I)(-G|--traditional)] )); then + specs+=3D( + arg '1:input file:_files' '2:output file:_files' ) + else + specs+=3D( + arg '(-G --traditional)*:input file:_files' ) + fi +else + # The only non-GNU implementation I can find is the one in + # heirloom-doctools. FreeBSD has a package for this. + specs=3D( ${specs:#(|*\))--*} ) # remove long options + # remove '+' from -b+ -g+ -i+ -o+ -w+ + local MATCH MBEGIN MEND + specs=3D( ${specs/(#m)-[bgiow]+/$MATCH[1,-2]} ) + specs+=3D( + '-t[prepare output for typesetter]' + '1:input file:_files' + '2:output file:_files' + ) + optA=3D( -A '-?*' ) # a single '-' is a valid file name (stdin) +fi + +_arguments -s -S $optA : $specs diff --git a/Completion/Unix/Command/_truncate = b/Completion/Unix/Command/_truncate new file mode 100644 index 000000000..117be9702 --- /dev/null +++ b/Completion/Unix/Command/_truncate @@ -0,0 +1,69 @@ +#compdef truncate + +local curcontext=3D$curcontext variant rs ret=3D1 +local -a state state_descr line specs optA +typeset -A opt_args + +_pick_variant -r variant gnu=3DGNU $OSTYPE --version +[[ $variant !=3D gnu ]] && rs=3D'-r -s' # -r/-s mutually exclusive + +# common specs +specs=3D( + '(hv -c --no-create)'{-c,--no-create}'[do not create any files]' + "(hv $rs -r --reference)"{-r+,--reference=3D}'[base size on the = specified file]:reference file:_files' + "(hv $rs -s --size)"{-s+,--size=3D}'[set or adjust the file size by = specified bytes]:size:->size' + '(hv)*: :_files' +) + +case $variant in + gnu) # GNU coreutils 8.32 + specs+=3D( + '(hv -o --io-blocks)'{-o,--io-blocks}'[treat the specified size = as number of IO blocks instead of bytes]' + + 'hv' + '(- *)--help[display help and exit]' + '(- *)--version[output version information and exit]' + ) + ;; + *) # FreeBSD/DragonFly + specs=3D( ${specs:#(|*\))--*} ) # remove long options + optA=3D( -A '-*' ) + ;; +esac + +_arguments -C -s -S : $specs && ret=3D0 + +case $state in + size) + local unit=3Dbytes + (( ${#opt_args[(I)(-o|--io-blocks)]} )) && unit=3Dblocks + local -a suffix=3D( K:1024 M G T ) + local -a prefix=3D( '+:extend by' '-:reduce by' ) + local prefix_char=3D'[-+]' + case $variant in + gnu|freebsd*) + prefix+=3D( '/:round down to multiple of' '%:round up to = multiple of' ) + ;| + gnu) + suffix=3D( K:1024 KB:1000 {M,G,T,P,E,Z,Y}{,B} ) + prefix+=3D( '<:at most' '>:at least' ) + prefix_char=3D'([-+/%]|\\[<>])' + ;; + freebsd*) + prefix_char=3D'[-+/%]' + ;; + esac + local -a numbers=3D( _numbers -u $unit size $suffix ) + + if compset -P "$prefix_char"; then + $numbers && ret=3D0 + elif (( ${#opt_args[(I)(-r|--reference)]} )); then + # prefix is required if the reference file is given + _describe -t 'prefixes' 'prefix' prefix && ret=3D0 + else + _alternative "prefixes:prefix:((${(@q)prefix}))" \ + "sizes: :$numbers" && ret=3D0 + fi + ;; +esac + +return ret