From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13867 invoked from network); 25 Nov 2004 19:57:02 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Nov 2004 19:57:02 -0000 Received: (qmail 86497 invoked from network); 25 Nov 2004 19:56:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Nov 2004 19:56:56 -0000 Received: (qmail 24080 invoked by alias); 25 Nov 2004 19:47:59 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8238 Received: (qmail 24049 invoked from network); 25 Nov 2004 19:47:54 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 25 Nov 2004 19:47:54 -0000 Received: (qmail 79776 invoked from network); 25 Nov 2004 19:46:53 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 25 Nov 2004 19:46:52 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Thu, 25 Nov 2004 19:45:39 +0000 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 25 Nov 2004 19:47:02 +0000 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.12.11/8.12.11) with ESMTP id iAPJkm6O015083 for ; Thu, 25 Nov 2004 19:46:49 GMT Received: from csr.com (pws@localhost) by news01.csr.com (8.12.11/8.12.11/Submit) with ESMTP id iAPJklpi015080 for ; Thu, 25 Nov 2004 19:46:48 GMT Message-Id: <200411251946.iAPJklpi015080@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: "List: ZSH" Subject: Re: VMS Style auto command-complition In-reply-to: <1101407389.31116.9.camel@localhost> References: <1101407389.31116.9.camel@localhost> Date: Thu, 25 Nov 2004 19:46:46 +0000 From: Peter Stephenson X-OriginalArrivalTime: 25 Nov 2004 19:47:02.0882 (UTC) FILETIME=[88FF1420:01C4D327] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Ziggy wrote: > Recently I have tried using OpenVMS. So far I pretty much like > everything there. > One thing that I liked specifically about it is that it completes > commands automatically if there is only one match. > For example - if I want to purge all the previous versions of all files > in the directory, instead of typing 'PURGE' I can type 'PU' because > there is no any other command that starts with PU, so it knows that I'm > talking about the command PURGE: > > $ pu <- here the command went out fine > $ p <- here it says that there are other commands that start with p > %DCL-W-ABVERB, ambiguous command verb - supply more characters > \P\ > > I wish you could tell me if it is possible to do with ZSH, because this > feature is simply one of OpenVMS' best features. There are lots of answers to this which deserve thinking about. First, Unix command names tend to be short and it's much harder to find unambiguous completions in many cases. Second, you can explicitly ask for a completion of the command name with a TAB. Because of the first point, this is very often more useful than assuming an unambiguous expansion. Third, you can assign an explicit alias "alias pu=purge". Since in practice you tend to use only one abbreviation, you don't have to go through the full equivalent ("alias pu=purge pur=purge purg=purge"). If, despite all that, you still want to try it this way, have a go at the following function. Assuming it's called autoexpand in your function path, you activate it with autoload autoexec zle -N autoexec alias -A autoexpand accept-line and deactivate it with alias -A .accept-line accept-line Be careful, since it's not well tested and I'm sure there are additional safety tests it could usefully have. However, I don't think it's liable to reformat your disk. Instead of trying to execute a command and failing if it finds multiple possibilities, it outputs an error message underneath and allows you to edit the line again. This is likely to be the biggest source of grief. You can turn that off by replacing zle -M "Multiple $hash matches: $expn" return 1 with zle .accept-line return 0 # start autoexpand integer curpos len local hash cmd line expn found line=(${(z)BUFFER}) len=${#line[1]} cmd=${(Q)line[1]} if [[ -z $cmd ]]; then zle .accept-line return 0 fi for hash in aliases reswords functions builtins commands; do # always accept exact match if [[ $hash = reswords ]]; then # actually it's an array expn=${reswords[(r)$cmd]} else # expn=${(P)hash[$cmd]} doesn't do the right thing eval expn='${(k)'$hash'[$cmd]}' fi if [[ -n $expn ]]; then zle .accept-line return 0 fi done for hash in aliases reswords functions builtins commands; do if [[ $hash = reswords ]]; then # actually it's an array expn=(${reswords:#^$cmd*}) else eval expn='(${(k)'$hash'[(I)$cmd*]})' fi if (( ${#expn} > 1 )); then zle -M "Multiple $hash matches: $expn" return 1 elif (( ${#expn} == 1 )); then (( curpos = CURSOR )) BUFFER[1,$len]="$expn" (( curpos <= len )) && (( CURSOR = ${#expn[1]} )) zle .accept-line return 0 else continue fi done zle .accept-line # end autoexpand -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************