Eitan Suez's Home

TextMate icon

Open Sesame

Posted by eitan Tue, 17 Jan 2006 22:38:59 GMT

One of the small little but valuable features I used to like on macosx (before switching to Ubuntu last Summer) was the command-line open command. You could just type open index.html and the file would pop up in the a web browser. I used it all the time.

I'm not "guru of the universe" and surely something like this exists for linux but for some reason thirty minutes searching the synaptic package manager did not yield anything.

So one day I finally decided to turn on my brain for a change and in five minutes hacked this:

  #!/usr/bin/ruby -w

  def suffix(file_name)
    file_name.split(".").last()
  end

  map = {
           "pdf" => "kpdf",
           "directory" => "nautilus",
           "html" => "epiphany",
           "htm" => "epiphany",
           "xls" => "gnumeric",
           "csv" => "gnumeric",
           "txt" => "kate",
           "gif" => "eog",
           "jpg" => "eog",
           "png" => "eog",
           "xml" => "gedit"
         }

  file_name = ARGV[0]
  key = (File.directory?(file_name)) ? "directory" : suffix(file_name)
  app_name = map[key]

  fork do
    puts "invoking #{app_name}..\n"
    exec "#{app_name} #{file_name}"
  end

I've been using it daily for a while now and I like it. Over time I've built myself a few other little utilities. A recent one is merge for merging data with an erb template. I use 'show' a lot. It breaks down a path-like structure into multiple line entries so one can actually read the foresaken string. I use it like this:

  eitan@ubuntu:~/bin$ show path
  PATH:
  /usr/local/bin
  /usr/local/sbin
  /sbin
  /usr/sbin
  /bin
  /usr/bin
  ...

.. or show classpath etc..

Another one that is a real time saver when the time comes to import a new project into subversion is svnize which will automatically restructure your project in the trunk/tags/branches hierarchy suitable for doing the import.

Posted in ,  | no comments

Comments

Comments are disabled


Powered