nibble and me cleaned up a bit more my refactored script and
now supports youtube and does not depends on awk, the code
is now much cleaner and easy to ready/modify.
The last script depends on dmenu from mercurial, so it uses
-e $xid to embed.
http://surf.suckless.org/files/bmarks
enjoy :)
btw nibble will probably change the ^G to run $EDITOR to
edit the url. any other idea? feedback?
pancake wrote:
Conceptually looks nice, but the script uses some bashisms and linuxsms and
depends on urlencode.sh which is not distributed with the script. it also
has a race condition in the history file on multiuser environments and it
is possible to steal the history information because of the cp
hack: (while : ; chmod 000 /tmp/history* ; done)
I think I can simplify it a bit and fix these issues:
http://lolcathost.org/b/surf.sh
Some functionalities has changed and some other has been added. actually it
supports:
- bookmarking with tags ^b
- sorted by bookmark date
- autocompletion of bookmarked uris with ^g
- open uri without autocomplete ^G
- fix search keybinding in spanish keyboard ^f (can this be added in
mainstream?)
- uri handlers:
- google (g food)
- wikipedia (w foo bar)
- del.icio.us (d )
- tinyurl (t )
- open url matching tags (h web editor)
it can be improved, but at least it works with no dependencies or linuxisms.
Let me know if you find any issue.
--pancake
On Wed, 31 Mar 2010 13:14:26 -0400 (EDT)
Peter John Hartman <peterjohnhart...@gmail.com> wrote:
Hi Folks,
So, I've cobbled together the attached shell script to do most of what I
want to do with surf, including history, smart prefixes, and bookmarks.
The upshot is that one doesn't need the history patch and the searchengines
patch.
I'd appreciate comments on this, esp.\ with respect to how I can figure
out what the TITLE value is of a new uri. The current technique does
a nasty little loop; and it still sometimes returns odd values for the
TITLE. You can see that in the comments to the code.
In config.h replace the SETPROP line with:
#define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.sh $1 $0",
p, winid, NULL } }
And you also bind:
{ MODKEY, GDK_b, spawn, SETPROP("_SURF_BMARK") },
============= surf.sh ===================================================
#!/bin/sh
# TODO add to surf-start.sh a cleanup routine to get rid of all old entries
# $1 = $xid
# $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI i.e. what SETPROP states in
config.h
function s_add() {
url=$1
name=$2
timestamp=`date +%Y%m%d%H%M%S`
grep "$url" ~/.surf/history >/dev/null || echo -e "$url\t$name\t$timestamp"
>> ~/.surf/history
}
function s_get_uri() {
xid=$1
xprop -id $xid _SURF_URI | cut -d '"' -f 2
}
function s_get_name() {
xid=$1
xprop -id $xid WM_ICON_NAME | cut -d '"' -f 2
}
function s_set_uri() {
xid=$1
newuri=$2
xprop -id $xid -f _SURF_URI 8s -set _SURF_URI "$newuri" 2>/dev/null
>/dev/null
}
xid=$1
p=$2
if [[ $p == "_SURF_FIND" ]]; then
dmenu -b -p ":"
exit;
elif [[ $p == "_SURF_BMARK" ]]; then
cur=`s_get_uri $xid`
name=`s_get_name $xid`
s_add "$cur" "$name"
exit;
else
# display the history PLUS the current uri via dmenu
cur=`s_get_uri $xid`
curname=`s_get_name $xid`
cp ~/.surf/history /tmp/surf.history.$$
echo -e "$cur\t$curname\t$timestamp" >> /tmp/surf.history.$$
selection=`tac /tmp/surf.history.$$ | awk 'BEGIN { FS="\t" } {print $1"
"$2}' | dmenu -b -l 10`
rm -f /tmp/surf.history.$$
# if we hit escape, then exit
if [[ $selection == "" ]]; then
exit;
fi
# post "smart" process
# entries ($selection) will either be:
# gg foobar foo foo2 foo3 i.e. <SMART ABBV><SPACE><VALUE>
# or:
# http://www.google.com/ NAME OF SITE i.e. <URL><SPACE><NAME>
#
# this removes trailing whitespace, ie when there is no name
OPTION=$(echo $selection | sed -e 's/^ *//g;s/ *//g' | awk '{print
$1}')
if [[ $OPTION == "gg" ]]; then
VALUE=$(echo $selection | sed 's/gg //' | urlencode.sh)
URL="http://www.google.com/search?q=$VALUE"
s_set_uri $xid $URL
s_add "$selection" ""
elif [[ $OPTION == "ut" ]]; then
VALUE=$(echo $selection | sed 's/ut //' | urlencode.sh)
URL="http://search2.library.utoronto.ca/UTL/index?N=0&Ntk=Anywhere&Ntt=$VALUE&Ntx=mode%2Bmatchallpartial&Nu=p_work_normalized&Np=1&formName=search_form_simple"
s_set_uri $xid $URL
s_add "$selection" ""
else
# otherwise go to the url they enter
URL=$(echo $selection | awk '{print $1}')
s_set_uri $xid $URL
# NASTY little hack to figure out what the REAL TITLE is.
name="`s_get_name $xid`"
while echo $name | grep "[*%\]"; do
name=`s_get_name $xid`
done
s_add $URL "$name"
fi
fi
Peter Hartman
--
sic dicit magister P.
http://individual.utoronto.ca/peterjh/