; ; urlgrab.tf ; vega@Sanity's Edge ; october/something/2007 ; ; 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. ; ; Make sure to update the config section for your system before using this! ; ; You may also want to update the regexp to suit your needs. ; ; USAGE: ; /url -h - help message ; /url - go to the most recently grabbed url ; /url -l - list all grabbed urls ; /url -a - add a new url to the list by hand ; /url -c - remove a url from the list (depends on system sed) ; /url -n - open browser window to url from list. ; ; config ; /def browser_command = /quote -0 !export DISPLAY=:0.0;firefox \ $[escape(" &\"*()'[]?", %{1})] > /dev/null 2>&1 %; \ /set urlfile=/home/myhome/.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|cc|edu|au|uk) \ (?:[?/]\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 - add a new url to the list by hand ; /url -c - remove a url from the list (depends on system sed) ; /url -n - open browser window to url from list. /def url = \ /test getopts("hln#c#a:", -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 No negatives. %; /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 No negatives. %; /return %; /endif %; \ /eval /sys sed -i -e '%{opt_c}d' %{urlfile} %; \ /echo Ok. %; \ /elseif (%{opt_a} != -1) \ /add_new_url %{opt_a} %; \ /echo Ok. (no status is returned for this) %; \ /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 - Add a new url to the list by hand %; \ /echo /url -c - Remove a url from the list (requires sed) %; \ /echo /url -n - Open browser window to url from 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