about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authortaiyu <taiyu.len@gmail.com>2021-02-07 05:15:03 -0800
committerOliver Kiddle <opk@zsh.org>2021-02-13 01:01:40 +0100
commit3714ee0b5868a30d7556acab337889849a3c8226 (patch)
tree45c6279283d66a61666d1c96043bfa029bf5a3de /Completion
parent3d6e5b6231f0d80873c6f83924a48df223121e72 (diff)
downloadzsh-3714ee0b5868a30d7556acab337889849a3c8226.tar.gz
zsh-3714ee0b5868a30d7556acab337889849a3c8226.tar.xz
zsh-3714ee0b5868a30d7556acab337889849a3c8226.zip
github #68: support section suffix completion for man pages
Support prepend and suffix values for insert-sections
Add values for insert-sections for zstyle completion
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Command/_man22
-rw-r--r--Completion/Zsh/Command/_zstyle6
2 files changed, 20 insertions, 8 deletions
diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man
index 7d55201e3..dba1d13dc 100644
--- a/Completion/Unix/Command/_man
+++ b/Completion/Unix/Command/_man
@@ -6,7 +6,6 @@
 # - We assume that Linux distributions are using either man-db or mandoc
 # - @todo Would be nice to support completing the initial operand as a section
 #   name (on non-Solaris systems)
-# - @todo We don't support the man-db syntax <name>.<section> (e.g., `ls.1`)
 # - @todo We don't support the man-db feature of 'sub-pages' — that is, treating
 #   pairs of operands like `git diff` as `git-diff`
 # - @todo Option exclusivity isn't super accurate
@@ -415,7 +414,7 @@ _man() {
 }
 
 _man_pages() {
-  local pages sopt
+  local pages sopt tmp
 
   # What files corresponding to manual pages can end in.
   local suf='.((?|<->*|ntcl)(|.gz|.bz2|.z|.Z|.lzma))'
@@ -444,13 +443,20 @@ _man_pages() {
   # `POSIX.1.5'.
 
   [[ $variant = solaris* ]] && sopt='-s '
-  if ((CURRENT > 1 || noinsert)) ||
-      ! zstyle -t ":completion:${curcontext}:manuals.$sect_dirname" insert-sections
-  then
-    compadd "$@" - ${pages%$~suf}
-  else
-    compadd "$@" -P "$sopt$sect_dirname " - ${pages%$~suf}
+  if ! ((CURRENT > 1 || noinsert)); then
+    zstyle -s ":completion:${curcontext}:manuals.$sect_dirname" insert-sections tmp
   fi
+  case "$tmp" in
+    prepend|true|on|yes|1)
+      compadd "$@" -P "$sopt$sect_dirname " - ${pages%$~suf}
+    ;;
+    suffix)
+      compadd "$@" -s ".$sect_dirname" - ${pages%$~suf}
+    ;;
+    *)
+      compadd "$@" - ${pages%$~suf}
+    ;;
+  esac
 }
 
 _man "$@"
diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index bb0e1f5bc..0473dd0fe 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -62,6 +62,7 @@ styles=(
   ignore-parents         c:ignorepar
   ignored-patterns	 c:
   insert-ids             c:insert-ids
+  insert-sections	 c:insert-sections
   insert-tab             c:bool
   insert-unambiguous	 c:insunambig
   keep-prefix		 c:keep-prefix
@@ -524,6 +525,11 @@ while (( $#state )); do
           compadd - menu single longer
       ;;
 
+    (insert-sections)
+      _wanted values expl 'where to insert man page section' \
+          compadd - true false prepend suffix
+      ;;
+
     (fake-files)
       _message -e fakes 'prefix and names'
       ;;