Hi,
I modified your original surf.sh because it makes two xprop calls every time
it is invoked, which is unnecessary overhead. I also attach below my own surf2.sh
which implements as minimally as I can figure out how the history functions mentioned
in the last e-mail.
================= surf.sh ==========================
#!/bin/sh
# $1 = $xid
# $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI (what SETPROP sets in config.h)
#
# // replace default setprop with this one
# #define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.sh $1 $0", p,
winid, NULL } }
#
# // fix shift+slash keybinding in spanish keyboard (f.example)
# { MODKEY, GDK_s, spawn, SETPROP("_SURF_FIND") },
# { MODKEY, GDK_b, spawn, SETPROP("_SURF_BMARK") },
# { MODKEY|GDK_SHIFT_MASK, GDK_g, spawn, SETPROP("_SURF_URI_RAW") },
font='-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*'
normbgcolor='#181818'
normfgcolor='#e9e9e9'
selbgcolor='#dd6003'
selfgcolor='#e9e9e9'
bmarks=~/.surf/bookmarks.txt
xid=$1
p=$2
dmenu="dmenu -e $xid -fn $font -nb $normbgcolor -nf $normfgcolor \
-sb $selbgcolor -sf $selfgcolor"
s_get_prop() {
xprop -id $xid $1 | cut -d '"' -f 2
}
s_set_prop() {
[ -n "$2" ] && xprop -id $xid -f $1 8s -set $1 "$2"
}
case "$p" in
"_SURF_FIND")
find="`echo $(s_get_prop _SURF_FIND) | $dmenu -p find:`"
s_set_prop _SURF_FIND "$find"
;;
"_SURF_BMARK")
uri=`s_get_prop _SURF_URI`
grep "$uri" $bmarks >/dev/null 2>&1 || echo "$uri" >> $bmarks
;;
"_SURF_URI_RAW")
uri=`echo $(s_get_prop _SURF_URI) | $dmenu -p "uri:"`
s_set_prop _SURF_URI "$uri"
;;
"_SURF_URI")
sel=`tac $bmarks 2> /dev/null | $dmenu -p "uri [dgtwy*]:"`
[ -z "$sel" ] && exit
opt=$(echo $sel | cut -d ' ' -f 1)
arg=$(echo $sel | cut -d ' ' -f 2-)
case "$opt" in
"d") # del.icio.us
uri="http://del.icio.us/save?url=`s_get_prop _SURF_URI`"
;;
"g") # google for it
uri="http://www.google.com/search?q=$arg"
;;
"t") # tinyurl
uri="http://tinyurl.com/create.php?url=`s_get_prop _SURF_URI`"
;;
"w") # wikipedia
uri="http://wikipedia.org/wiki/$arg"
;;
"y") # youtube
uri="http://www.youtube.com/results?search_query=$arg&aq=f"
;;
*)
uri="$sel"
;;
esac
s_set_prop _SURF_URI "$uri"
;;
*)
echo Unknown xprop
;;
esac
========================================surf2.sh======================
#!/bin/sh
# $1 = $xid
# $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI (what SETPROP sets in config.h)
#
# // replace default setprop with this one
# #define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.sh $1 $0", p,
winid, NULL } }
#
# // fix shift+slash keybinding in spanish keyboard (f.example)
# { MODKEY, GDK_s, spawn, SETPROP("_SURF_FIND") },
# { MODKEY, GDK_b, spawn, SETPROP("_SURF_BMARK") },
# { MODKEY|GDK_SHIFT_MASK, GDK_g, spawn, SETPROP("_SURF_URI_RAW") },
font='-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*'
normbgcolor='#181818'
normfgcolor='#e9e9e9'
selbgcolor='#dd6003'
selfgcolor='#e9e9e9'
bmarks=~/.surf/bookmarks.txt
ffile=~/.surf/find.txt # pjh
xid=$1
p=$2
dmenu="dmenu -e $xid -fn $font -nb $normbgcolor -nf $normfgcolor \
-sb $selbgcolor -sf $selfgcolor"
s_get_prop() {
xprop -id $xid $1 | cut -d '"' -f 2
}
s_set_prop() {
[ -n "$2" ] && xprop -id $xid -f $1 8s -set $1 "$2"
}
case "$p" in
"_SURF_FIND")
#find="`echo $(s_get_prop _SURF_FIND) | $dmenu -p find:`"
find="`tac $ffile 2>/dev/null | $dmenu -p find:`" # pjh
s_set_prop _SURF_FIND "$find"
grep "$find" $ffile >/dev/null 2>&1 || echo "$1" >> $ffile # pjh
;;
"_SURF_BMARK")
uri=`s_get_prop _SURF_URI`
grep "$uri" $bmarks >/dev/null 2>&1 || echo "$uri" >> $bmarks
;;
"_SURF_URI_RAW")
uri=`echo $(s_get_prop _SURF_URI) | $dmenu -p "uri:"`
s_set_prop _SURF_URI "$uri"
;;
"_SURF_URI")
sel=`tac $bmarks 2> /dev/null | $dmenu -p "uri [dgtwy*]:"`
[ -z "$sel" ] && exit
opt=$(echo $sel | cut -d ' ' -f 1)
arg=$(echo $sel | cut -d ' ' -f 2-)
case "$opt" in
"d") # del.icio.us
uri="http://del.icio.us/save?url=`s_get_prop _SURF_URI`"
;;
"g") # google for it
uri="http://www.google.com/search?q=$arg"
;;
"t") # tinyurl
uri="http://tinyurl.com/create.php?url=`s_get_prop _SURF_URI`"
;;
"w") # wikipedia
uri="http://wikipedia.org/wiki/$arg"
;;
"y") # youtube
uri="http://www.youtube.com/results?search_query=$arg&aq=f"
;;
*)
uri="$sel"
;;
esac
xprop -id $xid -f WM_ICON_NAME 8s -set WM_ICON_NAME "" >/dev/null 2>&1
# pjh because surf doesn't sometimes
s_set_prop _SURF_URI "$uri"
name=`xprop -id $xid WM_ICON_NAME | cut -d '"' -f 2` # pjh
while echo $name | grep "[*%\]" >/dev/null 2>&1; do # pjh
name=`xprop -id $xid WM_ICON_NAME | cut -d '"' -f 2` #pjh
done # pjh
if [[ $name != "Error" ]]; then # pjh
grep "$sel" $bmarks >/dev/null 2>&1 || echo "$sel" >> $bmarks
#pjh
fi #pjh
;;
*)
echo Unknown xprop
;;
esac
Peter
--
sic dicit magister P.
http://individual.utoronto.ca/peterjh/
On Fri, 2 Apr 2010, Nibble wrote:
On Fri, 2 Apr 2010 09:32:41 -0400 (EDT)
Peter John Hartman <peterjohnhart...@gmail.com> wrote:
Hi nibbles (and pancake et al):
Hi Peter, (it is *nibble* ;)
Looks even better (once more)! But you still don't store stuff to a
local history file, except when one explicitly bookmarks the page.
Two of the goals of the script, I think, are to:
(1) store all find transactions to a find.history.txt file.
In the last version of the script, only the last keyword is "stored".
From my point of view it is enough in most cases, I think that store
all the searched keywords adds unnecessary complexity.
(2) store all set uri transactions to a history.txt file, provided
they are successful. also, i like storing my set uri transactions
prior to any processing, e.g., store "g foobar" rather than the ugly
looking "http://www.google.com/search?q=foobar".
I've been talking with pancake and neither him nor me will use this
feature, that's because we didn't add it to the script.
Anyway, these features could be useful for other people, so it's almost
sure that surf2.sh will be welcome :)
Best,
Peter
Best regards,
-- nibble