urldecode plugin for gedit

For my friend Kenneth:

  1. Enable the “External Tools” plugin in the gedit plugin prefs click “Configure Plugin”
  2. Create a new plugin and name it UrlEncode
  3. Select a shortcut key
  4. Set Input & Output to Current selection / Replace current selection

Paste this into command(s):

#!/bin/sh
 (C) 2006 GPL by Huidae Cho
awk '
BEGIN{
  for(i = 0; i < 10; i++)
    hex[i] = i
  hex["A"] = hex["a"] = 10
  hex["B"] = hex["b"] = 11
  hex["C"] = hex["c"] = 12
  hex["D"] = hex["d"] = 13
  hex["E"] = hex["e"] = 14
  hex["F"] = hex["f"] = 15
}
{
  gsub(/\+/, " ")
  i = $0
  while(match(i, /%../)){
    if(RSTART > 1)
      printf "%s", substr(i, 1, RSTART-1)
    printf "%c", hex[substr(i, RSTART+1, 1)] * 16 + hex[substr(i, RSTART+2, 1)]
    i = substr(i, RSTART+RLENGTH)
  }
  print i
}
'

Further reading:

Posted on 16 May 2009 by Morgan Christiansson.
blog comments powered by Disqus