From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28360 invoked from network); 25 Mar 2006 18:16:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Mar 2006 18:16:46 -0000 Received: (qmail 86734 invoked from network); 25 Mar 2006 18:16:39 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Mar 2006 18:16:39 -0000 Received: (qmail 7526 invoked by alias); 25 Mar 2006 18:16:32 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10079 Received: (qmail 7515 invoked from network); 25 Mar 2006 18:16:32 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 25 Mar 2006 18:16:32 -0000 Received: (qmail 85632 invoked from network); 25 Mar 2006 18:16:32 -0000 Received: from shu.cs.utk.edu (160.36.56.39) by a.mx.sunsite.dk with SMTP; 25 Mar 2006 18:16:29 -0000 Received: from localhost (shu [127.0.0.1]) by shu.cs.utk.edu (Postfix) with ESMTP id AE62913B27 for ; Sat, 25 Mar 2006 13:16:27 -0500 (EST) Received: from shu.cs.utk.edu ([127.0.0.1]) by localhost (shu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 10903-01 for ; Sat, 25 Mar 2006 13:16:25 -0500 (EST) Received: from namib.cs.utk.edu (namib.cs.utk.edu [160.36.59.92]) by shu.cs.utk.edu (Postfix) with ESMTP id E68DF13B22 for ; Sat, 25 Mar 2006 13:16:25 -0500 (EST) Received: by namib.cs.utk.edu (Postfix, from userid 10605) id A31C836EFF; Sat, 25 Mar 2006 13:16:25 -0500 (EST) Date: Sat, 25 Mar 2006 13:16:25 -0500 From: Chris Johnson To: zsh-users@sunsite.dk Subject: Textfile-Favoring Completion Message-ID: <20060325181625.GA17430@namib.cs.utk.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new with ClamAV and SpamAssasin at cs.utk.edu A while back I posted about trying to complete only text files for vi, vim, and emacs. I'd had the problem of opening executable files instead of the longer named source files (app versus app.c). Bart and Peter offered some good suggestions, but for one reason or another, nothing's worked out perfect. I think Peter suggested this one: # First match files that end in known text file extensions or are # directories. Failing that, match anything. zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \ '*.(c|h|pl|tex|txt|cpp|java|php|bib):globbed-files *(-/):directories' \ '*:all-files' This one works okay, but that regular expression which details all known text files becomes unwieldy. Dotfiles aren't currently matched with that pattern. I thought I'd lost my .muttrc once because only my .mutt directory would complete. Completion has minimized my usage of ls, and this can get me in trouble. Bart offered a solution that fixed this and was almost always right on target, scanning the result of the UNIX file utility for the word 'text'. This was a little slow, however: textfiles() { reply=( ${${(@M)${(f)"$(file $REPLY 2>/dev/null)"}\:#*text*}%:*} ) } zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \ '%p(e,textfiles,):globbed-files *(-/):directories' \ '*:all-files' Now I'm using something slightly simpler that has the same drawback as the first solution in hiding certain files when there's a valid match in the first group. (For instance, I want to complete an executable plain file 'itself.sh' but there's a directory 'include' that supercedes.) It does cut back on the regular expression maintenance, though. (I haven't entered the extensions for LaTeX yet, so this may change.) # First match files that aren't plain executable files or don't # end in .o. Failing that, match anything. zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \ '*~*.o(^*):globbed-files' '*:all-files' Just thought I'd share. Someone posted something similar specifically about LaTeX a few weeks ago which caused me to revisit the issue. -- Chris Johnson cjohnson@cs.utk.edu http://www.cs.utk.edu/~cjohnson