Created
June 20, 2010 17:47
-
-
Save xxx/445970 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; url grabber | |
; vega@Sanity's Edge | |
; Notes: The -c switch to /url requires your system's sed utility to | |
; support the -i (update file in-place) option. It would be | |
; fairly trivial to re-write it to use redirects, but i | |
; don't feel like doing it. | |
; | |
; config | |
/def browser_command = /quote -0 !export DISPLAY=:0.0;firefox \ | |
$[escape(" &|<>$\"*(){}'[]?@#~`;", {1})] > /dev/null 2>&1 | |
/set urlfile=/home/pope/.tfurl | |
; allow us to add urls by hand | |
/def add_new_url = \ | |
/set lasturl %{1} %; \ | |
/let handle= %; \ | |
/test handle := tfopen({urlfile}, "a") %; \ | |
/if ({handle} == -1) \ | |
/return %; \ | |
/endif %; \ | |
/test tfwrite({handle}, "%{1}") %; \ | |
/test tfclose({handle}) | |
; url catcher | |
/def -p999 -F -mregexp \ | |
-t'((?xi)(?:(?:ht|f)tp://|) \ | |
[\w\d\-\.]+\.(?:com|net|org|edu|au|uk|ca|de|cc) \ | |
(?:[?/]{1,2}[^\)\s]+|))' \ | |
urlgrab = /add_new_url %{P1} | |
; do stuff with caught urls | |
; /url - go to the most recently grabbed url | |
; /url -l - list all grabbed urls | |
; /url -a<url> - add a new url to the list by hand | |
; /url -u<url> - just open browser to <url>. don't save it or add to list. | |
; /url -c<number> - remove a url from the list (depends on system sed) | |
; /url -n<number> - open browser window to url <n> from list. | |
; /url -q - remove all duplicates from url list | |
/def url = \ | |
/test getopts("qhln#c#a:u:", -1) %; \ | |
/if ({opt_l} == 1) \ | |
/let handle= %; \ | |
/test handle := tfopen({urlfile}, "r") %; \ | |
/if ({handle} == -1) \ | |
/return %; \ | |
/endif %; \ | |
/let lineno=1 %; \ | |
/let line= %;\ | |
/while (tfread({handle}, {line}) != -1) \ | |
/_echo %{lineno}: %{line} %; \ | |
/test lineno += 1 %; \ | |
/done %; \ | |
/test tfclose({handle}) %; \ | |
/elseif ({opt_n} != -1) \ | |
/if ({opt_n} < 1) /_echo Don't be gay. %; /return %; /endif %; \ | |
/let handle= %; \ | |
/test handle := tfopen({urlfile}, "r") %; \ | |
/if ({handle} == -1) \ | |
/return %; \ | |
/endif %; \ | |
/let lineno=1 %; \ | |
/let line= %; \ | |
/while (tfread({handle}, {line}) != -1) \ | |
/if ({lineno} == {opt_n}) \ | |
/test tfclose({handle}) %; \ | |
$(/browser_command %{line}) %; \ | |
/return %; \ | |
/endif %; \ | |
/test lineno += 1 %; \ | |
/done %; \ | |
/test tfclose({handle}) %; \ | |
/_echo %{opt_n}: Not in the list. %; \ | |
/elseif ({opt_c} != -1) \ | |
/if ({opt_c} < 1) /_echo Don't be gay. %; /return %; /endif %; \ | |
/eval /sys sed -i -e '%{opt_c}d' %{urlfile} %; \ | |
/_echo Ok. %; \ | |
/elseif ({opt_u} != -1) \ | |
$(/browser_command %{opt_u}) %; \ | |
/elseif ({opt_a} != -1) \ | |
/add_new_url %{opt_a} %; \ | |
/_echo Ok. (no status is returned for this) %; \ | |
/elseif ({opt_q} != -1) \ | |
/sys perl -e 'print grep { !\$pseen{\$_}++ } <>' /home/pope/.tfurl > \ | |
/home/pope/.tfutmp 2>/dev/null %; \ | |
/sys mv .tfutmp .tfurl %; \ | |
/elseif ({opt_h} != -1) \ | |
/_echo USAGE: %; \ | |
/_echo /url -h - This message %; \ | |
/_echo /url - Go to the most recently grabbed url %; \ | |
/_echo /url -l - List all grabbed urls %; \ | |
/_echo /url -a<url> - Add a new url to the list by hand %; \ | |
/_echo /url -c<number> - Remove a url from the list (requires sed) %; \ | |
/_echo /url -n<number> - Open browser window to url <n> from list. %; \ | |
/_echo /url -q - Remove duplicates from the url list. %; \ | |
/else \ | |
/if ({lasturl} =~ "") \ | |
/let handle= %; \ | |
/test handle := tfopen({urlfile}, "r") %; \ | |
/if ({handle} == -1) \ | |
/return %; \ | |
/endif %; \ | |
/let line= %;\ | |
/while (tfread({handle}, {line}) != -1) \ | |
/set lasturl {line} %; \ | |
/done %; \ | |
/test tfclose({handle}) %; \ | |
/endif %; \ | |
$(/browser_command %{lasturl}) %; \ | |
/endif | |
; commonly used alias | |
/def urls = /url -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment