From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29825 invoked by alias); 21 Oct 2010 15:15:52 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15464 Received: (qmail 23835 invoked from network); 21 Oct 2010 15:15:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=3fq6Zztbw83+mP8PEqnl24bZGZosJSKaDNKv9nbwspI=; b=IDV+rng9hodMDLioncyeo2I56A+haE/75NQL3E/hcZhy+1KZgcfSvKSzOSsAHEAW2a aA/bSuiu3dOvsgzjbWoo0dpJ5nMyVmWnIUzjEhqY1+So/6MDZPckRTQ9e2sLz9VH3YgF /kZ9Ae+7sAB8j9T+FQ6F34vXFXYDjCNQX3TME= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=TNJUmK19mQVlLIJbE3JgVzNq1w0EqDR7elsw2RrdaafRI+O/aWI98p5GKIauLy+cC0 kaTnkvvhjIqXMWSC5R08vrNqzsSSscY9baNHx+IEuLnE14paEmApaUcTBc6guvR5L8Vm 8eZ0QIpm7sPGN7kbxQ/q7cQObgHRgOGorkRQM= Date: Thu, 21 Oct 2010 13:15:14 -0200 From: Silas Silva To: zsh-users@zsh.org Subject: Completion for man (_man) patch to support -M Message-ID: <20101021151504.GA24694@bsoares.omnisys.int.com.br> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline User-Agent: Mutt/1.4.2.3i --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, I was studying the completion system and, since I would like to add support for -M for the _man completion, I've done it. Dirty and ugly patch is attached. Anyway, here comes some inline considerations: + if (( $words[(I)-M] == (( $CURRENT - 1 )) )); then + _directories && return 0 + fi + Here I wanted to check if the cursor position (where the user will hit tab) will be just after the -M option. If true, it complete for directories and exit. Is it right? Is there any better way to make that check? First I tried to use the _arguments function, but I realized that _arguments is just an easy layer for what happens behind the scenes and _man (and other completion functions) use the "behind the scenes" way to make things work. + if (( $words[(I)-M] )); then + local opt + opt=$words[(( $words[(I)-M]+1 ))] + _manpath=($_manpath $opt) + fi + _man sets a local MANPATH to make man look for man pages in the right places. If the user set a man path with -M, I want it to be added to the _manpath variable. I'm just not sure if it is the better way to do it. opt holds the option passed to the -M flag, but (( $words[(I)-M]+1 )) looks ugly? If it is all right, can it be pulled upstream? Thank you very much! -- Silas Silva --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="man--M.diff" --- _man.orig 2010-10-21 12:48:02.000000000 -0200 +++ _man 2010-10-21 12:44:37.000000000 -0200 @@ -3,6 +3,10 @@ _man() { local dirs expl mrd awk + if (( $words[(I)-M] == (( $CURRENT - 1 )) )); then + _directories && return 0 + fi + if [[ $service == man ]] && (( $words[(I)-l] + $words[(I)--local-file] )); then _files || return 0 fi @@ -21,6 +25,12 @@ (( $#_manpath )) || _manpath=( /usr/man(-/) /(opt|usr)/(pkg|dt|share|X11R6|local)/(cat|)man(-/) ) + if (( $words[(I)-M] )); then + local opt + opt=$words[(( $words[(I)-M]+1 ))] + _manpath=($_manpath $opt) + fi + # `sman' is the SGML manual directory for Solaris 7. # 1M is system administrator commands on SVR4 --ZPt4rx8FFjLCG7dd--