Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh-4.04 and w3m browser
- X-seq: zsh-users 5319
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: Vincent Lefevre <vincent@xxxxxxxxxx>, Zsh users list <zsh-users@xxxxxxxxxx>
- Subject: Re: zsh-4.04 and w3m browser
- Date: Fri, 30 Aug 2002 05:31:59 +0000
- In-reply-to: <1020828152500.ZM7603@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20020828121825.GD13666@xxxxxxxxxxxxxx> <18364.1030539052@xxxxxxx> <20020828130851.GE13666@xxxxxxxxxxxxxx> <1020828152500.ZM7603@xxxxxxxxxxxxxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author