summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2015-10-29 01:03:18 +0900
committerJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2015-10-29 01:03:18 +0900
commit9640e9f497e8d78bf0bfa9defc4cfdeba1e7bfae (patch)
tree395aea06dcece2f2a78e11cbeda557c1c13b267d /Completion
parentaba7c00698fdd459d2f17f84ed371413458afae5 (diff)
downloadzsh-9640e9f497e8d78bf0bfa9defc4cfdeba1e7bfae.tar.gz
zsh-9640e9f497e8d78bf0bfa9defc4cfdeba1e7bfae.tar.xz
zsh-9640e9f497e8d78bf0bfa9defc4cfdeba1e7bfae.zip
36983 + 36990: new completions for head and tail
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Command/_head45
-rw-r--r--Completion/Unix/Command/_tail65
2 files changed, 110 insertions, 0 deletions
diff --git a/Completion/Unix/Command/_head b/Completion/Unix/Command/_head
new file mode 100644
index 000000000..4f956acdc
--- /dev/null
+++ b/Completion/Unix/Command/_head
@@ -0,0 +1,45 @@
+#compdef head
+
+local curcontext=$curcontext state state_descr line expl opts args ret=1
+typeset -A opt_args
+
+if _pick_variant gnu=GNU unix --version; then
+  args=(
+    '(-n --lines -c --bytes)'{-c+,--bytes=}'[print the first (or with -, all but the last) specified bytes]:number of bytes:->number'
+    '(-n --lines -c --bytes)'{-n+,--lines=}'[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=(-A '-*')
+  args=( '(-c)-n+[display the first specified lines]:number of lines' )
+  case $OSTYPE in
+    (freebsd*|darwin*|dragonfly*|netbsd*)
+      args+=( '(-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='multiplier:multiplier:((b\:512 K\:1024 KB\:1000 M\:1024\^2'
+    mlt+=' MB\:1000\^2 G\:1024\^3 GB\:1000\^3 T\:1024\^4 TB\:1000\^4))'
+    sign='sign:sign:((-\:"print all but the last specified bytes/lines"'
+    sign+=' +\:"print the first specified bytes/lines (default)"))'
+    digit='digits:digit:(0 1 2 3 4 5 6 7 8 9)'
+    if compset -P '*[0-9]'; then
+      _alternative $mlt $digit && ret=0
+    elif [[ -z $PREFIX ]]; then
+      _alternative $sign $digit && ret=0
+    elif compset -P '(+|-)'; then
+      _alternative $digit && ret=0
+    fi
+    ;;
+esac
+
+return ret
diff --git a/Completion/Unix/Command/_tail b/Completion/Unix/Command/_tail
new file mode 100644
index 000000000..6e1445328
--- /dev/null
+++ b/Completion/Unix/Command/_tail
@@ -0,0 +1,65 @@
+#compdef tail
+
+local curcontext=$curcontext state state_descr line expl opts args ret=1
+typeset -A opt_args
+
+if _pick_variant gnu=GNU unix --version; then
+  args=(
+    '(-n --lines -c --bytes)'{-c+,--bytes=}'[print the last specified bytes; with +, start at the specified byte]:number of bytes:->number'
+    '(-n --lines -c --bytes)'{-n+,--lines=}'[print the last specified lines; with +, start at the specified line]:number of lines:->number'
+    '(-F -f)--follow=-[output appended data as the file grows]::how:(name descriptor)'
+    '(-F --follow)-f[same as --follow=descriptor]'
+    '(-f --follow --retry)-F[same as --follow=name --retry]'
+    '--max-unchanged-stats=[with --follow=name, check file rename after the specified number of iterations]:number of iterations'
+    '(-s --sleep-interval)'{-s+,--sleep-interval=}'[with -f, sleep the specfied seconds between iterations]:seconds'
+    '--pid=[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=(-A '-*')
+  args=(
+    '(-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+=(
+	'(-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+=( '(-f -r)-F[implies -f, but also detect file rename]' )
+      ;|
+    (freebsd*|darwin*|dragonfly*)
+      args+=( '-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='multiplier:multiplier:((b\:512 K\:1024 KB\:1000 M\:1024\^2'
+    mlt+=' MB\:1000\^2 G\:1024\^3 GB\:1000\^3 T\:1024\^4 TB\:1000\^4))'
+    sign='sign:sign:((+\:"start at the specified byte/line"'
+    sign+=' -\:"output the last specified bytes/lines (default)"))'
+    digit='digits:digit:(0 1 2 3 4 5 6 7 8 9)'
+    if compset -P '*[0-9]'; then
+      _alternative $mlt $digit && ret=0
+    elif [[ -z $PREFIX ]]; then
+      _alternative $sign $digit && ret=0
+    elif compset -P '(+|-)'; then
+      _alternative $digit && ret=0
+    fi
+    ;;
+esac
+
+return ret