chris blogs: October 2010

31oct2010 · Two insanely useful command line tools

I have been using these two almost trivial scripts for a few months now and they have become rather essential for my workflow.

clip2firefox:

#!/bin/sh
# clip2firefox - open selected text as firefox address
firefox "$(xclip -out)"

clip2goog:

#!/bin/zsh
# clip2goog - google for selected text

selurl() {
  setopt localoptions extendedglob
  sel=$(xclip -out)
  input=( ${(s::)sel} )
  print ${(j::)input/(#b)([^A-Za-z0-9_.!~*\'()-])/%$(([##16]#match))}
}

firefox "http://google.com/search?q=$(selurl)"

I give them shortcuts with xbindkeys:

"clip2goog"
  Mod4 + g

"clip2firefox"
  Mod4 + o

… and instantly I can open any URL or google for every selection I made.

When I first read about these scripts, I thought they weren’t a big deal, but they are insanely useful, believe me.

NP: The Brian Jonestown Massacre—The Be Song

Copyright © 2004–2016