Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: detecting a url - run browser

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
        # 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

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