« Firefox, you're annoying me again!Take a tablet »

Tue, May 15, 2012

[Icon][Icon]Open URLs from the CLI

• Post categories: Omni, FOSS, Programming, Helpful

Despite the rise of bulletin boards, social media, wikis, and god knows what other means of communication the Web has given rise to, programmers still rely heavily on Old Faithful: IRC.

Personally, I tend to be logged on to over a dozen channels at any one time, via irssi - a command-line IRC client. This has the advantage that I can leave it running in a screen session and stay logged in permanently, and access it from anywhere I have a net connection.

Most of the people I work with use also use irssi, but there's also some fondness for xchat. One feature it has that no command-line client supports is that you can click on a link in xchat and it opens in your browser. Using irssi, I have to copy & paste it manually into a browser.

This got slightly tedious recently, so I devised a shortcut. It's nice and simple, just a few lines of perl called from xbindkeys. All I have to do now is double-click on a link to select it, then press a shortcut key, and the link opens in a new tab in Firefox. Simple as that.

If anyone else wants to be able to do that, the code is available below:


# Take URL from clipboard & open it in firefox

use strict;
use warnings;
use Clipboard;

# Ugly fixify of cliboard order
if ('Clipboard::Xclip' eq $Clipboard::driver) {
    no warnings 'redefine'; *Clipboard::Xclip::all_selections = sub {
        qw(clipboard primary buffer secondary)

# Get the URL from clipboard
my $url = Clipboard->paste;

# Pass it to firefox
system("firefox $url");

I have this script get called by xbindkeys, using the shortcut Start-f since it happened to be free. Works well!


Comment from: woddfellow2 [Visitor] · http://wlair.us.to/
I still usually just C-a [ copy the URI from irssi manually, then either open a shell or switch to a pre-existing one, type "firefox ", C-a ] paste, type " &", and send the command. If Firefox is not already running, I start it before doing this.
15/05/12 @ 13:27
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
An excellent strategy, with just two drawbacks: It takes longer than a quick double-click; and I run my screen on a remote server, not my local machine :)
15/05/12 @ 13:59
Comment from: passstab [Visitor]
why don't you use tmux?
is lighter and cleaner then screen
15/05/12 @ 17:01
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
Eh.. I've been using screen since the 90s, I'm used to it & haven't encountered anything that made me want to change so far..
15/05/12 @ 17:09
Jakub Narębski
Comment from: Jakub Narębski [Visitor]
IIRC X-Chat can open link in new tab, but this requires passing URL in some parameter to firefox.

"firefox -new-tab $url"

But now I see that depending on configuration of Firefox your solution would also do the right thing.
15/05/12 @ 19:23
Mark Gardner
Comment from: Mark Gardner [Visitor] Email
rxvt-unicode (a.k.a. urxvt) comes with an extension to do this. Just put the following in your ~/.Xresources:

URxvt.perl-ext-common: default,matcher
URxvt.urlLauncher: /usr/bin/firefox

Voila, clickable URLs.
15/05/12 @ 22:17
Scott Thomson
Comment from: Scott Thomson [Visitor]
My terminal emulator (XFCE Terminal) handles this for me, any text it recognises as URLs (in any output, vim, irssi etc.) are clickable using middle click and open in my default browser.

I think it has worked like this for years and I don't remember having to configure anything apart from choosing the default browser in the general desktop settings.
16/05/12 @ 09:46
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
Nice to know there are a few terminals out there that can do clickable links. I actually prefer mine non-clickable for ease of C&P but that may change in future..
17/05/12 @ 10:37
Cliff Stanford
Comment from: Cliff Stanford [Visitor] Email · http://may.be/
You might want to consider using Browser::Open rather than calling firefox directly.
21/05/12 @ 15:01

[Links][icon] My links

[Icon][Icon]About Me

[Icon][Icon]About this blog

[Icon][Icon]My /. profile

[Icon][Icon]My Wishlist


[FSF Associate Member]

November 2015
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29


User tools

XML Feeds

eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

powered by open-source CMS software