π

Enable remote URL opening from screen to Firefox at OS X

Show Sidebar

My setup:

kva (Rootserver)                --- ned (Linux-router) --- marge (OS X desktop)
screen-session with mutt as MUA --- just a hop host    --- here I sit infront of the computer ;-)	  

I am using the host marge as a desktop but I mostly work through a ssh-session to the host ned and another one to host kva in a GNU screen-session on kva.

Don't know GNU screen? If you're working with terminals, you've missed the best tool: http://en.wikipedia.org/wiki/GNU_Screen

Desired feature: when I press a magic key combination, the currently shown content of my screen windows gets parsed for hyperlinks, a window pops up where I can choose one of the found URLs and after selecting it, it gets opened as a new tab on my desktop Firefox browser in OS X. Cool eh? ;-)

Things that have to be accomplished::

  1. enable ssh backward tunnel through ssh from kva to marge
  2. enable ssh-login from kva to marge without entering a password
  3. create a screen-mechanism to extract URLs
  4. invoke a command that opens the URL on my Firefox

Starting the ssh backward tunnel when connecting to kva (from ned):

vk@ned ~ % grep ssh .zshrc.local
alias kva="ssh vk@123.456.78.9 -R 4242:marge:22"
vk@ned ~ %	  

Note: if you connect directly from OS X to the host with the screen session, you can choose "4242:localhost:22" too, without the need of the router hop in between.

enable ssh-login from kva directly to marge without entering a password:

vk@kva ~ % cd .ssh
vk@kva ~/.ssh % ssh-keygen -t rsa
[...generating key pair without passphrase...]
vk@kva ~/.ssh % cat id_rsa.pub | ssh vk@localhost -p 4242 'cat >> .ssh/authorized_keys'
vk@kva ~/.ssh	  

You can do the last step even more cool by using ssh-copy-id. (Have a look on the man-page for further details):

Alternative method using ssh-copy-id:

vk@kva ~ % ssh-copy-id -i .ssh/id_rsa.pub vk@the.ned.server
15
Password:
Now try logging into the machine, with "ssh 'vk@the.ned.server'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

vk@kva ~ %	  

To extract URLs from a file, you can use urlview.

my urlview configuration:

vk@kva ~ % cat .urlview
#
# Sample urlview(1) configuration file
#

# regular expression to use to match URLs
REGEXP (((http|https|ftp|gopher)|mailto):(//)?[^ <>"\t]*|(www|ftp)[0-9]?\.[-a-z0-9.]+)[^ .,;\t\n\r<">\):]?[^, <>"\t]*[^ .,;\t\n\r<">\):]

# command to invoke for selected URL
COMMAND ssh vk@localhost -p 4242 open

vk@kva ~ %	  

manual remote opening test of URLs with urlview:

vk@kva ~ % echo http://www.heise.de >deleteme
vk@kva ~ % urlview deleteme
[ choose URL and press Enter twice ]
[ URL gets opened in Firefox! ]
vk@kva ~ %	  

create a screen-mechanism to extract URLs:

vk@kva ~/.screen % grep urlview default_bind
bind U eval "hardcopy_append off" "hardcopy -h /tmp/screen-urlview.tmp" "screen urlview /tmp/screen-urlview.tmp; rm /tmp/screen-urlview.tmp"
vk@kva ~/.screen %	  

Note: the file "default_bind" from above is sourced in my ~/.screenrc so you can put the line there also.

Now whenever I press "Ctrl-a U" in screen, a dialog pops up with all the URLs found in the current screen and I can choose, which one of those will be opened in my browser. Jeah, Baby jeah!

Note: If you are using mutt as MUA, I described a method to simply copy mail attachments to the OS X desktop which is found in the blog entry "Attachment handling from mutt to OS X (over the network)"


Related articles that link to this one:

Comment via email (persistent) or via Disqus (ephemeral) comments below: