zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@zsh.org (Zsh hackers list)
Subject: PATCH: man pages as files, at last
Date: Fri, 03 Dec 2010 17:22:16 +0000	[thread overview]
Message-ID: <12523.1291396936@csr.com> (raw)

I've always been too cowardly to try to get _man to complete file names
instead of page references by default, since it's not universally
supported and I'm not entirely sure how to mix them as normal
alternatives.

This is the easy way out: if there's a "/" in the name you must be
looking for a file explicitly.  As it happens, I tend to use "./" in front
of manual pages I want to look at; further the man page for man here
says it treats words with a "/" specially, so this is good enough for
me.

I can't remember how many years it is since this was first requested.

It might want some _wanted stuff if anyone can remember what to put.

Index: Completion/Unix/Command/_man
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_man,v
retrieving revision 1.13
diff -p -u -r1.13 _man
--- Completion/Unix/Command/_man	21 Oct 2010 19:29:09 -0000	1.13
+++ Completion/Unix/Command/_man	3 Dec 2010 17:15:06 -0000
@@ -86,6 +86,18 @@ _man() {
 _man_pages() {
   local matcher pages dummy sopt
 
+  # What files corresponding to manual pages can end in.
+  local suf='.((?|<->*)(|.gz|.bz2|.Z|.lzma))'
+
+  if [[ $PREFIX$SUFFIX = */* ]]; then
+    # Easy way to test for versions of man that allow file names.
+    # This can't be a normal man page reference.
+    # Try to complete by glob first.
+    _path_files -g "*$suf" && return
+    _path_files
+    return
+  fi
+
   zparseopts -E M+:=matcher
 
   if (( $#matcher )); then
@@ -109,9 +121,9 @@ _man_pages() {
   if ((CURRENT > 2)) ||
       ! zstyle -t ":completion:${curcontext}:manuals.$sect" insert-sections
   then
-    compadd "$@" - ${pages%.((?|<->*)(|.gz|.bz2|.Z|.lzma))}
+    compadd "$@" - ${pages%$~suf}
   else
-    compadd "$@" -P "$sopt$sect " - ${pages%.((?|<->*)(|.gz|.bz2|.Z|.lzma))}
+    compadd "$@" -P "$sopt$sect " - ${pages%$~suf}
   fi
 }
 
-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


                 reply	other threads:[~2010-12-03 17:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12523.1291396936@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).