From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6930 invoked from network); 25 Oct 2003 18:33:31 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 25 Oct 2003 18:33:31 -0000 Received: (qmail 19319 invoked by alias); 25 Oct 2003 18:33:10 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6736 Received: (qmail 8273 invoked from network); 25 Oct 2003 18:26:30 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 25 Oct 2003 18:26:30 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [4.3.58.249] by sunsite.dk (MessageWall 1.0.8) with SMTP; 25 Oct 2003 18:26:29 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id h9PIQRm10362 for zsh-users@sunsite.dk; Sat, 25 Oct 2003 11:26:27 -0700 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to barton.schaefer@verizon.net using -f From: Bart Schaefer Message-Id: <1031025182627.ZM10361@candle.brasslantern.com> Date: Sat, 25 Oct 2003 18:26:27 +0000 In-Reply-To: <200310250100.12757.hisham@apple2.com> Comments: In reply to Hisham Muhammad "How to make tab add quotes on expansion?" (Oct 25, 1:00am) References: <200310250100.12757.hisham@apple2.com> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk Subject: Re: How to make tab add quotes on expansion? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 25, 1:00am, Hisham Muhammad wrote: } } I'd like to have tab-completion to add double quotes to words when the } completed word has spaces in it (instead of having it add a backslash } on each space). } } I know there's probably something simple I am missing No, actually, there isn't anything simple. The builtins that update the command line don't modify the part to the left of the cursor unless they have explicitly been told to (by, e.g. "compadd -U"). A side-effect is that this preserves the quoting that's already in use on the line. So if you type hisham@aria ~] mpg123 "01 you'll get hisham@aria ~] mpg123 "01 - Tom Sawyer.mp3" but if you start with no quotes at all, you'll get backslashes. Rather than try to convince the completion system to rewrite every word, I suggest creating a normal (not completion, i.e., "zle -N" rather than "zle -C") widget which first inserts the double quote and then calls a completion widget. Of course your widget will have to test whether any quote is already there, etc. This would best be accomplished by getting the latest 4.1.x-dev from SourceForge, and using match-words-by-style to parse the command line for you. (I *think* m-w-b-s could be backported to 4.0.7, but I'm not sure.) As an alternative, you could use something like this completer: function _force_quote { [[ -z $compstate[quoting] ]] && compstate[to_end]='' && compadd -U -S "$SUFFIX" -I "$ISUFFIX"\" -i \""$IPREFIX" "$PREFIX" } Plus this widget: function quote-and-complete-word { setopt localoptions unset noksharrays noshwordsplit local lbuf=$LBUFFER rbuf=$RBUFFER last=$LASTWIDGET if [[ $last != $WIDGET ]] then local oldcontext="$curcontext" local curcontext="$WIDGET:${${curcontext:-:::}#*:}" zle complete-word curcontext="$oldcontext" fi zle complete-word local ret=$? if [[ $_lastcomp[nmatches] -eq 0 && $last != $WIDGET ]] then LBUFFER=$lbuf RBUFFER=$rbuf fi return ret } zle -N quote-and-complete-word Plus this zstyle: zstyle ':completion:quote-and-complete-word:*' completer _force_quote And finally bindkey '^I' quote-and-complete-word However, this seems to confuse zsh's "undo" mechanism pretty badly, so use at your own risk.