This is only tangentially OpenBSD-related, but probably a no-brainer
for most of you who have a basic understanding of awk(1), so I'm
hoping I can pick your brains:

Now please bear with me, I'll get to the awk problem soon:
I want to make Firefox respect telnet URLs, ie. if I click on a URL
such as telnet://mud.vhdev.com:1991, I want Firefox to launch telnet
in xterm, and make it hand off the domain name and port to it, so
telnet can connect to the host (at the given port, if one was
specified).

So far, I have created a script .telnet4firefox.sh in my home folder,
made that executable (chmod u+x), and in Firefox' about:config I have
added a new boolean network.protocol-handler.external.telnet (set to
true) and a new string network.protocol-handler.app.telnet (set to
/home/ropers/.telnet4firefox.sh). The contents of the script are:

#!/bin/sh
xterm -e "telnet ${1##telnet://}"

When I click a telnet URL that does not specify a port, it works,
xterm launches with telnet, which duly connects to the port.

However, if I click a telnet URL that *does* specify a port, it does
not work, xterm closes immediately. I've manually figured out that it
throws the error message

telnet: could not resolve mud.vhdev.com:1991/telnet: Name or service not known

before closing.

man telnet told me that telnet expects to be given the port number
separated by a space, not divided by a colon.

Currently, if I click on telnet://mud.vhdev.com:1991, telnet is called with

telnet mud.vhdev.com:1991

instead of

telnet mud.vhdev.com 1991

which would be correct.

But I'm just too stupid/stumped figuring out how to do this
super-basic substitution in the above script. How do I make it replace
the : with a space (if a :portnumber part is present)?

I'm awfully sorry to ask such a basic question here. Maybe the many
introductions to awk on the web were not gentle enough for my poor
little loaf. I just can't get it to work.
Many thanks in advance for any pointers. Pointers to superior
sed/grep/awk tutorials also highly welcome! I've started reading
http://www.grymoire.com/Unix/Awk.html , but I'm either too dumb or too
impatient with myself.

Cheers,
--ropers

Reply via email to