From: Bart Schaefer <schaefer@brasslantern.com>
To: Eric Smith <Eric.Smith@fruitcom.com>, zsh-users@sunsite.dk
Subject: Re: detecting a url - run browser
Date: Sun, 19 Aug 2001 16:29:44 +0000 [thread overview]
Message-ID: <1010819162945.ZM17258@candle.brasslantern.com> (raw)
In-Reply-To: <20010819161552.A2343@apple.fruitcom.com>
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
prev parent reply other threads:[~2001-08-19 16:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-19 14:15 Eric Smith
2001-08-19 16:29 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1010819162945.ZM17258@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=Eric.Smith@fruitcom.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).