From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2333 invoked from network); 30 Aug 2002 05:32:50 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 30 Aug 2002 05:32:50 -0000 Received: (qmail 2820 invoked by alias); 30 Aug 2002 05:32:33 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5319 Received: (qmail 2806 invoked from network); 30 Aug 2002 05:32:32 -0000 From: "Bart Schaefer" Message-Id: <1020830053200.ZM9539@candle.brasslantern.com> Date: Fri, 30 Aug 2002 05:31:59 +0000 In-Reply-To: <1020828152500.ZM7603@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "Re: zsh-4.04 and w3m browser" (Aug 28, 3:25pm) References: <20020828121825.GD13666@greux.loria.fr> <18364.1030539052@csr.com> <20020828130851.GE13666@greux.loria.fr> <1020828152500.ZM7603@candle.brasslantern.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Vincent Lefevre , Zsh users list Subject: Re: zsh-4.04 and w3m browser MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 28, 3:25pm, Bart Schaefer wrote: } } Minimally tested, but seems to work: Actually there was a bug, which is that even with ${var##pat} it's not necessarily the case that the longest pattern will be matched when the pattern contains alternatives with (|) -- because that form tries each alternative in order, and stops when one matches. So the right formulation is (only two of the `|' have moved): ---- 8< ---- snip ---- 8< ---- function urlglobber { local -a args globbed local arg command="$1" shift for arg do case "${arg}" in (ftp://(|localhost)/*) globbed=( ${~${arg##ftp://(localhost|)}} ) args[$#args+1]=( "${(M)arg##ftp://(localhost|)}${(@)^globbed}" ) ;; ((http(|s)|ftp):*) args[$#args+1]="$arg";; (*) args[$#args+1]=( ${~arg} );; esac done "$command" "${(@)args}" } alias globurl='noglob urlglobber' ---- 8< ---- snip ---- 8< ---- However, I had another thought about a possible approach to handling URLs in shell input: ---- 8< ---- snip ---- 8< ---- function url-magic-space { local words words=("${(@Q)${(q)=LBUFFER}}") case "$words[-1]" in (*[\'\"]*) ;; (ftp://(|localhost)/(~|*([][?#*]|\(|\)))*) local left="${(qqM)${words[-1]}##ftp://(localhost|)}" local right="${${words[-1]}##ftp://(localhost|)}" right="${right/#\/~/~}" words[-1]="$left"'"${(f)^$(print -lr -- '"$right"')}"' ;; (http(|s)|ftp):*) words[-1]="${(qq)words[-1]}" ;; esac LBUFFER="${(j: :)words}" zle self-insert # Or zle magic-space if you prefer ... } zle -N url-magic-space bindkey ' ' url-magic-space ---- 8< ---- snip ---- 8< ---- When SPACE is pressed, the widget above rewrites e.g. zsh% echo ftp://localhost/~/* into zsh% echo ftp://localhost"${(f)^$(print -lr -- ~/*)}" which should have the desired end result (unless you have file names with embedded newlines), even if it's not so readable. It also turns zsh% lynx http://somewhere.com/something.cgi?x=1&y=2&so=on into zsh% lynx 'http://somewhere.com/something.cgi?x=1&y=2&so=on' (that is, it adds the quotes for you) and it is clever enough to try not to mess with a word that already uses quotes (though that too might be improved a little bit with a lot of effort). -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net