Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: detecting a url - run browser
- X-seq: zsh-users 4140
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Eric Smith <Eric.Smith@xxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Subject: Re: detecting a url - run browser
- Date: Sun, 19 Aug 2001 16:29:44 +0000
- In-reply-to: <20010819161552.A2343@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20010819161552.A2343@xxxxxxxxxxxxxxxxxx>
On Aug 19, 4:15pm, Eric Smith wrote:
} Subject: detecting a url - run browser
}
} What would I do to configure zsh to detect
} $ www.foo.com or
} $ http://bar.dk etc
} entered at the prompt as a url and then execute:
} w3m <the url>
} ?
You'll have to use the preexec function -- which means it'll work only at
the command line, only at the PS1 prompt (not inside a function body or a
loop body or a subshell or ...), and only in zsh 4.0. [*]
function preexec {
local cmd
cmd=(${(Q)${(z)3}})
# Adjust this URL recognition test as necessary
if [[ $cmd[1] == (http://*|www.*.*) ]]; then
eval "function ${(q)cmd[1]} {
unsetopt noglob
w3m ${(q)cmd[1]}" '$*
unfunction' "${(q)cmd[1]}
}"
setopt noglob
fi
}
You can probably do without the noglob twaddling; I put it there just so
you don't have to quote question marks and tildes (~) and so forth in the
URLs, but you still have to quote ampersands (&) and semicolons.
[*] Actually preexec is available as far back as 3.1.3, but the complete
combination of things in my example are available only as of very recently.
--
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