zsh-users
 help / color / mirror / code / Atom feed
* detecting a url - run browser
@ 2001-08-19 14:15 Eric Smith
  2001-08-19 16:29 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Smith @ 2001-08-19 14:15 UTC (permalink / raw)
  To: zsh-users

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

thanx

-- 
Eric Smith


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: detecting a url - run browser
  2001-08-19 14:15 detecting a url - run browser Eric Smith
@ 2001-08-19 16:29 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2001-08-19 16:29 UTC (permalink / raw)
  To: Eric Smith, zsh-users

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   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-19 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-19 14:15 detecting a url - run browser Eric Smith
2001-08-19 16:29 ` Bart Schaefer

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).