Gedit: make links clickable (with Ruby script)

Gedit is my favorite text editor in Ubuntu. It’s almost perfect for me.
I use it for fast files editing or simple scripts writing when I don’t want to open my IDE.
enter image description here

But I feel uncomfortable with Gedit when I cannot click links directly in text. We can fix it easily with External Tools plugin. All we need is to write a simple script (I prefer Ruby) and run it through External Tools.

Write Ruby script

  1. Create click_link.rb in your home directory.
  2. Paste following text to click_link.rb

    
    #!/usr/local/bin/ruby
    
    v1 = ARGV[0]
    require "uri"
    url =  URI.extract(v1)[0]
    system("firefox #{url.to_s}")
  3. Do not forget to make click_link.rb executable

    chmod +x click_link.rb

Create External Tool for Gedit

  1. Enable External Tools plugin in Preferences
  2. Tools > Manage External Tools
  3. Add new tool
  4. Paste following text

    
    #!/bin/sh
    
    /<your_path_to_file>/click_link.rb $GEDIT_CURRENT_LINE 
  5. Set Input = Current line and set desired Shortcut key
    enter image description here

Thats it.

Now just set your cursor on the line with a valid URL and press your shortcut key. Firefox should open your URL.
enter image description here

You can do a lot of interesting things with External Tools. Anything you want!
For example, you can grep selected word from another document or logs.

Comments

Popular posts from this blog

Geminabox: Simple private RubyGems server on your own host

Using Jenkins as HTTP server for your custom HTML