From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18603 invoked by alias); 27 Oct 2015 15:52:30 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36983 Received: (qmail 10522 invoked from network); 27 Oct 2015 15:52:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Biglobe-Sender: From: "Jun T." Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: [PATCH] new completions for head and tail commands Message-Id: Date: Tue, 27 Oct 2015 22:44:47 +0900 To: zsh-workers@zsh.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) X-Mailer: Apple Mail (2.1878.6) X-Biglobe-Spnum: 55968 --- Here are new completion functions for 'head' and 'tail' commands. Completion/Unix/Command/_head | 45 ++++++++++++++++++++++++++++++ Completion/Unix/Command/_tail | 65 = +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Completion/Unix/Command/_head create mode 100644 Completion/Unix/Command/_tail diff --git a/Completion/Unix/Command/_head = b/Completion/Unix/Command/_head new file mode 100644 index 0000000..1f0fab9 --- /dev/null +++ b/Completion/Unix/Command/_head @@ -0,0 +1,45 @@ +#compdef head + +local curcontext=3D$curcontext state state_descr line expl opts args = ret=3D1 +typeset -A opt_args + +if _pick_variant gnu=3DGNU unix --version; then + args=3D( + '(-n --lines -c --bytes)'{-c+,--bytes=3D}'[print the first (or with = -, all but the last) specified bytes]:number of bytes:->number' + '(-n --lines -c --bytes)'{-n+,--lines=3D}'[print the first (or with = -, all but the last) specified lines]:number of lines:->number' + '(-q --quiet --silent -v --verbose)'{-q,--quiet,--silent}'[never = print headers giving file names]' + '(-q --quiet --silent -v --verbose)'{-v,--verbose}'[always print = headers giving file names]' + '(- *)--help[display help and exit]' + '(- *)--version[output version information and exit]' + ) +else + opts=3D'-A "-*"' + args=3D( '(-c)-n+[display the first specified lines]:number of lines' = ) + case $OSTYPE in + (freebsd*|darwin*|dragonfly*|netbsd*) + args+=3D( '(-n)-c+[display the first specified bytes]:number of = bytes' ) + ;; + esac +fi + +_arguments -C -s -S $opts : $args '*:file:_files' && return 0 + +case $state in + (number) + local mlt sign digit + mlt=3D'multiplier:multiplier:((b\:512 K\:1024 KB\:1000 M\:1024\^2' + mlt+=3D' MB\:1000\^2 G\:1024\^3 GB\:1000\^3 T\:1024\^4 = TB\:1000\^4))' + sign=3D'sign:sign:((-\:"print all but the last specified = bytes/lines"' + sign+=3D' +\:"print the first specified bytes/lines (default)"))' + digit=3D'digits:digit:(0 1 2 3 4 5 6 7 8 9)' + if compset -P '*[0-9]'; then + _alternative $mlt $digit && ret=3D0 + elif [[ -z $PREFIX ]]; then + _alternative $sign $digit && ret=3D0 + elif compset -P '(+|-)'; then + _alternative $digit && ret=3D0 + fi + ;; +esac + +return ret diff --git a/Completion/Unix/Command/_tail = b/Completion/Unix/Command/_tail new file mode 100644 index 0000000..3cab26c --- /dev/null +++ b/Completion/Unix/Command/_tail @@ -0,0 +1,65 @@ +#compdef tail + +local curcontext=3D$curcontext state state_descr line expl opts args = ret=3D1 +typeset -A opt_args + +if _pick_variant gnu=3DGNU unix --version; then + args=3D( + '(-n --lines -c --bytes)'{-c+,--bytes=3D}'[print the last specified = bytes; with +, start at the specified byte]:number of bytes:->number' + '(-n --lines -c --bytes)'{-n+,--lines=3D}'[print the last specified = lines; with +, start at the specified line]:number of lines:->number' + '(-F -f)--follow=3D-[output appended data as the file = grows]::how:(name descriptor)' + '(-F --follow)-f[same as --follow=3Ddescriptor]' + '(-f --follow --retry)-F[same as --follow=3Dname --retry]' + '--max-unchanged-stats=3D[with --follow=3Dname, check file rename = after the specified number of iterations]:number of iterations' + '(-s --sleep-interval)'{-s+,--sleep-interval=3D}'[with -f, sleep = the specfied seconds between iterations]:seconds' + '--pid=3D[with -f, terminate after the specified process = dies]:pid:_pids' + '(-q --quiet --silent -v --verbose)'{-q,--quiet,--silent}'[never = output headers giving file names]' + '(-q --quiet --silent -v --verbose)'{-v,--verbose}'[always output = headers giving file names]' + '--retry[keep trying to open a file even when it becomes = inaccessible]' + '(- *)--help[display help and exit]' + '(- *)--version[output version information and exit]' + ) +else + opts=3D'-A "-*"' + args=3D( + '(-b -n)-c+[start at the specified byte]:bytes relative to the end = (with +, beginning) of file' + '(-b -c)-n+[start at the specified line]:lines relative to the end = (with +, beginning) of file' + '(-F -r)-f[wait for new data to be appended to the file]' + ) + case $OSTYPE in + (freebsd*|darwin*|dragonfly*|netbsd*|openbsd*) + args+=3D( + '(-f -F)-r[display the file in reverse order]' + '(-c -n)-b+[start at the specified block (512-byte)]:blocks = relative to the end (with +, beginning) of file' + ) + ;| + (freebsd*|darwin*|dragonfly*|netbsd*) + args+=3D( '(-f -r)-F[implies -f, but also detect file rename]' ) + ;| + (freebsd*|darwin*|dragonfly*) + args+=3D( '-q[suppress the headers when displaying multiple = files]' ) + ;; + esac +fi + +_arguments -C -s -S $opts : $args '*:file:_files' && return 0 + +case $state in + (number) + local mlt sign digit + mlt=3D'multiplier:multiplier:((b\:512 K\:1024 KB\:1000 M\:1024\^2' + mlt+=3D' MB\:1000\^2 G\:1024\^3 GB\:1000\^3 T\:1024\^4 = TB\:1000\^4))' + sign=3D'sign:sign:((+\:"start at the specified byte/line"' + sign+=3D' -\:"output the last specified bytes/lines (default)"))' + digit=3D'digits:digit:(0 1 2 3 4 5 6 7 8 9)' + if compset -P '*[0-9]'; then + _alternative $mlt $digit && ret=3D0 + elif [[ -z $PREFIX ]]; then + _alternative $sign $digit && ret=3D0 + elif compset -P '(+|-)'; then + _alternative $digit && ret=3D0 + fi + ;; +esac + +return ret --=20 1.9.5 (Apple Git-50.3)