From 22c3109e1a26c2eb37e03d3f7bb86079c2e0874c Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 28 Mar 2010 18:19:14 +0200 Subject: emit FORM_ACTIVE, when form element follow.js'ed Due to Uzbl removal it is no longer possible to emit event from js script. So follow.js does not emit FORM_ACTIVE event, when user selects form element using follow.js. Workaround for that is to run follow.js from shell script, set some global variable and next read this variable from shell script. --- examples/config/config | 2 +- examples/data/scripts/follow.js | 10 +++++++++- examples/data/scripts/follow.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 examples/data/scripts/follow.sh (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index de01cf3..29e7d16 100644 --- a/examples/config/config +++ b/examples/config/config @@ -324,7 +324,7 @@ set follow_hint_keys = 0123456789 #set follow_hint_keys = qwerty #set follow_hint_keys = asdfghjkl; #set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234 -@cbind fl* = script @scripts_dir/follow.js '@follow_hint_keys %s' +@cbind ff* = spawn @scripts_dir/follow.sh "%s" # --- Form filler binds --- # This script allows you to configure (per domain) values to fill in form diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index a42447c..9236ed4 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -17,6 +17,7 @@ var doc = document; var win = window; var links = document.links; var forms = document.forms; +var rv = ""; //Make onlick-links "clickable" try { HTMLElement.prototype.click = function() { @@ -131,16 +132,23 @@ function clickElem(item) { item.click(); window.location = item.href; } else if (name == 'INPUT') { - var type = item.getAttribute('type').toUpperCase(); + var type; + try { + type = item.getAttribute('type').toUpperCase(); + } catch(err) { + type = 'TEXT'; + } if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') { item.focus(); item.select(); } else { item.click(); } + rv="XXXFORMELEMENTCLICKEDXXX"; } else if (name == 'TEXTAREA' || name == 'SELECT') { item.focus(); item.select(); + rv="XXXFORMELEMENTCLICKEDXXX"; } else { item.click(); window.location = item.href; diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh new file mode 100644 index 0000000..44a0d55 --- /dev/null +++ b/examples/data/scripts/follow.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +config=$1; +shift +pid=$1; +shift +xid=$1; +shift +fifo=$1; +shift +socket=$1; +shift +url=$1; +shift +title=$1; +shift + +echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:$socket + +# Read variable set by script. If it equals XXXFORMELEMENTCLICKEDXXX emit +# FORM_ACTIVE event +echo 'js rv' \ + | socat - unix-connect:$socket \ + | grep -q XXXINPUTELEMENTCLICKEDXXX \ + && echo 'event FORM_ACTIVE' \ + | socat - unix-connect:$socket -- cgit v1.2.3 From ba451c2ce489fd0b49c825d4ea95b2052c5ba028 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 28 Mar 2010 18:52:05 +0200 Subject: chmod a+x follow.sh --- examples/data/scripts/follow.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 examples/data/scripts/follow.sh (limited to 'examples') diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From 8bd5a87606d54308e666afdc1b83d79d3e42720c Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 28 Mar 2010 20:57:22 +0200 Subject: use same marker in follow.{sh,js}. Pointed out by Paul Tomak , thx. --- examples/data/scripts/follow.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index 44a0d55..76dd1d2 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -21,6 +21,6 @@ echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-c # FORM_ACTIVE event echo 'js rv' \ | socat - unix-connect:$socket \ - | grep -q XXXINPUTELEMENTCLICKEDXXX \ + | grep -q XXXFORMELEMENTCLICKEDXXX \ && echo 'event FORM_ACTIVE' \ | socat - unix-connect:$socket -- cgit v1.2.3 From 007b87d48b647b0bdf4d8bc8bd28796d3cca05d2 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 28 Mar 2010 21:52:50 +0200 Subject: more events from follow script emit FORM_ACTIVE on TEXT, PASSWORD, TEXTAREA and SELECT reset mode on other INPUT elements (checkboxes, radiobuttons etc) Additionaly: does not invoke item.select() on elements. --- examples/data/scripts/follow.js | 7 ++++--- examples/data/scripts/follow.sh | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index 9236ed4..f8c859d 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -138,17 +138,18 @@ function clickElem(item) { } catch(err) { type = 'TEXT'; } - if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') { + if (type == 'TEXT' || type == 'PASSWORD') { item.focus(); item.select(); + rv="XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); + rv="XXXRESET_MODEXXX"; } - rv="XXXFORMELEMENTCLICKEDXXX"; } else if (name == 'TEXTAREA' || name == 'SELECT') { item.focus(); item.select(); - rv="XXXFORMELEMENTCLICKEDXXX"; + rv="XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); window.location = item.href; diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index 76dd1d2..af9e277 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -17,10 +17,17 @@ shift echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:$socket -# Read variable set by script. If it equals XXXFORMELEMENTCLICKEDXXX emit -# FORM_ACTIVE event -echo 'js rv' \ - | socat - unix-connect:$socket \ - | grep -q XXXFORMELEMENTCLICKEDXXX \ +# Read variable set by script. If it equals XXXEMIT_FORM_ACTIVEXXX emit +# FORM_ACTIVE event. If it equals XXXEMIT_ROOT_ACTIVEXXX emit ROOT_ACTIVE +# event. +rv=$(echo 'js rv' | socat - unix-connect:$socket) + +echo $rv \ + | grep -q XXXEMIT_FORM_ACTIVEXXX \ && echo 'event FORM_ACTIVE' \ | socat - unix-connect:$socket + +echo $rv \ + | grep -q XXXRESET_MODEXXX \ + && echo 'set mode =' \ + | socat - unix-connect:$socket -- cgit v1.2.3 From b6117cce525e60aa41f960fd094f535077f2f83c Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sun, 28 Mar 2010 21:54:55 +0200 Subject: reverted fl* keybinding for follow script. ff* was mistake --- examples/config/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 29e7d16..3ab778a 100644 --- a/examples/config/config +++ b/examples/config/config @@ -324,7 +324,7 @@ set follow_hint_keys = 0123456789 #set follow_hint_keys = qwerty #set follow_hint_keys = asdfghjkl; #set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234 -@cbind ff* = spawn @scripts_dir/follow.sh "%s" +@cbind fl* = spawn @scripts_dir/follow.sh "%s" # --- Form filler binds --- # This script allows you to configure (per domain) values to fill in form -- cgit v1.2.3 From 3593d5fcae27ce3d96d3944ee81deab37a1eab77 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Mon, 29 Mar 2010 06:58:36 +0200 Subject: emit FORM_ACTIVE also on --- examples/data/scripts/follow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index f8c859d..763b0d9 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -138,7 +138,7 @@ function clickElem(item) { } catch(err) { type = 'TEXT'; } - if (type == 'TEXT' || type == 'PASSWORD') { + if (type == 'TEXT' || type == 'SEARCH' || type == 'PASSWORD') { item.focus(); item.select(); rv="XXXEMIT_FORM_ACTIVEXXX"; -- cgit v1.2.3 From 7352cd1b1d4ed9f3d98567d21f7bd6f118cc4225 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 18 Apr 2010 17:44:55 -0500 Subject: added userscript in the examples, modified from singpolyma's script --- examples/config/config | 4 ++++ examples/data/scripts/userscript.sh | 40 ++++++++++++++++++++++++++++++++++++ examples/data/scripts/userscripts.sh | 8 ++++++++ 3 files changed, 52 insertions(+) create mode 100755 examples/data/scripts/userscript.sh create mode 100755 examples/data/scripts/userscripts.sh (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index bb5acc6..2fa30a1 100644 --- a/examples/config/config +++ b/examples/config/config @@ -65,6 +65,10 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # Load commit handlers @on_event LOAD_COMMIT @set_status recv + +@on_event LOAD_COMMIT spawn @scripts_dir/userscripts.sh + + # Load finish handlers @on_event LOAD_FINISH @set_status done @on_event LOAD_FINISH spawn @scripts_dir/history.sh diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh new file mode 100755 index 0000000..33a24ae --- /dev/null +++ b/examples/data/scripts/userscript.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +if [ $# = "3" ] +then + fifo="$1" + url="$2" + SCRIPT="$3" +else + fifo="$4" + url="$6" + SCRIPT="$8" +fi + +# Extract metadata chunk +META="`sed -ne '/^\s*\/\/\s*==UserScript==\s*$/,/^\s*\/\/\s*==\/UserScript==\s*$/p' "$SCRIPT"`" +SHOULD_RUN=false # Assume this script will not be included +# Loop over all include rules +for INCLUDE in `echo "$META" | grep "^\s*\/\/\s*@include"`; do + # Munge into grep pattern + INCLUDE="`echo "$INCLUDE" | sed -e 's/^\s*\/\/\s*@include\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" + if echo "$url" | grep -x "$INCLUDE"; then + SHOULD_RUN=true + break + fi +done + +# Loop over all exclude rules +for EXCLUDE in `echo "$META" | grep "^\s*\/\/\s*@exclude"`; do + # Munge into grep pattern + EXCLUDE="`echo "$EXCLUDE" | sed -e 's/^\s*\/\/\s*@exclude\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" + if echo "$url" | grep -x "$EXCLUDE"; then + SHOULD_RUN=false + break + fi +done + +# Run the script +if [ $SHOULD_RUN = true ]; then + echo "script '$SCRIPT'" > "$fifo" +fi diff --git a/examples/data/scripts/userscripts.sh b/examples/data/scripts/userscripts.sh new file mode 100755 index 0000000..8896224 --- /dev/null +++ b/examples/data/scripts/userscripts.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +scripts_dir="$XDG_DATA_HOME/uzbl/userscripts" + +for SCRIPT in $(grep -rlx "\s*//\s*==UserScript==\s*" "$scripts_dir") +do + $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$4" "$6" "$SCRIPT" +done -- cgit v1.2.3 From 733d83d0ada566b0353fd2c305a3838cc2eed131 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 18 Apr 2010 17:50:18 -0500 Subject: commented config line --- examples/config/config | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 2fa30a1..7e1be21 100644 --- a/examples/config/config +++ b/examples/config/config @@ -65,9 +65,8 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # Load commit handlers @on_event LOAD_COMMIT @set_status recv - -@on_event LOAD_COMMIT spawn @scripts_dir/userscripts.sh - +# Userscript support. Add all scripts to $XDG_DATA_HOME/uzbl/userscripts +#@on_event LOAD_COMMIT spawn @scripts_dir/userscripts.sh # Load finish handlers @on_event LOAD_FINISH @set_status done -- cgit v1.2.3 From 6a06bd6706092ccf300fda02726c2066b03721c8 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Sun, 16 May 2010 15:09:52 +0200 Subject: This helper does not require bash, a generic posix shell is fine enough Signed-off-by: Luca Bruno --- examples/data/scripts/load_url_from_bookmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 1e9f9e7..cb13420 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. -- cgit v1.2.3 From 3f33558e48612004b70d0b726f7e5651b6f67ea1 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Sun, 16 May 2010 15:11:12 +0200 Subject: Avoid bash specific syntax in helpers Most of our helpers don't really depend on bash, and work just fine with every system shell. Thus, let's avoid "bashisms" in there to accomodate more bare-bone shells (like dash, see https://wiki.ubuntu.com/DashAsBinSh ) Signed-off-by: Luca Bruno --- examples/config/config | 6 +++--- examples/data/scripts/formfiller.sh | 5 +++-- examples/data/scripts/insert_bookmark.sh | 4 ++-- examples/data/scripts/instance-select-wmii.sh | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index cff13ad..6c4b0fb 100644 --- a/examples/config/config +++ b/examples/config/config @@ -251,8 +251,8 @@ set ebind = @mode_bind global,-insert @cbind gh = uri http://www.uzbl.org # Yanking & pasting binds -@cbind yu = sh 'echo -n $6 | xclip' -@cbind yy = sh 'echo -n $7 | xclip' +@cbind yu = sh 'printf $6 | xclip' +@cbind yy = sh 'printf $7 | xclip' # Go the page from primary selection @cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' @@ -264,7 +264,7 @@ set ebind = @mode_bind global,-insert @bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > $4' # Bookmark inserting binds -@cbind b_ = sh 'echo -e "$6 %s" >> $XDG_DATA_HOME/uzbl/bookmarks' +@cbind b_ = sh 'echo `printf "$6 %s"` >> $XDG_DATA_HOME/uzbl/bookmarks' # Or use a script to insert a bookmark. @cbind B = spawn @scripts_dir/insert_bookmark.sh diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 69eca17..deccea2 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -51,6 +51,7 @@ else fi PROMPT="Choose profile" +RAND=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c 1-5) MODELINE="> vim:ft=formfiller" keydir=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/dforms @@ -159,7 +160,7 @@ then then menu=`cat $keydir/$domain| \ sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p'` - option=`echo -e -n "$menu"| dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}"` + option=`printf "$menu"| dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}"` fi # Remove comments @@ -210,7 +211,7 @@ else if [ "$action" = 'new' -o "$action" = 'add' ] then [ "$action" = 'new' ] && echo "$MODELINE" > $keydir/$domain - echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $keydir/$domain + echo "!profile=NAME_THIS_PROFILE$RAND" >> $keydir/$domain # # 2. and 3. line (tr -d and sed) are because, on gmail login for example, # tag is splited into lines diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index d0ec84e..2ec5975 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -3,7 +3,7 @@ [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/uzbl" ] || exit 1 file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks -which zenity &>/dev/null || exit 2 +which zenity 2>&1 >/dev/null || exit 2 url=$6 # replace tabs, they are pointless in titles and we want to use tabs as delimiter. title=$(echo "$7" | sed 's/\t/ /') @@ -14,5 +14,5 @@ url=`echo $entry | awk '{print $1}'` # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags echo "$entry" >/dev/null #for some reason we need this.. don't ask me why -echo -e "$entry" >> $file +printf "$entry\n" >> $file true diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index fdd27e6..64b859e 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -20,7 +20,7 @@ else DMENU="dmenu -i" fi -if [ "$1" == 'list' ] +if [ "$1" = 'list' ] then list= # get window id's of uzbl clients. we could also get the label in one shot but it's pretty tricky @@ -29,9 +29,9 @@ then label=$(wmiir read /client/$i/label) list="$list$i : $label\n" done - window=$(echo -e "$list" | $DMENU $COLORS | cut -d ' ' -f1) + window=$(printf "$list\n" | $DMENU $COLORS | cut -d ' ' -f1) wmiir xwrite /tag/sel/ctl "select client $window" -elif [ "$1" == 'next' ] +elif [ "$1" = 'next' ] then current=$(wmiir read /client/sel/ctl | head -n 1) # find the next uzbl window and focus it @@ -40,7 +40,7 @@ then then wmiir xwrite /tag/sel/ctl "select client $next" fi -elif [ "$1" == 'prev' ] +elif [ "$1" = 'prev' ] then current=$(wmiir read /client/sel/ctl | head -n 1) prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2) -- cgit v1.2.3 From 528da21727fba819d8eef4251d22d91de2c111c9 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Tue, 8 Jun 2010 16:04:31 +0200 Subject: simplifiy follow.sh. Now it executes less processes and works a bti faster. --- examples/data/scripts/follow.js | 10 +++++----- examples/data/scripts/follow.sh | 20 ++++---------------- 2 files changed, 9 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index 763b0d9..77c40cd 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -17,7 +17,6 @@ var doc = document; var win = window; var links = document.links; var forms = document.forms; -var rv = ""; //Make onlick-links "clickable" try { HTMLElement.prototype.click = function() { @@ -131,6 +130,7 @@ function clickElem(item) { if (name == 'A') { item.click(); window.location = item.href; + return "XXXRESET_MODEXXX"; } else if (name == 'INPUT') { var type; try { @@ -141,15 +141,15 @@ function clickElem(item) { if (type == 'TEXT' || type == 'SEARCH' || type == 'PASSWORD') { item.focus(); item.select(); - rv="XXXEMIT_FORM_ACTIVEXXX"; + return "XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); - rv="XXXRESET_MODEXXX"; + return "XXXRESET_MODEXXX"; } } else if (name == 'TEXTAREA' || name == 'SELECT') { item.focus(); item.select(); - rv="XXXEMIT_FORM_ACTIVEXXX"; + return "XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); window.location = item.href; @@ -251,7 +251,7 @@ function followLinks(follow) { var oldDiv = doc.getElementById(uzbldivid); var leftover = [[], []]; if (s.length == len && linknr < elems[0].length && linknr >= 0) { - clickElem(elems[0][linknr]); + return clickElem(elems[0][linknr]); } else { for (var j = 0; j < elems[0].length; j++) { var b = true; diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index af9e277..ba59575 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -15,19 +15,7 @@ shift title=$1; shift -echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:$socket - -# Read variable set by script. If it equals XXXEMIT_FORM_ACTIVEXXX emit -# FORM_ACTIVE event. If it equals XXXEMIT_ROOT_ACTIVEXXX emit ROOT_ACTIVE -# event. -rv=$(echo 'js rv' | socat - unix-connect:$socket) - -echo $rv \ - | grep -q XXXEMIT_FORM_ACTIVEXXX \ - && echo 'event FORM_ACTIVE' \ - | socat - unix-connect:$socket - -echo $rv \ - | grep -q XXXRESET_MODEXXX \ - && echo 'set mode =' \ - | socat - unix-connect:$socket +case $(echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:$socket) in + *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' | socat - unix-connect:$socket ;; + *XXXRESET_MODEXXX*) echo 'set mode=' | socat - unix-connect:$socket ;; +esac -- cgit v1.2.3 From f9922ae0f9b05afb3f485a60f57744f61fda8c40 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Tue, 8 Jun 2010 16:31:50 +0200 Subject: Resurect go_input script. --- examples/config/config | 1 + examples/data/scripts/go_input.js | 27 +++++++++++++++++++++++++++ examples/data/scripts/go_input.sh | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 examples/data/scripts/go_input.js create mode 100755 examples/data/scripts/go_input.sh (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 3ab778a..5617e2e 100644 --- a/examples/config/config +++ b/examples/config/config @@ -325,6 +325,7 @@ set follow_hint_keys = 0123456789 #set follow_hint_keys = asdfghjkl; #set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234 @cbind fl* = spawn @scripts_dir/follow.sh "%s" +@cbind gi = spawn @scripts_dir/go_input.sh # --- Form filler binds --- # This script allows you to configure (per domain) values to fill in form diff --git a/examples/data/scripts/go_input.js b/examples/data/scripts/go_input.js new file mode 100644 index 0000000..557671f --- /dev/null +++ b/examples/data/scripts/go_input.js @@ -0,0 +1,27 @@ +var elements = document.querySelectorAll("textarea, input" + [ + ":not([type='button'])", + ":not([type='checkbox'])", + ":not([type='hidden'])", + ":not([type='image'])", + ":not([type='radio'])", + ":not([type='reset'])", + ":not([type='submit'])"].join("")); +function gi() { + if (elements) { + var el, i = 0; + while((el = elements[i++])) { + var style=getComputedStyle(el, null); + if (style.display !== 'none' && style.visibility === 'visible') { + if (el.type === "file") { + el.click(); + } + else { + el.focus(); + } + return "XXXEMIT_FORM_ACTIVEXXX"; + } + } + } +} + +gi(); diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh new file mode 100755 index 0000000..c873dd8 --- /dev/null +++ b/examples/data/scripts/go_input.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +config=$1; +shift +pid=$1; +shift +xid=$1; +shift +fifo=$1; +shift +socket=$1; +shift +url=$1; +shift +title=$1; +shift + +case $(echo 'script @scripts_dir/go_input.js' | socat - unix-connect:$socket) in + *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' | socat - unix-connect:$socket ;; +esac -- cgit v1.2.3 From da394f15e53e010186348a06f35fd64a6adbabc0 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Fri, 13 Aug 2010 11:53:54 +0200 Subject: Typo in event-manager online help. Spotted by from #uzbl, thanks. --- examples/data/scripts/uzbl-event-manager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/uzbl-event-manager b/examples/data/scripts/uzbl-event-manager index ab13fbb..8ad3af7 100755 --- a/examples/data/scripts/uzbl-event-manager +++ b/examples/data/scripts/uzbl-event-manager @@ -825,7 +825,7 @@ if __name__ == "__main__": add('-n', '--no-daemon', dest='daemon_mode', action='store_false', default=True, - help='daemonize the process') + help='do not daemonize the process') add('-a', '--auto-close', dest='auto_close', action='store_true', default=False, -- cgit v1.2.3 From 86729383c1aa931b0793118eb5853955583e9391 Mon Sep 17 00:00:00 2001 From: Gustavo Chaín Date: Wed, 25 Aug 2010 17:41:47 +0200 Subject: add newbg command, to open a new tab in the background --- AUTHORS | 1 + examples/data/scripts/uzbl-tabbed | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'examples') diff --git a/AUTHORS b/AUTHORS index 2ed9117..3b3e241 100644 --- a/AUTHORS +++ b/AUTHORS @@ -39,6 +39,7 @@ In alphabetical order: Dmytro Milinevskyy - uzbl-tabbed useability patches Dusan Popovic (dusanx) - many contributions to early uzbl Evgeny Grablyk - libsoup settings + Gustavo Chaín - newbg command Gregor Uhlenheuer (kongo2002) - uzbl vim syntax & related files Helmut Grohne (helmut) - move void **ptr to union, various fixes Henri Kemppainen (DuClare) - many contributions, mostly old handler code diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed index 5bf802a..42837d3 100755 --- a/examples/data/scripts/uzbl-tabbed +++ b/examples/data/scripts/uzbl-tabbed @@ -847,6 +847,8 @@ class UzblTabbed: # Commands ( [] = optional, {} = required ) # new [uri] # open new tab and head to optional uri. + # newbg [uri] + # open a new tab in the background # close [tab-num] # close current tab or close via tab id. # next [n-tabs] @@ -875,6 +877,12 @@ class UzblTabbed: else: self.new_tab() + elif cmd[0] == "newbg": + if len(cmd) == 2: + self.new_tab(cmd[1], switch=False) + else: + self.new_tab(switch=False) + elif cmd[0] == "newfromclip": uri = subprocess.Popen(['xclip','-selection','clipboard','-o'],\ stdout=subprocess.PIPE).communicate()[0] -- cgit v1.2.3 From d151e7038d94270cbfb742eebc3a4a2a7a95265f Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Thu, 30 Sep 2010 09:51:10 -0600 Subject: uzbl-cookie-daemon: maintain persistent connections to uzbl instances --- examples/data/scripts/uzbl-cookie-daemon | 44 ++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/uzbl-cookie-daemon b/examples/data/scripts/uzbl-cookie-daemon index ed88de4..0b9bef9 100755 --- a/examples/data/scripts/uzbl-cookie-daemon +++ b/examples/data/scripts/uzbl-cookie-daemon @@ -436,18 +436,26 @@ class CookieMonster: daemon_timeout = config['daemon_timeout'] echo("listening on %r" % config['cookie_socket']) + connections = [] + while self._running: # This line tells the socket how many pending incoming connections # to enqueue at once. Raising this number may or may not increase # performance. self.server_socket.listen(1) - if bool(select.select([self.server_socket], [], [], 1)[0]): - client_socket, _ = self.server_socket.accept() - self.handle_request(client_socket) + r, w, x = select.select([self.server_socket]+connections, [], [], 1) + + for socket in r: + if self.server_socket == socket: + client_socket, _ = socket.accept() + connections.append(client_socket) + else: + if not self.handle_request(socket): + # connection was closed, forget about the client socket + connections.remove(socket) + self.last_request = time.time() - client_socket.close() - continue if daemon_timeout: # Checks if the daemon has been idling for too long. @@ -462,7 +470,7 @@ class CookieMonster: # Receive cookie request from client. data = client_socket.recv(8192) if not data: - return + return False # Cookie argument list in packet is null separated. argv = data.split("\0") @@ -471,17 +479,17 @@ class CookieMonster: # Catch the EXIT command sent to kill running daemons. if action == "EXIT": self._running = False - return + return False # Catch whitelist RELOAD command. elif action == "RELOAD": self.reload_whitelist() - return + return True # Return if command unknown. elif action not in ['GET', 'PUT']: error("unknown command %r." % argv) - return + return True # Determine whether or not to print cookie data to terminal. print_cookie = (config['verbose'] and not config['daemon_mode']) @@ -499,13 +507,14 @@ class CookieMonster: req = urllib2.Request(uri) if action == "GET": - self.jar.add_cookie_header(req) - if req.has_header('Cookie'): - cookie = req.get_header('Cookie') - client_socket.send(cookie) - if print_cookie: - print cookie - + self.jar._policy._now = self._now = int(time.time()) + cookies = self.jar._cookies_for_request(req) + attrs = self.jar._cookie_attrs(cookies) + if attrs: + cookie = "; ".join(attrs) + client_socket.send(cookie) + if print_cookie: + print cookie else: client_socket.send("\0") @@ -515,10 +524,13 @@ class CookieMonster: print cookie self.put_cookie(req, cookie) + client_socket.send("\0") if print_cookie: print + return True + def put_cookie(self, req, cookie=None): '''Put a cookie in the cookie jar.''' -- cgit v1.2.3 From 32aabff645692e78e2ef2c438d11ce2fafac9b91 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 09:52:44 -0400 Subject: Reorder Bnd style to match others --- examples/config/config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index b6d9fe3..81aa464 100644 --- a/examples/config/config +++ b/examples/config/config @@ -353,13 +353,13 @@ set stack = @mode_config stack @insert modcmd_updates = 0 # Multi-stage-binding mode config. -@stack keycmd_events = 1 -@stack modcmd_updates = 1 -@stack forward_keys = 0 @stack keycmd_style = foreground="red" -@stack prompt_style = foreground="#888" weight="light" @stack status_background = #202020 @stack mode_indicator = Bnd +@stack prompt_style = foreground="#888" weight="light" +@stack keycmd_events = 1 +@stack modcmd_updates = 1 +@stack forward_keys = 0 set default_mode = command -- cgit v1.2.3 From b9cc0b3e0a9ed7f5ce1181e94cf813544011547e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 10:07:26 -0400 Subject: Put `then' on the same line as `if' --- examples/data/scripts/download.sh | 3 +-- examples/data/scripts/formfiller.sh | 21 +++++++-------------- examples/data/scripts/instance-select-wmii.sh | 21 +++++++-------------- examples/data/scripts/load_url_from_bookmarks.sh | 3 +-- examples/data/scripts/load_url_from_history.sh | 3 +-- 5 files changed, 17 insertions(+), 34 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index f6d34e9..0f051db 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -14,8 +14,7 @@ export http_proxy test "x$url" = "x" && { echo "you must supply a url! ($url)"; exit 1; } # only changes the dir for the $get sub process -if echo "$url" | grep -E '.*\.torrent' >/dev/null; -then +if echo "$url" | grep -E '.*\.torrent' >/dev/null; then ( cd "$dest"; $GET "$url") else ( cd "$dest"; $GET "$url") diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 69eca17..2801262 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -43,8 +43,7 @@ NF="#4e7093" SB="#003d7c" SF="#3a9bff" -if [ "`dmenu --help 2>&1| grep lines`x" != "x" ] -then +if [ "`dmenu --help 2>&1| grep lines`x" != "x" ]; then LINES=" -l 3 " else LINES="" @@ -87,12 +86,10 @@ action=$1 domain=$(echo $url | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') -if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ] -then +if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ]; then action="new" [ -e "$keydir/$domain" ] && action="load" -elif [ "$action" = 'edit' ] && [ ! -e "$keydir/$domain" ] -then +elif [ "$action" = 'edit' ] && [ ! -e "$keydir/$domain" ]; then action="new" fi @@ -152,11 +149,9 @@ insertFunction="function insert(fname, ftype, fvalue, fchecked) { \ } \ }; " -if [ "$action" = 'load' ] -then +if [ "$action" = 'load' ]; then [ -e $keydir/$domain ] || exit 2 - if [ `cat $keydir/$domain|grep "!profile"|wc -l` -gt 1 ] - then + if [ `cat $keydir/$domain|grep "!profile"|wc -l` -gt 1 ]; then menu=`cat $keydir/$domain| \ sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p'` option=`echo -e -n "$menu"| dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}"` @@ -179,8 +174,7 @@ then printf '%s\n' "${fields}" | \ sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \ sed -e 's/@/\\@/g' > $fifo -elif [ "$action" = "once" ] -then +elif [ "$action" = "once" ]; then tmpfile=`mktemp` printf 'js %s dump(); \n' "$dumpFunction" | \ socat - unix-connect:$socket | \ @@ -207,8 +201,7 @@ then sed -e 's/@/\\@/g' > $fifo rm -f $tmpfile else - if [ "$action" = 'new' -o "$action" = 'add' ] - then + if [ "$action" = 'new' -o "$action" = 'add' ]; then [ "$action" = 'new' ] && echo "$MODELINE" > $keydir/$domain echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $keydir/$domain # diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index fdd27e6..1340351 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -13,39 +13,32 @@ COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]' -then +if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch else DMENU="dmenu -i" fi -if [ "$1" == 'list' ] -then +if [ "$1" == 'list' ]; then list= # get window id's of uzbl clients. we could also get the label in one shot but it's pretty tricky - for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2) - do + for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2); do label=$(wmiir read /client/$i/label) list="$list$i : $label\n" done window=$(echo -e "$list" | $DMENU $COLORS | cut -d ' ' -f1) wmiir xwrite /tag/sel/ctl "select client $window" -elif [ "$1" == 'next' ] -then +elif [ "$1" == 'next' ]; then current=$(wmiir read /client/sel/ctl | head -n 1) # find the next uzbl window and focus it next=$(wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f2) - if [ x"$next" != "x" ] - then + if [ x"$next" != "x" ]; then wmiir xwrite /tag/sel/ctl "select client $next" fi -elif [ "$1" == 'prev' ] -then +elif [ "$1" == 'prev' ]; then current=$(wmiir read /client/sel/ctl | head -n 1) prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2) - if [ x"$prev" != "x" ] - then + if [ x"$prev" != "x" ]; then wmiir xwrite /tag/sel/ctl "select client $prev" fi else diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 1e9f9e7..569f2bf 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -5,8 +5,7 @@ file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks [ -r "$file" ] || exit COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]' -then +if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # show tags as well goto=`$DMENU $COLORS < $file | awk '{print $1}'` diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 62e02ac..bec6258 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -6,8 +6,7 @@ history_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history # choose from all entries, sorted and uniqued # goto=`awk '{print $3}' $history_file | sort -u | dmenu -i` COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; -then +if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # choose an item in reverse order, showing also the date and page titles # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. -- cgit v1.2.3 From 1c8635db3838f613e400a5ef8897f7853e260276 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 10:09:09 -0400 Subject: Use $() over `` --- examples/data/scripts/formfiller.sh | 22 +++++++++++----------- examples/data/scripts/history.sh | 4 ++-- examples/data/scripts/insert_bookmark.sh | 4 ++-- examples/data/scripts/load_url_from_bookmarks.sh | 4 ++-- examples/data/scripts/load_url_from_history.sh | 10 +++++----- examples/data/scripts/session.sh | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 2801262..564bf82 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -43,7 +43,7 @@ NF="#4e7093" SB="#003d7c" SF="#3a9bff" -if [ "`dmenu --help 2>&1| grep lines`x" != "x" ]; then +if [ "$(dmenu --help 2>&1 | grep lines)x" != "x" ]; then LINES=" -l 3 " else LINES="" @@ -54,7 +54,7 @@ MODELINE="> vim:ft=formfiller" keydir=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/dforms -[ -d "`dirname $keydir`" ] || exit 1 +[ -d "$(dirname $keydir)" ] || exit 1 [ -d "$keydir" ] || mkdir "$keydir" editor="${VISUAL}" @@ -151,23 +151,23 @@ insertFunction="function insert(fname, ftype, fvalue, fchecked) { \ if [ "$action" = 'load' ]; then [ -e $keydir/$domain ] || exit 2 - if [ `cat $keydir/$domain|grep "!profile"|wc -l` -gt 1 ]; then - menu=`cat $keydir/$domain| \ - sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p'` - option=`echo -e -n "$menu"| dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}"` + if [ $(cat $keydir/$domain | grep "!profile" | wc -l) -gt 1 ]; then + menu=$(cat $keydir/$domain | \ + sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p') + option=$(echo -e -n "$menu" | dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}") fi # Remove comments sed '/^>/d' -i $tmpfile sed 's/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):\(off\|no\|false\|unchecked\|0\|$\)/\1{\2}(\3):0/I;s/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[^0]\+/\1{\2}(\3):1/I' -i $keydir/$domain - fields=`cat $keydir/$domain | \ + fields=$(cat $keydir/$domain | \ sed -n "/^!profile=${option}/,/^!profile=/p" | \ sed '/^!profile=/d' | \ sed 's/^\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):/%{>\1\2):<}%/' | \ sed 's/^\(.\+\)$/<{br}>\1/' | \ tr -d '\n' | \ - sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g'` + sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g') printf '%s\n' "${fields}" | \ sed -n -e "s/\([^(]\+\)(\(password\|text\|search\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \ sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $fifo @@ -175,7 +175,7 @@ if [ "$action" = 'load' ]; then sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \ sed -e 's/@/\\@/g' > $fifo elif [ "$action" = "once" ]; then - tmpfile=`mktemp` + tmpfile=$(mktemp) printf 'js %s dump(); \n' "$dumpFunction" | \ socat - unix-connect:$socket | \ sed -n '/^[^(]\+([^)]\+):/p' > $tmpfile @@ -188,11 +188,11 @@ elif [ "$action" = "once" ]; then sed '/^>/d' -i $tmpfile sed 's/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):\(off\|no\|false\|unchecked\|0\|$\)/\1{\2}(\3):0/I;s/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[^0]\+/\1{\2}(\3):1/I' -i $tmpfile - fields=`cat $tmpfile | \ + fields=$(cat $tmpfile | \ sed 's/^\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):/%{>\1\2):<}%/' | \ sed 's/^\(.\+\)$/<{br}>\1/' | \ tr -d '\n' | \ - sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g'` + sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g') printf '%s\n' "${fields}" | \ sed -n -e "s/\([^(]\+\)(\(password\|text\|search\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \ sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $fifo diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index 7c83aa6..be5fd34 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -1,5 +1,5 @@ #!/bin/sh file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history -[ -d `dirname $file` ] || exit 1 -echo `date +'%Y-%m-%d %H:%M:%S'`" $6 $7" >> $file +[ -d $(dirname $file) ] || exit 1 +echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $file diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index d0ec84e..4d29ad6 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -7,10 +7,10 @@ which zenity &>/dev/null || exit 2 url=$6 # replace tabs, they are pointless in titles and we want to use tabs as delimiter. title=$(echo "$7" | sed 's/\t/ /') -entry=`zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$url $title\t"` +entry=$(zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$url $title\t") exitstatus=$? if [ $exitstatus -ne 0 ]; then exit $exitstatus; fi -url=`echo $entry | awk '{print $1}'` +url=$(echo $entry | awk '{print $1}') # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags echo "$entry" >/dev/null #for some reason we need this.. don't ask me why diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 569f2bf..3134407 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -8,11 +8,11 @@ COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # show tags as well - goto=`$DMENU $COLORS < $file | awk '{print $1}'` + goto=$($DMENU $COLORS < $file | awk '{print $1}') else DMENU="dmenu -i" # because they are all after each other, just show the url, not their tags. - goto=`awk '{print $1}' $file | $DMENU $COLORS` + goto=$(awk '{print $1}' $file | $DMENU $COLORS) fi #[ -n "$goto" ] && echo "uri $goto" > $4 diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index bec6258..5156eee 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -4,19 +4,19 @@ history_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history [ -r "$history_file" ] || exit 1 # choose from all entries, sorted and uniqued -# goto=`awk '{print $3}' $history_file | sort -u | dmenu -i` +# goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # choose an item in reverse order, showing also the date and page titles # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. - goto=`tac $history_file | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}'` + goto=$(tac $history_file | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') else DMENU="dmenu -i" # choose from all entries (no date or title), the first one being current url, and after that all others, sorted and uniqued, in ascending order - current=`tail -n 1 $history_file | awk '{print $3}'`; - goto=`(echo $current; awk '{print $3}' $history_file | grep -v "^$current\$" \ - | sort -u) | $DMENU $COLORS` + current=$(tail -n 1 $history_file | awk '{print $3}'); + goto=$((echo $current; awk '{print $3}' $history_file | grep -v "^$current\$" \ + | sort -u) | $DMENU $COLORS) fi [ -n "$goto" ] && echo "uri $goto" > $4 diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 1059b5e..acd6934 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -26,7 +26,7 @@ fi case $act in "launch" ) - urls=`cat $sessionfile` + urls=$(cat $sessionfile) if [ "$urls." = "." ]; then $UZBL else -- cgit v1.2.3 From aef2bd5944ea23b9bf3ec58460e13f22f792dd44 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:12:56 -0400 Subject: Factor out dmenu functionality --- examples/data/scripts/util/dmenu.sh | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/data/scripts/util/dmenu.sh (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh new file mode 100644 index 0000000..3f307f2 --- /dev/null +++ b/examples/data/scripts/util/dmenu.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# dmenu setup + +case "$DMENU_SCHEME" in + # wmii + "wmii" ) + NB="#303030" + NF="khaki" + SB="#ccffaa" + SF="#303030" + ;; + # Formfiller + "formfiller" ) + NB="#0f0f0f" + NF="4e7093" + SB="#003d7c" + SF="#3a9bff" + ;; + # Bookmarks + "bookmarks" ) + NB="#303030" + NF="khaki" + SB="#ccffaa" + SF="#303030" + ;; + # History + "history" ) + NB="#303030" + NF="khaki" + SB="#ccffaa" + SF="#303030" + ;; + # Default + * ) + NB="#303030" + NF="khaki" + SB="#ccffaa" + SF="#303030" + ;; +esac + +# Default arguments +if [ "x$DMENU_ARGS" = "x" ]; then + DMENU_ARGS="-i" +fi + +# Set the prompt if wanted +if [ ! "x$DMENU_PROMPT" = "x" ]; then + DMENU_ARGS="$DMENU_ARGS -p $DMENU_PROMPT" +fi + +# Detect the xmms patch +if dmenu --help 2>&1 | grep -q '\[-xs\]'; then + DMENU_ARGS="$DMENU_ARGS -xs" + DMENU_HAS_XMMS=1 +fi + +# Detect the vertical patch +if dmenu --help 2>&1 | grep -q '\[-l lines\]'; then + # Default to 10 lines + if [ "x$DMENU_LINES" = "x" ]; then + DMENU_LINES=10 + fi + + DMENU_ARGS="$DMENU_ARGS -l $DMENU_LINES" + DMENU_HAS_VERTICAL=1 + + # Detect the resize patch + if dmenu --help 2>&1 | grep -q '\[-rs\]'; then + DMENU_ARGS="$DMENU_ARGS -rs" + fi +fi + +DMENU="dmenu $DMENU_ARGS -nb $NB -nf $NF -sb $SB -sf $SF" -- cgit v1.2.3 From 8526a0dd73661ae0a5d1cf950ea5e5f63b5b08c5 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:13:17 -0400 Subject: Add uzbl directory and file discovery --- examples/data/scripts/util/uzbl-dir.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/data/scripts/util/uzbl-dir.sh (limited to 'examples') diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh new file mode 100644 index 0000000..01fb469 --- /dev/null +++ b/examples/data/scripts/util/uzbl-dir.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Common directories and files used in scripts + +# Common things first +UZBL_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl +UZBL_CONFIG_DIR=${XDG_CONFIG_DIR:-$HOME/.config}/uzbl +UZBL_FIFO_DIR=/tmp + +# Directories +UZBL_DOWNLOAD_DIR=${XDG_DOWNLOAD_DIR:-$HOME} +UZBL_FORMS_DIR=$UZBL_DATA_DIR/dforms + +# Data files +UZBL_CONFIG_FILE=$UZBL_CONFIG_DIR/config +UZBL_COOKIE_FILE=$UZBL_DATA_DIR/cookies.txt +UZBL_BOOKMARKS_FILE=$UZBL_DATA_DIR/bookmarks +UZBL_HISTORY_FILE=$UZBL_DATA_DIR/history +UZBL_SESSION_FILE=$UZBL_DATA_DIR/browser-session -- cgit v1.2.3 From 6229a4eff9a4e9ac38c790d37ac05fd2ea0a6a7b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:11:13 -0400 Subject: Add editor utility script --- examples/data/scripts/util/editor.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/data/scripts/util/editor.sh (limited to 'examples') diff --git a/examples/data/scripts/util/editor.sh b/examples/data/scripts/util/editor.sh new file mode 100644 index 0000000..a152ebd --- /dev/null +++ b/examples/data/scripts/util/editor.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Editor selection + +if [ "x$VTERM" = "x" ]; then + VTERM="xterm" +fi + +UZBL_EDITOR="$VISUAL" +if [ -z "$UZBL_EDITOR" ]; then + if [ -z "$EDITOR" ]; then + UZBL_EDITOR="$VTERM -e vim" + else + UZBL_EDITOR="$VTERM -e $EDITOR" + fi +fi -- cgit v1.2.3 From ea9290192f06b61a88538d6f646fec3aa7d405ce Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:11:30 -0400 Subject: Add script to manage common uzbl arguments --- examples/data/scripts/util/uzbl-args.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/data/scripts/util/uzbl-args.sh (limited to 'examples') diff --git a/examples/data/scripts/util/uzbl-args.sh b/examples/data/scripts/util/uzbl-args.sh new file mode 100644 index 0000000..7a3dbe5 --- /dev/null +++ b/examples/data/scripts/util/uzbl-args.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Arguments from uzbl + +UZBL_CONFIG=$1 +shift +UZBL_PID=$1 +shift +UZBL_XID=$1 +shift +UZBL_FIFO=$1 +shift +UZBL_SOCKET=$1 +shift +UZBL_URL=$1 +shift +UZBL_TITLE=$1 +shift -- cgit v1.2.3 From c4f026cb42b016193007d90447e6ccb9438c818a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:13:52 -0400 Subject: PEP8 auth.py --- examples/data/scripts/auth.py | 68 +++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py index 4feb90b..9c1b4fc 100755 --- a/examples/data/scripts/auth.py +++ b/examples/data/scripts/auth.py @@ -4,50 +4,50 @@ import gtk import sys def responseToDialog(entry, dialog, response): - dialog.response(response) + dialog.response(response) def getText(authInfo, authHost, authRealm): - dialog = gtk.MessageDialog( - None, - gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, - gtk.MESSAGE_QUESTION, - gtk.BUTTONS_OK_CANCEL, - None) - dialog.set_markup('%s at %s' % (authRealm, authHost)) + dialog = gtk.MessageDialog( + None, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, + gtk.MESSAGE_QUESTION, + gtk.BUTTONS_OK_CANCEL, + None) + dialog.set_markup('%s at %s' % (authRealm, authHost)) - login = gtk.Entry() - password = gtk.Entry() - password.set_visibility(False) + login = gtk.Entry() + password = gtk.Entry() + password.set_visibility(False) - login.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) - password.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) + login.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) + password.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) - hbox = gtk.HBox(); + hbox = gtk.HBox(); - vbox_entries = gtk.VBox(); - vbox_labels = gtk.VBox(); + vbox_entries = gtk.VBox(); + vbox_labels = gtk.VBox(); - vbox_labels.pack_start(gtk.Label("Login:"), False, 5, 5) - vbox_labels.pack_end(gtk.Label("Password:"), False, 5, 5) + vbox_labels.pack_start(gtk.Label("Login:"), False, 5, 5) + vbox_labels.pack_end(gtk.Label("Password:"), False, 5, 5) - vbox_entries.pack_start(login) - vbox_entries.pack_end(password) + vbox_entries.pack_start(login) + vbox_entries.pack_end(password) - dialog.format_secondary_markup("Please enter username and password:") - hbox.pack_start(vbox_labels, True, True, 0) - hbox.pack_end(vbox_entries, True, True, 0) + dialog.format_secondary_markup("Please enter username and password:") + hbox.pack_start(vbox_labels, True, True, 0) + hbox.pack_end(vbox_entries, True, True, 0) - dialog.vbox.pack_start(hbox) - dialog.show_all() - rv = dialog.run() + dialog.vbox.pack_start(hbox) + dialog.show_all() + rv = dialog.run() - output = login.get_text() + "\n" + password.get_text() - dialog.destroy() - return rv, output + output = login.get_text() + "\n" + password.get_text() + dialog.destroy() + return rv, output if __name__ == '__main__': - rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10]) - if (rv == gtk.RESPONSE_OK): - print output; - else: - exit(1) + rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10]) + if (rv == gtk.RESPONSE_OK): + print output; + else: + exit(1) -- cgit v1.2.3 From f1e85d8f962510a667e765b48c979773bb5ea459 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:14:08 -0400 Subject: Make indentation in follow.js uniform --- examples/data/scripts/follow.js | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index a42447c..bcceb74 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -193,38 +193,38 @@ function reDrawHints(elems, chars) { // pass: number of keys // returns: key length function labelLength(n) { - var oldn = n; - var keylen = 0; - if(n < 2) { - return 1; - } - n -= 1; // our highest key will be n-1 - while(n) { - keylen += 1; - n = Math.floor(n / charset.length); - } - return keylen; + var oldn = n; + var keylen = 0; + if(n < 2) { + return 1; + } + n -= 1; // our highest key will be n-1 + while(n) { + keylen += 1; + n = Math.floor(n / charset.length); + } + return keylen; } // pass: number // returns: label function intToLabel(n) { - var label = ''; - do { - label = charset.charAt(n % charset.length) + label; - n = Math.floor(n / charset.length); - } while(n); - return label; + var label = ''; + do { + label = charset.charAt(n % charset.length) + label; + n = Math.floor(n / charset.length); + } while(n); + return label; } // pass: label // returns: number function labelToInt(label) { - var n = 0; - var i; - for(i = 0; i < label.length; ++i) { - n *= charset.length; - n += charset.indexOf(label[i]); - } - return n; + var n = 0; + var i; + for(i = 0; i < label.length; ++i) { + n *= charset.length; + n += charset.indexOf(label[i]); + } + return n; } //Put it all together function followLinks(follow) { -- cgit v1.2.3 From 6c53e3e93b449c5501ef9d046244a71eb36db074 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:14:29 -0400 Subject: Fix trailing space --- examples/data/scripts/formfiller.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 564bf82..f6962c4 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -5,9 +5,9 @@ # uses settings files like: $keydir/ # files contain lines like: !profile= # (fieldtype): -# profile_name should be replaced with a name that will tell sth about that +# profile_name should be replaced with a name that will tell sth about that # profile -# fieldtype can be checkbox, text or password, textarea - only for information +# fieldtype can be checkbox, text or password, textarea - only for information # pupropse (auto-generated) - don't change that # # Texteares: for textareas edited text can be now splitted into more lines. -- cgit v1.2.3 From 391ffa73dfa46beea7dff2c9789a5f56a39227c4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:40:45 -0400 Subject: Migrate to using uzbl-dir util script --- examples/data/scripts/download.sh | 9 +++--- examples/data/scripts/formfiller.sh | 36 +++++++++++------------- examples/data/scripts/history.sh | 8 ++++-- examples/data/scripts/insert_bookmark.sh | 8 ++++-- examples/data/scripts/load_url_from_bookmarks.sh | 10 ++++--- examples/data/scripts/load_url_from_history.sh | 13 +++++---- examples/data/scripts/session.sh | 20 ++++++------- 7 files changed, 55 insertions(+), 49 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 0f051db..5b4baa7 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -2,10 +2,11 @@ # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do +source $UZBL_UTIL_DIR/uzbl-dir.sh + # Some sites block the default wget --user-agent.. -GET="wget --user-agent=Firefox --content-disposition --load-cookies=$XDG_DATA_HOME/uzbl/cookies.txt" +GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" -dest="$HOME" url="$8" http_proxy="$9" @@ -15,7 +16,7 @@ test "x$url" = "x" && { echo "you must supply a url! ($url)"; exit 1; } # only changes the dir for the $get sub process if echo "$url" | grep -E '.*\.torrent' >/dev/null; then - ( cd "$dest"; $GET "$url") + ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") else - ( cd "$dest"; $GET "$url") + ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") fi diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index f6962c4..3aa1676 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -2,7 +2,7 @@ # # Enhanced html form (eg for logins) filler (and manager) for uzbl. # -# uses settings files like: $keydir/ +# uses settings files like: $UZBL_FORMS_DIR/ # files contain lines like: !profile= # (fieldtype): # profile_name should be replaced with a name that will tell sth about that @@ -49,13 +49,13 @@ else LINES="" fi +source $UZBL_UTIL_DIR/uzbl-dir.sh + PROMPT="Choose profile" MODELINE="> vim:ft=formfiller" -keydir=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/dforms - -[ -d "$(dirname $keydir)" ] || exit 1 -[ -d "$keydir" ] || mkdir "$keydir" +[ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 +[ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1 editor="${VISUAL}" if [ -z "${editor}" ]; then @@ -82,14 +82,12 @@ title=$1; shift action=$1 -[ -d $keydir ] || mkdir $keydir || exit 1 - domain=$(echo $url | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ]; then action="new" - [ -e "$keydir/$domain" ] && action="load" -elif [ "$action" = 'edit' ] && [ ! -e "$keydir/$domain" ]; then + [ -e "$UZBL_FORMS_DIR/$domain" ] && action="load" +elif [ "$action" = 'edit' ] && [ ! -e "$UZBL_FORMS_DIR/$domain" ]; then action="new" fi @@ -150,9 +148,9 @@ insertFunction="function insert(fname, ftype, fvalue, fchecked) { \ }; " if [ "$action" = 'load' ]; then - [ -e $keydir/$domain ] || exit 2 - if [ $(cat $keydir/$domain | grep "!profile" | wc -l) -gt 1 ]; then - menu=$(cat $keydir/$domain | \ + [ -e $UZBL_FORMS_DIR/$domain ] || exit 2 + if [ $(cat $UZBL_FORMS_DIR/$domain | grep "!profile" | wc -l) -gt 1 ]; then + menu=$(cat $UZBL_FORMS_DIR/$domain | \ sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p') option=$(echo -e -n "$menu" | dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}") fi @@ -160,8 +158,8 @@ if [ "$action" = 'load' ]; then # Remove comments sed '/^>/d' -i $tmpfile - sed 's/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):\(off\|no\|false\|unchecked\|0\|$\)/\1{\2}(\3):0/I;s/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[^0]\+/\1{\2}(\3):1/I' -i $keydir/$domain - fields=$(cat $keydir/$domain | \ + sed 's/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):\(off\|no\|false\|unchecked\|0\|$\)/\1{\2}(\3):0/I;s/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[^0]\+/\1{\2}(\3):1/I' -i $UZBL_FORMS_DIR/$domain + fields=$(cat $UZBL_FORMS_DIR/$domain | \ sed -n "/^!profile=${option}/,/^!profile=/p" | \ sed '/^!profile=/d' | \ sed 's/^\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):/%{>\1\2):<}%/' | \ @@ -202,8 +200,8 @@ elif [ "$action" = "once" ]; then rm -f $tmpfile else if [ "$action" = 'new' -o "$action" = 'add' ]; then - [ "$action" = 'new' ] && echo "$MODELINE" > $keydir/$domain - echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $keydir/$domain + [ "$action" = 'new' ] && echo "$MODELINE" > $UZBL_FORMS_DIR/$domain + echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $UZBL_FORMS_DIR/$domain # # 2. and 3. line (tr -d and sed) are because, on gmail login for example, # tag is splited into lines @@ -222,10 +220,10 @@ else # printf 'js %s dump(); \n' "$dumpFunction" | \ socat - unix-connect:$socket | \ - sed -n '/^[^(]\+([^)]\+):/p' >> $keydir/$domain + sed -n '/^[^(]\+([^)]\+):/p' >> $UZBL_FORMS_DIR/$domain fi - [ -e "$keydir/$domain" ] || exit 3 #this should never happen, but you never know. - $editor "$keydir/$domain" #TODO: if user aborts save in editor, the file is already overwritten + [ -e "$UZBL_FORMS_DIR/$domain" ] || exit 3 #this should never happen, but you never know. + $editor "$UZBL_FORMS_DIR/$domain" #TODO: if user aborts save in editor, the file is already overwritten fi # vim:fileencoding=utf-8:sw=4 diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index be5fd34..b91d415 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -1,5 +1,7 @@ #!/bin/sh -file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history -[ -d $(dirname $file) ] || exit 1 -echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $file +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -w "$UZBL_HISTORY_FILE" ] || exit 1 + +echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $UZBL_HISTORY_FILE diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 4d29ad6..201bae0 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,7 +1,9 @@ #!/bin/sh -[ -d "${XDG_DATA_HOME:-$HOME/.local/share}/uzbl" ] || exit 1 -file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -d "$UZBL_DATA_DIR" ] || exit 1 +[ -w "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity &>/dev/null || exit 2 url=$6 @@ -14,5 +16,5 @@ url=$(echo $entry | awk '{print $1}') # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags echo "$entry" >/dev/null #for some reason we need this.. don't ask me why -echo -e "$entry" >> $file +echo -e "$entry" >> $UZBL_BOOKMARKS_FILE true diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 3134407..9a955ec 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,17 +2,19 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. -file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks -[ -r "$file" ] || exit +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 + COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # show tags as well - goto=$($DMENU $COLORS < $file | awk '{print $1}') + goto=$($DMENU $COLORS < $UZBL_BOOKMARKS_FILE | awk '{print $1}') else DMENU="dmenu -i" # because they are all after each other, just show the url, not their tags. - goto=$(awk '{print $1}' $file | $DMENU $COLORS) + goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU $COLORS) fi #[ -n "$goto" ] && echo "uri $goto" > $4 diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 5156eee..9fea1eb 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,21 +1,22 @@ #!/bin/sh -history_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history -[ -r "$history_file" ] || exit 1 +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -r "$UZBL_HISTORY_FILE" ] || exit 1 # choose from all entries, sorted and uniqued -# goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) +# goto=$(awk '{print $3}' $UZBL_HISTORY_FILE | sort -u | dmenu -i) COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # choose an item in reverse order, showing also the date and page titles # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. - goto=$(tac $history_file | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') + goto=$(tac $UZBL_HISTORY_FILE | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') else DMENU="dmenu -i" # choose from all entries (no date or title), the first one being current url, and after that all others, sorted and uniqued, in ascending order - current=$(tail -n 1 $history_file | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' $history_file | grep -v "^$current\$" \ + current=$(tail -n 1 $UZBL_HISTORY_FILE | awk '{print $3}'); + goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ | sort -u) | $DMENU $COLORS) fi diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index acd6934..68ce4d4 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -8,13 +8,13 @@ # and doesn't need to be called manually at any point. # Add a line like 'bind quit = /path/to/session.sh endsession' to your config -[ -d ${XDG_DATA_HOME:-$HOME/.local/share}/uzbl ] || exit 1 -scriptfile=$0 # this script -sessionfile=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/browser-session # the file in which the "session" (i.e. urls) are stored -configfile=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/config # uzbl configuration file -UZBL="uzbl-browser -c $configfile" # add custom flags and whatever here. +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -d $UZBL_DATA_DIR ] || exit 1 + +scriptfile=$0 # this script +UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. -fifodir=/tmp # remember to change this if you instructed uzbl to put its fifos elsewhere thisfifo="$4" act="$8" url="$6" @@ -26,7 +26,7 @@ fi case $act in "launch" ) - urls=$(cat $sessionfile) + urls=$(cat $UZBL_SESSION_FILE) if [ "$urls." = "." ]; then $UZBL else @@ -39,14 +39,14 @@ case $act in "endinstance" ) if [ "$url" != "(null)" ]; then - echo "$url" >> $sessionfile; + echo "$url" >> $UZBL_SESSION_FILE fi echo "exit" > "$thisfifo" ;; "endsession" ) - mv "$sessionfile" "$sessionfile~" - for fifo in $fifodir/uzbl_fifo_*; do + mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" + for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do if [ "$fifo" != "$thisfifo" ]; then echo "spawn $scriptfile endinstance" > "$fifo" fi -- cgit v1.2.3 From eeab3def726000c36cc0ba36ca0506b2eecbaf49 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:36:32 -0400 Subject: Migrate to using uzbl-args util script --- examples/data/scripts/download.sh | 5 ++-- examples/data/scripts/formfiller.sh | 29 +++++++----------------- examples/data/scripts/insert_bookmark.sh | 5 ++-- examples/data/scripts/load_url_from_bookmarks.sh | 5 ++-- examples/data/scripts/load_url_from_history.sh | 5 ++-- examples/data/scripts/session.sh | 21 +++++++++-------- 6 files changed, 30 insertions(+), 40 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 5b4baa7..f2ee4a8 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -2,14 +2,15 @@ # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh # Some sites block the default wget --user-agent.. GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" -url="$8" +url="$1" -http_proxy="$9" +http_proxy="$2" export http_proxy test "x$url" = "x" && { echo "you must supply a url! ($url)"; exit 1; } diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 3aa1676..2c792bc 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -49,6 +49,7 @@ else LINES="" fi +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh PROMPT="Choose profile" @@ -66,23 +67,9 @@ if [ -z "${editor}" ]; then fi fi -config=$1; -shift -pid=$1; -shift -xid=$1; -shift -fifo=$1; -shift -socket=$1; -shift -url=$1; -shift -title=$1; -shift action=$1 -domain=$(echo $url | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') +domain=$(echo $UZBL_URL | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ]; then action="new" @@ -168,14 +155,14 @@ if [ "$action" = 'load' ]; then sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g') printf '%s\n' "${fields}" | \ sed -n -e "s/\([^(]\+\)(\(password\|text\|search\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \ - sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $fifo + sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $UZBL_FIFO printf '%s\n' "${fields}" | \ sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \ - sed -e 's/@/\\@/g' > $fifo + sed -e 's/@/\\@/g' > $UZBL_FIFO elif [ "$action" = "once" ]; then tmpfile=$(mktemp) printf 'js %s dump(); \n' "$dumpFunction" | \ - socat - unix-connect:$socket | \ + socat - unix-connect:$UZBL_SOCKET | \ sed -n '/^[^(]\+([^)]\+):/p' > $tmpfile echo "$MODELINE" >> $tmpfile ${editor} $tmpfile @@ -193,10 +180,10 @@ elif [ "$action" = "once" ]; then sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g') printf '%s\n' "${fields}" | \ sed -n -e "s/\([^(]\+\)(\(password\|text\|search\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \ - sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $fifo + sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $UZBL_FIFO printf '%s\n' "${fields}" | \ sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \ - sed -e 's/@/\\@/g' > $fifo + sed -e 's/@/\\@/g' > $UZBL_FIFO rm -f $tmpfile else if [ "$action" = 'new' -o "$action" = 'add' ]; then @@ -219,7 +206,7 @@ else # passwd(password): # printf 'js %s dump(); \n' "$dumpFunction" | \ - socat - unix-connect:$socket | \ + socat - unix-connect:$UZBL_SOCKET | \ sed -n '/^[^(]\+([^)]\+):/p' >> $UZBL_FORMS_DIR/$domain fi [ -e "$UZBL_FORMS_DIR/$domain" ] || exit 3 #this should never happen, but you never know. diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 201bae0..18f643f 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -6,10 +6,9 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh [ -w "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity &>/dev/null || exit 2 -url=$6 # replace tabs, they are pointless in titles and we want to use tabs as delimiter. -title=$(echo "$7" | sed 's/\t/ /') -entry=$(zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$url $title\t") +title=$(echo "$UZBL_TITLE" | sed 's/\t/ /') +entry=$(zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$UZBL_URL $title\t") exitstatus=$? if [ $exitstatus -ne 0 ]; then exit $exitstatus; fi url=$(echo $entry | awk '{print $1}') diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 9a955ec..3bcb60f 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,6 +2,7 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 @@ -17,5 +18,5 @@ else goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU $COLORS) fi -#[ -n "$goto" ] && echo "uri $goto" > $4 -[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$5 +#[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO +[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 9fea1eb..5aba844 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,5 +1,6 @@ #!/bin/sh +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_HISTORY_FILE" ] || exit 1 @@ -20,5 +21,5 @@ else | sort -u) | $DMENU $COLORS) fi -[ -n "$goto" ] && echo "uri $goto" > $4 -#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$5 +[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO +#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 68ce4d4..1585159 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -8,6 +8,7 @@ # and doesn't need to be called manually at any point. # Add a line like 'bind quit = /path/to/session.sh endsession' to your config +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -d $UZBL_DATA_DIR ] || exit 1 @@ -15,12 +16,12 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh scriptfile=$0 # this script UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. -thisfifo="$4" -act="$8" -url="$6" +act="$1" -if [ "$act." = "." ]; then - act="$1" +# Test if we were run alone or from uzbl +if [ "x$UZBL_FIFO" = "x" ]; then + # Take the old config + act="$UZBL_CONFIG" fi @@ -38,20 +39,20 @@ case $act in ;; "endinstance" ) - if [ "$url" != "(null)" ]; then - echo "$url" >> $UZBL_SESSION_FILE + if [ "$UZBL_URL" != "(null)" ]; then + echo "$UZBL_URL" >> $UZBL_SESSION_FILE fi - echo "exit" > "$thisfifo" + echo "exit" > "$UZBL_FIFO" ;; "endsession" ) mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do - if [ "$fifo" != "$thisfifo" ]; then + if [ "$fifo" != "$UZBL_FIFO" ]; then echo "spawn $scriptfile endinstance" > "$fifo" fi done - echo "spawn $scriptfile endinstance" > "$thisfifo" + echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" ;; * ) echo "session manager: bad action" -- cgit v1.2.3 From 8eed5f24a0d40574433c3f3a945e6aac75e06aba Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:37:25 -0400 Subject: Migrate to using the dmenu util script --- examples/data/scripts/formfiller.sh | 19 ++++++------------- examples/data/scripts/instance-select-wmii.sh | 10 ++-------- examples/data/scripts/load_url_from_bookmarks.sh | 14 ++++++-------- examples/data/scripts/load_url_from_history.sh | 21 +++++++++------------ 4 files changed, 23 insertions(+), 41 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 2c792bc..cf8e46b 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -37,22 +37,15 @@ # something else (or empty): if file not available: new, otherwise load. # -# config dmenu colors and prompt -NB="#0f0f0f" -NF="#4e7093" -SB="#003d7c" -SF="#3a9bff" - -if [ "$(dmenu --help 2>&1 | grep lines)x" != "x" ]; then - LINES=" -l 3 " -else - LINES="" -fi +DMENU_ARGS="-i" +DMENU_SCHEMA="formfiller" +DMENU_LINES="3" +DMENU_PROMPT="Choose profile" +source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh -PROMPT="Choose profile" MODELINE="> vim:ft=formfiller" [ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 @@ -139,7 +132,7 @@ if [ "$action" = 'load' ]; then if [ $(cat $UZBL_FORMS_DIR/$domain | grep "!profile" | wc -l) -gt 1 ]; then menu=$(cat $UZBL_FORMS_DIR/$domain | \ sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p') - option=$(echo -e -n "$menu" | dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}") + option=$(echo -e -n "$menu" | $DMENU) fi # Remove comments diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index 1340351..82acf3b 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -11,13 +11,7 @@ # See http://www.uzbl.org/wiki/wmii for more info # $1 must be one of 'list', 'next', 'prev' -COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" - -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then - DMENU="dmenu -i -xs -rs -l 10" # vertical patch -else - DMENU="dmenu -i" -fi +source $UZBL_UTIL_DIR/dmenu.sh if [ "$1" == 'list' ]; then list= @@ -26,7 +20,7 @@ if [ "$1" == 'list' ]; then label=$(wmiir read /client/$i/label) list="$list$i : $label\n" done - window=$(echo -e "$list" | $DMENU $COLORS | cut -d ' ' -f1) + window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1) wmiir xwrite /tag/sel/ctl "select client $window" elif [ "$1" == 'next' ]; then current=$(wmiir read /client/sel/ctl | head -n 1) diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 3bcb60f..1cf8ea4 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,20 +2,18 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. +source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 -COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then - DMENU="dmenu -i -xs -rs -l 10" # vertical patch - # show tags as well - goto=$($DMENU $COLORS < $UZBL_BOOKMARKS_FILE | awk '{print $1}') +if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then + # because they are all after each other, just show the url, not their tags. + goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU) else - DMENU="dmenu -i" - # because they are all after each other, just show the url, not their tags. - goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU $COLORS) + # show tags as well + goto=$($DMENU < $UZBL_BOOKMARKS_FILE | awk '{print $1}') fi #[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 5aba844..f79e018 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,24 +1,21 @@ #!/bin/sh +source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_HISTORY_FILE" ] || exit 1 # choose from all entries, sorted and uniqued -# goto=$(awk '{print $3}' $UZBL_HISTORY_FILE | sort -u | dmenu -i) -COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then - DMENU="dmenu -i -xs -rs -l 10" # vertical patch - # choose an item in reverse order, showing also the date and page titles - # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. - goto=$(tac $UZBL_HISTORY_FILE | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') +# goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) +if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then + current=$(tail -n 1 $UZBL_HISTORY_FILE | awk '{print $3}'); + goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ + | sort -u) | $DMENU) else - DMENU="dmenu -i" - # choose from all entries (no date or title), the first one being current url, and after that all others, sorted and uniqued, in ascending order - current=$(tail -n 1 $UZBL_HISTORY_FILE | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ - | sort -u) | $DMENU $COLORS) + # choose an item in reverse order, showing also the date and page titles + # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. + goto=$(tac $UZBL_HISTORY_FILE | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}') fi [ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -- cgit v1.2.3 From 36b6240a73ceb9d7b5c504e960d491693de98199 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:37:46 -0400 Subject: Migrate to using the editor util script --- examples/data/scripts/formfiller.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index cf8e46b..fb1eb02 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -43,6 +43,7 @@ DMENU_LINES="3" DMENU_PROMPT="Choose profile" source $UZBL_UTIL_DIR/dmenu.sh +source $UZBL_UTIL_DIR/editor.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh @@ -51,15 +52,6 @@ MODELINE="> vim:ft=formfiller" [ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 [ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1 -editor="${VISUAL}" -if [ -z "${editor}" ]; then - if [ -z "${EDITOR}" ]; then - editor='xterm -e vim' - else - editor="xterm -e ${EDITOR}" - fi -fi - action=$1 domain=$(echo $UZBL_URL | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') @@ -158,7 +150,7 @@ elif [ "$action" = "once" ]; then socat - unix-connect:$UZBL_SOCKET | \ sed -n '/^[^(]\+([^)]\+):/p' > $tmpfile echo "$MODELINE" >> $tmpfile - ${editor} $tmpfile + $UZBL_EDITOR $tmpfile [ -e $tmpfile ] || exit 2 @@ -203,7 +195,7 @@ else sed -n '/^[^(]\+([^)]\+):/p' >> $UZBL_FORMS_DIR/$domain fi [ -e "$UZBL_FORMS_DIR/$domain" ] || exit 3 #this should never happen, but you never know. - $editor "$UZBL_FORMS_DIR/$domain" #TODO: if user aborts save in editor, the file is already overwritten + $UZBL_EDITOR "$UZBL_FORMS_DIR/$domain" #TODO: if user aborts save in editor, the file is already overwritten fi # vim:fileencoding=utf-8:sw=4 -- cgit v1.2.3 From 8c19571e0890d7a4922eb461147749e9f65a7be4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:45:52 -0400 Subject: Match indentation in session.sh to match others --- examples/data/scripts/session.sh | 70 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 1585159..385b40c 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -24,40 +24,40 @@ if [ "x$UZBL_FIFO" = "x" ]; then act="$UZBL_CONFIG" fi - case $act in - "launch" ) - urls=$(cat $UZBL_SESSION_FILE) - if [ "$urls." = "." ]; then - $UZBL - else - for url in $urls; do - $UZBL --uri "$url" & - done - fi - exit 0 - ;; - - "endinstance" ) - if [ "$UZBL_URL" != "(null)" ]; then - echo "$UZBL_URL" >> $UZBL_SESSION_FILE - fi - echo "exit" > "$UZBL_FIFO" - ;; - - "endsession" ) - mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" - for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do - if [ "$fifo" != "$UZBL_FIFO" ]; then - echo "spawn $scriptfile endinstance" > "$fifo" - fi - done - echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" - ;; - - * ) echo "session manager: bad action" - echo "Usage: $scriptfile [COMMAND] where commands are:" - echo " launch - Restore a saved session or start a new one" - echo " endsession - Quit the running session. Must be called from uzbl" - ;; + "launch" ) + urls=$(cat $UZBL_SESSION_FILE) + if [ "$urls." = "." ]; then + $UZBL + else + for url in $urls; do + $UZBL --uri "$url" & + done + fi + exit 0 + ;; + + "endinstance" ) + if [ ! "$UZBL_URL" = "(null)" ]; then + echo "$UZBL_URL" >> $UZBL_SESSION_FILE + fi + echo "exit" > "$UZBL_FIFO" + ;; + + "endsession" ) + mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" + for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do + if [ "$fifo" != "$UZBL_FIFO" ]; then + echo "spawn $scriptfile endinstance" > "$fifo" + fi + done + echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" + ;; + + * ) + echo "session manager: bad action" + echo "Usage: $scriptfile [COMMAND] where commands are:" + echo " launch - Restore a saved session or start a new one" + echo " endsession - Quit the running session. Must be called from uzbl" + ;; esac -- cgit v1.2.3 From 0c62bcfc3e5abbee44c2bbbfc236f7e3e3f2aa1e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:46:11 -0400 Subject: Fix empty string check --- examples/data/scripts/session.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 385b40c..ecd6b1a 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -27,7 +27,7 @@ fi case $act in "launch" ) urls=$(cat $UZBL_SESSION_FILE) - if [ "$urls." = "." ]; then + if [ "x$urls" = "x" ]; then $UZBL else for url in $urls; do -- cgit v1.2.3 From f00cd76d9e3e7f70afc5ed0b616c0c6582f81845 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:46:32 -0400 Subject: Disown the process as well --- examples/data/scripts/session.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index ecd6b1a..d7bb322 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -32,6 +32,7 @@ case $act in else for url in $urls; do $UZBL --uri "$url" & + disown done fi exit 0 -- cgit v1.2.3 From 75841cf0ca5c2790cb589a592c8af683fe04cbad Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:46:48 -0400 Subject: Check to make sure uzbl called endinstance --- examples/data/scripts/session.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index d7bb322..c226c29 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -39,6 +39,10 @@ case $act in ;; "endinstance" ) + if [ "x$UZBL_FIFO" = "x" ]; then + echo "session manager: endinstance must be called from uzbl" + exit 1 + fi if [ ! "$UZBL_URL" = "(null)" ]; then echo "$UZBL_URL" >> $UZBL_SESSION_FILE fi -- cgit v1.2.3 From 5f6d5a160485f262fbff74d1c1c8565702bc6f6e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:47:14 -0400 Subject: Fix usage message --- examples/data/scripts/session.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index c226c29..d30f3da 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -62,7 +62,8 @@ case $act in * ) echo "session manager: bad action" echo "Usage: $scriptfile [COMMAND] where commands are:" - echo " launch - Restore a saved session or start a new one" - echo " endsession - Quit the running session. Must be called from uzbl" + echo " launch - Restore a saved session or start a new one" + echo " endinstance - Quit the current instance. Must be called from uzbl" + echo " endsession - Quit the running session." ;; esac -- cgit v1.2.3 From a2901d469cacd317e8995486401f363bc569d37c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:47:25 -0400 Subject: Loading from bookmarks is now POSIX sh --- examples/data/scripts/load_url_from_bookmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 1cf8ea4..d5f7bd6 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. -- cgit v1.2.3 From e0e443e5c5bbd7663542788401d0e44da91e301e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:02:11 -0400 Subject: Use -z and -n tests rather than "x$foo" = "x" hack --- examples/data/scripts/download.sh | 5 ++++- examples/data/scripts/instance-select-wmii.sh | 4 ++-- examples/data/scripts/load_url_from_bookmarks.sh | 2 +- examples/data/scripts/load_url_from_history.sh | 2 +- examples/data/scripts/session.sh | 6 +++--- examples/data/scripts/util/dmenu.sh | 6 +++--- examples/data/scripts/util/editor.sh | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index f2ee4a8..7375535 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -13,7 +13,10 @@ url="$1" http_proxy="$2" export http_proxy -test "x$url" = "x" && { echo "you must supply a url! ($url)"; exit 1; } +if [ -z "$url" ]; then + echo "you must supply a url! ($url)" + exit 1 +fi # only changes the dir for the $get sub process if echo "$url" | grep -E '.*\.torrent' >/dev/null; then diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index 82acf3b..dcb8866 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -26,13 +26,13 @@ elif [ "$1" == 'next' ]; then current=$(wmiir read /client/sel/ctl | head -n 1) # find the next uzbl window and focus it next=$(wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f2) - if [ x"$next" != "x" ]; then + if [ -n "$next" ]; then wmiir xwrite /tag/sel/ctl "select client $next" fi elif [ "$1" == 'prev' ]; then current=$(wmiir read /client/sel/ctl | head -n 1) prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2) - if [ x"$prev" != "x" ]; then + if [ -n "$prev" ]; then wmiir xwrite /tag/sel/ctl "select client $prev" fi else diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index d5f7bd6..7613624 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -8,7 +8,7 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 -if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then +if [ -z "$DMENU_HAS_VERTICAL" ]; then # because they are all after each other, just show the url, not their tags. goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU) else diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index f79e018..ca8959c 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -8,7 +8,7 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh # choose from all entries, sorted and uniqued # goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) -if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then +if [ -z "$DMENU_HAS_VERTICAL" ]; then current=$(tail -n 1 $UZBL_HISTORY_FILE | awk '{print $3}'); goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ | sort -u) | $DMENU) diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index d30f3da..3f1c6d3 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -19,7 +19,7 @@ UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. act="$1" # Test if we were run alone or from uzbl -if [ "x$UZBL_FIFO" = "x" ]; then +if [ -z "$UZBL_FIFO" ]; then # Take the old config act="$UZBL_CONFIG" fi @@ -27,7 +27,7 @@ fi case $act in "launch" ) urls=$(cat $UZBL_SESSION_FILE) - if [ "x$urls" = "x" ]; then + if [ -z "$urls" ]; then $UZBL else for url in $urls; do @@ -39,7 +39,7 @@ case $act in ;; "endinstance" ) - if [ "x$UZBL_FIFO" = "x" ]; then + if [ -z "$UZBL_FIFO" ]; then echo "session manager: endinstance must be called from uzbl" exit 1 fi diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 3f307f2..2326cea 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -40,12 +40,12 @@ case "$DMENU_SCHEME" in esac # Default arguments -if [ "x$DMENU_ARGS" = "x" ]; then +if [ -z "$DMENU_ARGS" ]; then DMENU_ARGS="-i" fi # Set the prompt if wanted -if [ ! "x$DMENU_PROMPT" = "x" ]; then +if [ -n "$DMENU_PROMPT" ]; then DMENU_ARGS="$DMENU_ARGS -p $DMENU_PROMPT" fi @@ -58,7 +58,7 @@ fi # Detect the vertical patch if dmenu --help 2>&1 | grep -q '\[-l lines\]'; then # Default to 10 lines - if [ "x$DMENU_LINES" = "x" ]; then + if [ -z "$DMENU_LINES" ]; then DMENU_LINES=10 fi diff --git a/examples/data/scripts/util/editor.sh b/examples/data/scripts/util/editor.sh index a152ebd..1969769 100644 --- a/examples/data/scripts/util/editor.sh +++ b/examples/data/scripts/util/editor.sh @@ -1,7 +1,7 @@ #!/bin/sh # Editor selection -if [ "x$VTERM" = "x" ]; then +if [ -z "$VTERM" ]; then VTERM="xterm" fi -- cgit v1.2.3 From cfd3ff8fcff8aad7b57d8b757c2401f58aebd561 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:02:43 -0400 Subject: Use a case statement in the wmii script --- examples/data/scripts/instance-select-wmii.sh | 57 +++++++++++++++------------ 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index dcb8866..1fc6ed0 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -13,29 +13,34 @@ source $UZBL_UTIL_DIR/dmenu.sh -if [ "$1" == 'list' ]; then - list= - # get window id's of uzbl clients. we could also get the label in one shot but it's pretty tricky - for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2); do - label=$(wmiir read /client/$i/label) - list="$list$i : $label\n" - done - window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1) - wmiir xwrite /tag/sel/ctl "select client $window" -elif [ "$1" == 'next' ]; then - current=$(wmiir read /client/sel/ctl | head -n 1) - # find the next uzbl window and focus it - next=$(wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f2) - if [ -n "$next" ]; then - wmiir xwrite /tag/sel/ctl "select client $next" - fi -elif [ "$1" == 'prev' ]; then - current=$(wmiir read /client/sel/ctl | head -n 1) - prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2) - if [ -n "$prev" ]; then - wmiir xwrite /tag/sel/ctl "select client $prev" - fi -else - echo "\$1 not valid" >&2 - exit 2 -fi +case "$1" in + "list" ) + list= + # get window id's of uzbl clients. we could also get the label in one shot but it's pretty tricky + for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2); do + label=$(wmiir read /client/$i/label) + list="$list$i : $label\n" + done + window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1) + wmiir xwrite /tag/sel/ctl "select client $window" + ;; + "next" ) + current=$(wmiir read /client/sel/ctl | head -n 1) + # find the next uzbl window and focus it + next=$(wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f2) + if [ -n "$next" ]; then + wmiir xwrite /tag/sel/ctl "select client $next" + fi + ;; + "prev" ) + current=$(wmiir read /client/sel/ctl | head -n 1) + prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2) + if [ -n "$prev" ]; then + wmiir xwrite /tag/sel/ctl "select client $prev" + fi + ;; + * ) + echo "$1 not valid" >&2 + exit 2 + ;; +esac -- cgit v1.2.3 From 444be23decea26ea40090a909b36fd23516a88b4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:03:08 -0400 Subject: Quotes really needed here? --- examples/data/scripts/session.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 3f1c6d3..64d8c6b 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -46,17 +46,17 @@ case $act in if [ ! "$UZBL_URL" = "(null)" ]; then echo "$UZBL_URL" >> $UZBL_SESSION_FILE fi - echo "exit" > "$UZBL_FIFO" + echo "exit" > $UZBL_FIFO ;; "endsession" ) mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do if [ "$fifo" != "$UZBL_FIFO" ]; then - echo "spawn $scriptfile endinstance" > "$fifo" + echo "spawn $scriptfile endinstance" > $fifo fi done - echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" + echo "spawn $scriptfile endinstance" > $UZBL_FIFO ;; * ) -- cgit v1.2.3 From 01d32f99ff5b0fb3d195ad9816e992a8267ec7b9 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:07:14 -0400 Subject: Add directory for the sockets as well --- examples/data/scripts/util/uzbl-dir.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh index 01fb469..bb56954 100644 --- a/examples/data/scripts/util/uzbl-dir.sh +++ b/examples/data/scripts/util/uzbl-dir.sh @@ -5,6 +5,7 @@ UZBL_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl UZBL_CONFIG_DIR=${XDG_CONFIG_DIR:-$HOME/.config}/uzbl UZBL_FIFO_DIR=/tmp +UZBL_SOCKET_DIR=/tmp # Directories UZBL_DOWNLOAD_DIR=${XDG_DOWNLOAD_DIR:-$HOME} -- cgit v1.2.3 From 90ebadae7fa7843ed4a43c03e344d0e8cdebc936 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:07:34 -0400 Subject: Prefer sockets to fifos --- examples/data/scripts/formfiller.sh | 8 ++++---- examples/data/scripts/load_url_from_history.sh | 4 ++-- examples/data/scripts/session.sh | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index fb1eb02..041c6a6 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -140,10 +140,10 @@ if [ "$action" = 'load' ]; then sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g') printf '%s\n' "${fields}" | \ sed -n -e "s/\([^(]\+\)(\(password\|text\|search\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \ - sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $UZBL_FIFO + sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' | socat - unix-connect:$UZBL_SOCKET printf '%s\n' "${fields}" | \ sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \ - sed -e 's/@/\\@/g' > $UZBL_FIFO + sed -e 's/@/\\@/g' | socat - unix-connect:$UZBL_SOCKET elif [ "$action" = "once" ]; then tmpfile=$(mktemp) printf 'js %s dump(); \n' "$dumpFunction" | \ @@ -165,10 +165,10 @@ elif [ "$action" = "once" ]; then sed 's/<{br}>%{>\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):<}%/\\n\1\2):/g') printf '%s\n' "${fields}" | \ sed -n -e "s/\([^(]\+\)(\(password\|text\|search\|textarea\)\+):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\2', '\3', 0);/p" | \ - sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' > $UZBL_FIFO + sed -e 's/@/\\@/g;s/<{br}>/\\\\n/g' | socat - unix-connect:$UZBL_SOCKET printf '%s\n' "${fields}" | \ sed -n -e "s/\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[ ]*\(.\+\)/js $insertFunction; insert('\1', '\3', '\2', \4);/p" | \ - sed -e 's/@/\\@/g' > $UZBL_FIFO + sed -e 's/@/\\@/g' | socat - unix-connect:$UZBL_SOCKET rm -f $tmpfile else if [ "$action" = 'new' -o "$action" = 'add' ]; then diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index ca8959c..80cd3d8 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -18,5 +18,5 @@ else goto=$(tac $UZBL_HISTORY_FILE | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}') fi -[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET +#[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO +[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 64d8c6b..89eeb7a 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -19,7 +19,7 @@ UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. act="$1" # Test if we were run alone or from uzbl -if [ -z "$UZBL_FIFO" ]; then +if [ -z "$UZBL_SOCKET" ]; then # Take the old config act="$UZBL_CONFIG" fi @@ -39,24 +39,24 @@ case $act in ;; "endinstance" ) - if [ -z "$UZBL_FIFO" ]; then + if [ -z "$UZBL_SOCKET" ]; then echo "session manager: endinstance must be called from uzbl" exit 1 fi if [ ! "$UZBL_URL" = "(null)" ]; then echo "$UZBL_URL" >> $UZBL_SESSION_FILE fi - echo "exit" > $UZBL_FIFO + echo "exit" | socat - unix-connect:$UZBL_SOCKET ;; "endsession" ) mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" - for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do - if [ "$fifo" != "$UZBL_FIFO" ]; then - echo "spawn $scriptfile endinstance" > $fifo + for sock in $UZBL_SOCKET_DIR/uzbl_fifo_*; do + if [ "$sock" != "$UZBL_SOCKET" ]; then + echo "spawn $scriptfile endinstance" | socat - unix-connect:$socket fi done - echo "spawn $scriptfile endinstance" > $UZBL_FIFO + echo "spawn $scriptfile endinstance" | socat - unix-connect:$UZBL_SOCKET ;; * ) -- cgit v1.2.3 From c30ba29c31941e4ebc4322636e3fe435f1097aaa Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:11:15 -0400 Subject: Fix detection of the vertical patch --- examples/data/scripts/util/dmenu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 2326cea..2972663 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -56,7 +56,7 @@ if dmenu --help 2>&1 | grep -q '\[-xs\]'; then fi # Detect the vertical patch -if dmenu --help 2>&1 | grep -q '\[-l lines\]'; then +if dmenu --help 2>&1 | grep -q '\[-l \]'; then # Default to 10 lines if [ -z "$DMENU_LINES" ]; then DMENU_LINES=10 -- cgit v1.2.3 From aabbcdc4faa4447159606b8a5a70bf17002ba310 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:14:44 -0400 Subject: Make a variable for dmenu color arguments --- examples/data/scripts/util/dmenu.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 2972663..d1411c7 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -39,6 +39,8 @@ case "$DMENU_SCHEME" in ;; esac +DMENU_COLORS="-nb $NB -nf $NF -sb $SB -sf $SF" + # Default arguments if [ -z "$DMENU_ARGS" ]; then DMENU_ARGS="-i" @@ -71,4 +73,4 @@ if dmenu --help 2>&1 | grep -q '\[-l \]'; then fi fi -DMENU="dmenu $DMENU_ARGS -nb $NB -nf $NF -sb $SB -sf $SF" +DMENU="dmenu $DMENU_ARGS $DMENU_COLORS" -- cgit v1.2.3 From 1fcdfb3a104b44d80300f77f31d6192c3560d8e7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:16:19 -0400 Subject: Support setting the dmenu font --- examples/data/scripts/util/dmenu.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index d1411c7..7d540bd 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -46,6 +46,11 @@ if [ -z "$DMENU_ARGS" ]; then DMENU_ARGS="-i" fi +# Set the font if wanted +if [ -n "$DMENU_FONT" ]; then + DMENU_ARGS="$DMENU_ARGS -fn $DMENU_FONT" +fi + # Set the prompt if wanted if [ -n "$DMENU_PROMPT" ]; then DMENU_ARGS="$DMENU_ARGS -p $DMENU_PROMPT" -- cgit v1.2.3 From 7244ebde733e0578d8d617275f1bcaa5947bc935 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 13:30:21 -0400 Subject: Fix the default configuration to support utils --- examples/config/config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 81aa464..847b4af 100644 --- a/examples/config/config +++ b/examples/config/config @@ -34,7 +34,8 @@ set set_mode = set mode = set set_status = set status_message = # Spawn path shortcuts. In spawn the first dir+path match is used in "dir1:dir2:dir3:executable" -set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scripts +set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scripts +set scripts_util_dir = @scripts_dir/util # === Hardcoded handlers ===================================================== -- cgit v1.2.3 From fa27c93805d19d9aabae896a359b77767afc9de0 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:50:19 -0400 Subject: Set the dmenu theme properly --- examples/data/scripts/instance-select-wmii.sh | 2 ++ examples/data/scripts/load_url_from_bookmarks.sh | 2 ++ examples/data/scripts/load_url_from_history.sh | 2 ++ 3 files changed, 6 insertions(+) (limited to 'examples') diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index 1fc6ed0..967d7ad 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -11,6 +11,8 @@ # See http://www.uzbl.org/wiki/wmii for more info # $1 must be one of 'list', 'next', 'prev' +DMENU_SCHEME="wmii" + source $UZBL_UTIL_DIR/dmenu.sh case "$1" in diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 7613624..2c2a926 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,6 +2,8 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. +DMENU_SCHEME="bookmarks" + source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 80cd3d8..2d15b4f 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,5 +1,7 @@ #!/bin/sh +DMENU_SCHEME="history" + source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh -- cgit v1.2.3 From 5745a8f9f37fb233f1d5e1b7e1be3c8f8db7be54 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:51:33 -0400 Subject: Make xmms an option even if found --- examples/data/scripts/util/dmenu.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 7d540bd..9890b02 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -58,8 +58,12 @@ fi # Detect the xmms patch if dmenu --help 2>&1 | grep -q '\[-xs\]'; then - DMENU_ARGS="$DMENU_ARGS -xs" + DMENU_XMMS_ARGS="-xs" DMENU_HAS_XMMS=1 + + if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then + DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS" + fi fi # Detect the vertical patch -- cgit v1.2.3 From 505114b665757bace138f54b6bba22869f6835f6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:52:00 -0400 Subject: Make vertical mode an option even if found --- examples/data/scripts/util/dmenu.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 9890b02..8113c3b 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -73,12 +73,21 @@ if dmenu --help 2>&1 | grep -q '\[-l \]'; then DMENU_LINES=10 fi - DMENU_ARGS="$DMENU_ARGS -l $DMENU_LINES" + DMENU_VERTICAL_ARGS="-l $DMENU_LINES" DMENU_HAS_VERTICAL=1 # Detect the resize patch if dmenu --help 2>&1 | grep -q '\[-rs\]'; then - DMENU_ARGS="$DMENU_ARGS -rs" + DMENU_RESIZE_ARGS="-rs" + DMENU_HAS_RESIZE=1 + fi + + if echo $DMENU_OPTIONS | grep -q -w 'vertical'; then + DMENU_ARGS="$DMENU_ARGS $DMENU_VERTICAL_ARGS" + + if echo $DMENU_OPTIONS | grep -q -w 'resize'; then + DMENU_ARGS="$DMENU_ARGS $DMENU_RESIZE_ARGS" + fi fi fi -- cgit v1.2.3 From 310bff511a3fd53a30449e32b4f13bb1bc1f51c7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:52:18 -0400 Subject: Detect the placement patch --- examples/data/scripts/util/dmenu.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 8113c3b..757e5cd 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -91,4 +91,13 @@ if dmenu --help 2>&1 | grep -q '\[-l \]'; then fi fi +# Detect placement patch +if dmenu --help 2>&1 | grep -q '\[-x \]'; then + DMENU_PLACE_X="-x" + DMENU_PLACE_Y="-y" + DMENU_PLACE_WIDTH="-w" + DMENU_PLACE_HEIGHT="-h" + DMENU_HAS_PLACEMENT=1 +fi + DMENU="dmenu $DMENU_ARGS $DMENU_COLORS" -- cgit v1.2.3 From f6441475cdd4ff435d35e8692ee52b885b17f809 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:52:38 -0400 Subject: Add utility script to find the window geometry --- examples/data/scripts/util/uzbl-window.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/data/scripts/util/uzbl-window.sh (limited to 'examples') diff --git a/examples/data/scripts/util/uzbl-window.sh b/examples/data/scripts/util/uzbl-window.sh new file mode 100644 index 0000000..b2771e4 --- /dev/null +++ b/examples/data/scripts/util/uzbl-window.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# uzbl window detection + +if [ -z "$UZBL_XID" ]; then + echo "Error: UZBL_XID not set" + echo "Please source uzbl-args.sh first" + exit 1 +fi + +UZBL_WIN_POS=$(xwininfo -id $UZBL_XID | \ + sed -ne 's/Corners:[ ]*[+-]\([0-9]*\)[+-]\([0-9]*\).*$/\1 \2/p') +UZBL_WIN_SIZE=$(xwininfo -id $UZBL_XID | \ + sed -ne 's/-geometry[ ]*\([0-9]*\)x\([0-9]*\).*$/\1 \2/p') +UZBL_WIN_POS_X=$(echo $UZBL_WIN_POS | cut -d\ -f1) +UZBL_WIN_POS_Y=$(echo $UZBL_WIN_POS | cut -d\ -f2) +UZBL_WIN_WIDTH=$(echo $UZBL_WIN_SIZE | cut -d\ -f1) +UZBL_WIN_HEIGHT=$(echo $UZBL_WIN_SIZE | cut -d\ -f2) -- cgit v1.2.3 From ca680c621b57048f781f154d1e65009aa0001906 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:53:51 -0400 Subject: Set defaults for loading bookmarks and history --- examples/data/scripts/load_url_from_bookmarks.sh | 1 + examples/data/scripts/load_url_from_history.sh | 1 + 2 files changed, 2 insertions(+) (limited to 'examples') diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 2c2a926..564c3f8 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -3,6 +3,7 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. DMENU_SCHEME="bookmarks" +DMENU_OPTIONS="xmms vertical resize" source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 2d15b4f..d094625 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,6 +1,7 @@ #!/bin/sh DMENU_SCHEME="history" +DMENU_OPTIONS="xmms vertical resize" source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh -- cgit v1.2.3 From 400b23552e7a4e8f1219c677dc491f35e22d335a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:55:17 -0400 Subject: Prefer vertical and resizing in formfiller --- examples/data/scripts/formfiller.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 041c6a6..19147a8 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -41,6 +41,7 @@ DMENU_ARGS="-i" DMENU_SCHEMA="formfiller" DMENU_LINES="3" DMENU_PROMPT="Choose profile" +DMENU_OPTIONS="vertical resize" source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/editor.sh -- cgit v1.2.3 From 4527524da9af9feb9a324061c4f8cb11361da224 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Oct 2010 16:12:44 -0400 Subject: Alias the keypad enter to enter --- examples/config/config | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index b6d9fe3..dd76381 100644 --- a/examples/config/config +++ b/examples/config/config @@ -121,6 +121,7 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MI @modmap @modmap @modmap +@modmap #modkey_addition @modkey_addition -- cgit v1.2.3 From c3fdbba61d8312244078085568478c4e93066ea4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Oct 2010 16:13:10 -0400 Subject: Ignore multikey When the compose key is used in insert mode, the multi_key is still 'active' when command mode is returned to. Ignore this key. --- examples/config/config | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index dd76381..535e68b 100644 --- a/examples/config/config +++ b/examples/config/config @@ -131,6 +131,7 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MI #ignore_key @ignore_key @ignore_key +@ignore_key # --- Bind aliases ----------------------------------------------------------- -- cgit v1.2.3 From e208b432c1337d5b09650fe2f192fd9d5bf117af Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Oct 2010 16:13:54 -0400 Subject: More scrolling bindings Home/End should work. Ctrl-f/b are commonly used vim bindings. --- examples/config/config | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 535e68b..bbd9f82 100644 --- a/examples/config/config +++ b/examples/config/config @@ -190,8 +190,12 @@ set ebind = @mode_bind global,-insert @cbind l = scroll horizontal 20 @cbind = scroll vertical -100% @cbind = scroll vertical 100% +@cbind f = scroll vertical 100% +@cbind b = scroll vertical -100% @cbind << = scroll vertical begin @cbind >> = scroll vertical end +@cbind = scroll vertical begin +@cbind = scroll vertical end @cbind ^ = scroll horizontal begin @cbind $ = scroll horizontal end @cbind = scroll vertical end -- cgit v1.2.3 From de6c0fba6787c2b05e44244cfe3cdb1c864e0423 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Oct 2010 16:14:42 -0400 Subject: Add the same duality for pasting a url as others It changes gY's meaning, but it better matches with go/gO and friends. --- examples/config/config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index bbd9f82..fe2565c 100644 --- a/examples/config/config +++ b/examples/config/config @@ -305,7 +305,8 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gN = event NEW_TAB_NEXT @cbind go_ = event NEW_TAB %s @cbind gO_ = event NEW_TAB_NEXT %s -@cbind gY = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' # Closing / resting @cbind gC = exit -- cgit v1.2.3 From a43400b5633dcff781e5c4ff5a52608cf3e29793 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Oct 2010 16:15:27 -0400 Subject: Add a keybinding to open a similar window History is lost, but it works as a temporary bookmarking system. --- examples/config/config | 3 +++ 1 file changed, 3 insertions(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index fe2565c..961d1d9 100644 --- a/examples/config/config +++ b/examples/config/config @@ -261,6 +261,9 @@ set ebind = @mode_bind global,-insert @cbind yu = sh 'echo -n $6 | xclip' @cbind yy = sh 'echo -n $7 | xclip' +# Clone current window +@cbind c = sh 'echo "event NEW_TAB $6" > $4' +#@cbind c = sh 'uzbl-browser -u $6' # Go the page from primary selection @cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' # Go to the page in clipboard -- cgit v1.2.3 From c585a24f67fcd7e796ef25366123db21cfad1322 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Oct 2010 16:25:28 -0400 Subject: Make tabbed versions of the 'clone' binding --- examples/config/config | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 961d1d9..a387019 100644 --- a/examples/config/config +++ b/examples/config/config @@ -262,8 +262,7 @@ set ebind = @mode_bind global,-insert @cbind yy = sh 'echo -n $7 | xclip' # Clone current window -@cbind c = sh 'echo "event NEW_TAB $6" > $4' -#@cbind c = sh 'uzbl-browser -u $6' +@cbind c = sh 'uzbl-browser -u $6' # Go the page from primary selection @cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' # Go to the page in clipboard @@ -311,6 +310,10 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' @cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +# Clone current tab +@cbind gd = sh 'echo "event NEW_TAB $6" > $4' +@cbind gD = sh 'echo "event NEW_TAB_NEXT $6" > $4' + # Closing / resting @cbind gC = exit @cbind gQ = event CLEAN_TABS -- cgit v1.2.3 From 8da3fc7070bd9a4f6e712d38d9f628f1399b7c57 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 10 Oct 2010 11:46:23 -0400 Subject: Add yU/yY to yank the hovered uri --- examples/config/config | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index a387019..c61ae76 100644 --- a/examples/config/config +++ b/examples/config/config @@ -259,7 +259,9 @@ set ebind = @mode_bind global,-insert # Yanking & pasting binds @cbind yu = sh 'echo -n $6 | xclip' +@cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI @cbind yy = sh 'echo -n $7 | xclip' +@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI # Clone current window @cbind c = sh 'uzbl-browser -u $6' -- cgit v1.2.3 From b688f20bcf0393009924699c68e387ad6d0b55a5 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 10 Oct 2010 04:12:44 +0800 Subject: Alias the keypad enter to enter --- examples/config/config | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 622f859..c4a7e0d 100644 --- a/examples/config/config +++ b/examples/config/config @@ -124,6 +124,7 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MI @modmap @modmap @modmap +@modmap #modkey_addition @modkey_addition -- cgit v1.2.3 From 775d3fd5f0cd8bfc26700fd287034a9fb6387fcf Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 10 Oct 2010 04:13:10 +0800 Subject: Ignore multikey When the compose key is used in insert mode, the multi_key is still 'active' when command mode is returned to. Ignore this key. --- examples/config/config | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index c4a7e0d..6af2276 100644 --- a/examples/config/config +++ b/examples/config/config @@ -134,6 +134,7 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MI #ignore_key @ignore_key @ignore_key +@ignore_key # --- Bind aliases ----------------------------------------------------------- -- cgit v1.2.3 From 81711172d004473ce56b153f3aad3d56c395f795 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 10 Oct 2010 04:13:54 +0800 Subject: More scrolling bindings Home/End should work. Ctrl-f/b are commonly used vim bindings. --- examples/config/config | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 6af2276..d927b27 100644 --- a/examples/config/config +++ b/examples/config/config @@ -193,8 +193,12 @@ set ebind = @mode_bind global,-insert @cbind l = scroll horizontal 20 @cbind = scroll vertical -100% @cbind = scroll vertical 100% +@cbind f = scroll vertical 100% +@cbind b = scroll vertical -100% @cbind << = scroll vertical begin @cbind >> = scroll vertical end +@cbind = scroll vertical begin +@cbind = scroll vertical end @cbind ^ = scroll horizontal begin @cbind $ = scroll horizontal end @cbind = scroll vertical end -- cgit v1.2.3 From c98f8cc6e624a8490a535abedca7e72c1df8bb38 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 10 Oct 2010 04:14:42 +0800 Subject: Add the same duality for pasting a url as others It changes gY's meaning, but it better matches with go/gO and friends. --- examples/config/config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index d927b27..925f59b 100644 --- a/examples/config/config +++ b/examples/config/config @@ -309,7 +309,8 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gN = event NEW_TAB_NEXT @cbind go_ = event NEW_TAB %s @cbind gO_ = event NEW_TAB_NEXT %s -@cbind gY = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' # Closing / resting @cbind gC = exit -- cgit v1.2.3 From 53529705078bafe6ee2f719110525c11f2e4952b Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 11 Oct 2010 12:24:57 -0600 Subject: fix formfiller dmenu scheme --- examples/data/scripts/util/dmenu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 757e5cd..f789178 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -12,7 +12,7 @@ case "$DMENU_SCHEME" in # Formfiller "formfiller" ) NB="#0f0f0f" - NF="4e7093" + NF="#4e7093" SB="#003d7c" SF="#3a9bff" ;; -- cgit v1.2.3 From 2ab821580e64408dd290c97aac9d80733979d856 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Thu, 30 Sep 2010 09:51:10 -0600 Subject: uzbl-cookie-daemon: maintain persistent connections to uzbl instances --- examples/data/scripts/uzbl-cookie-daemon | 44 ++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/uzbl-cookie-daemon b/examples/data/scripts/uzbl-cookie-daemon index ed88de4..0b9bef9 100755 --- a/examples/data/scripts/uzbl-cookie-daemon +++ b/examples/data/scripts/uzbl-cookie-daemon @@ -436,18 +436,26 @@ class CookieMonster: daemon_timeout = config['daemon_timeout'] echo("listening on %r" % config['cookie_socket']) + connections = [] + while self._running: # This line tells the socket how many pending incoming connections # to enqueue at once. Raising this number may or may not increase # performance. self.server_socket.listen(1) - if bool(select.select([self.server_socket], [], [], 1)[0]): - client_socket, _ = self.server_socket.accept() - self.handle_request(client_socket) + r, w, x = select.select([self.server_socket]+connections, [], [], 1) + + for socket in r: + if self.server_socket == socket: + client_socket, _ = socket.accept() + connections.append(client_socket) + else: + if not self.handle_request(socket): + # connection was closed, forget about the client socket + connections.remove(socket) + self.last_request = time.time() - client_socket.close() - continue if daemon_timeout: # Checks if the daemon has been idling for too long. @@ -462,7 +470,7 @@ class CookieMonster: # Receive cookie request from client. data = client_socket.recv(8192) if not data: - return + return False # Cookie argument list in packet is null separated. argv = data.split("\0") @@ -471,17 +479,17 @@ class CookieMonster: # Catch the EXIT command sent to kill running daemons. if action == "EXIT": self._running = False - return + return False # Catch whitelist RELOAD command. elif action == "RELOAD": self.reload_whitelist() - return + return True # Return if command unknown. elif action not in ['GET', 'PUT']: error("unknown command %r." % argv) - return + return True # Determine whether or not to print cookie data to terminal. print_cookie = (config['verbose'] and not config['daemon_mode']) @@ -499,13 +507,14 @@ class CookieMonster: req = urllib2.Request(uri) if action == "GET": - self.jar.add_cookie_header(req) - if req.has_header('Cookie'): - cookie = req.get_header('Cookie') - client_socket.send(cookie) - if print_cookie: - print cookie - + self.jar._policy._now = self._now = int(time.time()) + cookies = self.jar._cookies_for_request(req) + attrs = self.jar._cookie_attrs(cookies) + if attrs: + cookie = "; ".join(attrs) + client_socket.send(cookie) + if print_cookie: + print cookie else: client_socket.send("\0") @@ -515,10 +524,13 @@ class CookieMonster: print cookie self.put_cookie(req, cookie) + client_socket.send("\0") if print_cookie: print + return True + def put_cookie(self, req, cookie=None): '''Put a cookie in the cookie jar.''' -- cgit v1.2.3 From 87b0c1fde07859f01424eea1abde930ad91b151e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 10 Oct 2010 22:50:53 -0400 Subject: Use SCROLL_VERT event to handle scroll percentage --- examples/config/config | 3 +++ src/uzbl-core.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 622f859..5656664 100644 --- a/examples/config/config +++ b/examples/config/config @@ -79,6 +79,9 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # Example CONFIG_CHANGED event handler #@on_event CONFIG_CHANGED print Config changed: %1 = %2 +# Scroll percentage calculation +@on_event SCROLL_VERT set scroll_message = \@<(function(){var a='%1'.split(' ');var p='--';if(a[2]!=a[1]){p=(a[0]/(a[2]-a[3]));p=Math.round(10000*p)/100;};return p+'%';})()>\@ + # === Behaviour and appearance =============================================== set show_status = 1 diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 4ced7af..fdfb811 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -2635,8 +2635,8 @@ main (int argc, char* argv[]) { NULL); g_object_connect((GObject*)uzbl.gui.bar_h, - "signal::value-changed", (GCallback)scroll_horiz_cb, NULL, - "signal::changed", (GCallback)scroll_vert_cb, NULL, + "signal::value-changed", (GCallback)scroll_horiz_cb, NULL, + "signal::changed", (GCallback)scroll_horiz_cb, NULL, NULL); if(!uzbl.state.instance_name) -- cgit v1.2.3 From 9bea9618424093c6d2cc93954f4cbdd0be4b7637 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 29 Oct 2010 21:49:38 -0600 Subject: add uzbl-cookie-manager --- Makefile | 18 ++-- examples/uzbl-cookie-manager.c | 211 +++++++++++++++++++++++++++++++++++++++++ src/util.c | 2 +- 3 files changed, 222 insertions(+), 9 deletions(-) create mode 100644 examples/uzbl-cookie-manager.c (limited to 'examples') diff --git a/Makefile b/Makefile index 5287d5c..2a08b5c 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SRC = $(wildcard src/*.c) HEAD = $(wildcard src/*.h) OBJ = $(foreach obj, $(SRC:.c=.o), $(notdir $(obj))) -all: uzbl-browser +all: uzbl-browser uzbl-cookie-manager VPATH:=src @@ -24,7 +24,11 @@ uzbl-core: ${OBJ} @echo -e "\n${CC} -o $@ ${OBJ} ${LDFLAGS}" @${CC} -o $@ ${OBJ} ${LDFLAGS} -uzbl-browser: uzbl-core +uzbl-cookie-manager: examples/uzbl-cookie-manager.o src/util.o + @echo -e "\n${CC} -o $@ uzbl-cookie-manager.o util.o ${LDFLAGS}" + @${CC} -o $@ uzbl-cookie-manager.o util.o ${LDFLAGS} + +uzbl-browser: uzbl-core uzbl-cookie-manager # packagers, set DESTDIR to your "package directory" and PREFIX to the prefix you want to have on the end-user system # end-users who build from source: don't care about DESTDIR, update PREFIX if you want to @@ -72,10 +76,8 @@ test-uzbl-browser-sandbox: uzbl-browser clean: rm -f uzbl-core - rm -f uzbl-core.o - rm -f events.o - rm -f callbacks.o - rm -f inspector.o + rm -f uzbl-cookie-manager + rm -f *.o find ./examples/ -name "*.pyc" -delete cd ./tests/; $(MAKE) clean rm -rf ./sandbox/ @@ -104,9 +106,9 @@ install-uzbl-core: all install-dirs rm $(INSTALLDIR)/share/uzbl/examples/config/config.bak install -m755 uzbl-core $(INSTALLDIR)/bin/uzbl-core -install-uzbl-browser: install-dirs +install-uzbl-browser: uzbl-cookie-manager install-dirs install -m755 src/uzbl-browser $(INSTALLDIR)/bin/uzbl-browser - install -m755 examples/data/scripts/uzbl-cookie-daemon $(INSTALLDIR)/bin/uzbl-cookie-daemon + install -m755 uzbl-cookie-manager $(INSTALLDIR)/bin/uzbl-cookie-manager install -m755 examples/data/scripts/uzbl-event-manager $(INSTALLDIR)/bin/uzbl-event-manager mv $(INSTALLDIR)/bin/uzbl-browser{,.bak} sed 's#^PREFIX=.*#PREFIX=$(RUN_PREFIX)#' < $(INSTALLDIR)/bin/uzbl-browser.bak > $(INSTALLDIR)/bin/uzbl-browser diff --git a/examples/uzbl-cookie-manager.c b/examples/uzbl-cookie-manager.c new file mode 100644 index 0000000..b873aeb --- /dev/null +++ b/examples/uzbl-cookie-manager.c @@ -0,0 +1,211 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "../src/util.h" + +extern const XDG_Var XDG[]; + +int verbose = 0; + +#define SOCK_BACKLOG 10 +#define MAX_COOKIE_LENGTH 4096 + +char cookie_buffer[MAX_COOKIE_LENGTH]; + +int setup_socket(const char *cookied_socket_path) { + int socket_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); + + if(socket_fd < 0) { + fprintf(stderr, "socket failed (%s)\n", strerror(errno)); + return -1; + } + + struct sockaddr_un sa; + sa.sun_family = AF_UNIX; + strcpy(sa.sun_path, cookied_socket_path); + + if(bind(socket_fd, (struct sockaddr*)&sa, sizeof(sa)) < 0) { + fprintf(stderr, "bind failed (%s)\n", strerror(errno)); + return -1; + } + + if(listen(socket_fd, SOCK_BACKLOG) < 0) { + fprintf(stderr, "listen failed (%s)\n", strerror(errno)); + return -1; + } + + return socket_fd; +} + +void handle_request(SoupCookieJar *j, const char *buff, int len, int fd) { + const char *command = buff; + + const char *scheme = command + strlen(command) + 1; + if((scheme - buff) > len) { + fprintf(stderr, "got malformed or partial request\n"); + return; + } + + const char *host = scheme + strlen(scheme) + 1; + if((host - buff) > len) { + fprintf(stderr, "got malformed or partial request\n"); + return; + } + + const char *path = host + strlen(host) + 1; + if((path - buff) > len) { + fprintf(stderr, "got malformed or partial request\n"); + return; + } + + /* glue the parts back together into a SoupURI */ + char *u = g_strconcat(scheme, "://", host, path, NULL); + if(verbose) printf("%s %s\n", command, u); + SoupURI *uri = soup_uri_new(u); + g_free(u); + + if(!strcmp(command, "GET")) { + char *result = soup_cookie_jar_get_cookies(j, uri, TRUE); + if(result) { + if(verbose) puts(result); + if(write(fd, result, strlen(result)+1) < 0) + fprintf(stderr, "write failed (%s)", strerror(errno)); + + g_free(result); + } else { + if(verbose) puts("-"); + if(write(fd, "", 1) < 0) + fprintf(stderr, "write failed (%s)", strerror(errno)); + } + } else if(!strcmp(command, "PUT")) { + const char *name_and_val = path + strlen(path) + 1; + if((name_and_val - buff) > len) { + fprintf(stderr, "got malformed or partial request\n"); + return; + } + + if(verbose) puts(name_and_val); + + char *eql = strchr(name_and_val, '='); + eql[0] = 0; + + const char *name = name_and_val; + const char *value = eql + 1; + + SoupCookie *cookie = soup_cookie_new(name, value, host, path, SOUP_COOKIE_MAX_AGE_ONE_YEAR); + + soup_cookie_jar_add_cookie(j, cookie); + + if(write(fd, "", 1) < 0) + fprintf(stderr, "write failed (%s)", strerror(errno)); + } + + soup_uri_free(uri); +} + +void usage(const char *progname) { + printf("%s [-s socket-path] [-f cookies.txt] [-w whitelist-file] [-v]\n", progname); +} + +int main(int argc, char *argv[]) { + int i; + + const char *cookies_txt_path = NULL; + const char *cookied_socket_path = NULL; + + for(i = 1; i < argc && argv[i][0] == '-'; i++) { + switch(argv[i][1]) { + case 's': + cookied_socket_path = argv[++i]; + break; + case 'f': + cookies_txt_path = argv[++i]; + break; + case 'v': + verbose = 1; + break; + default: + usage(argv[0]); + return 1; + } + } + + if(!cookies_txt_path) + cookies_txt_path = find_xdg_file(1, "/uzbl/cookies.txt"); + + if(!cookied_socket_path) + cookied_socket_path = g_strconcat(get_xdg_var(XDG[2]), "/uzbl/cookie_daemon_socket", NULL); + + g_type_init(); + + SoupCookieJar *j = soup_cookie_jar_text_new(cookies_txt_path, FALSE); + + int cookie_socket = setup_socket(cookied_socket_path); + if(cookie_socket < 0) { + return 1; + } + + GArray *connections = g_array_new (FALSE, FALSE, sizeof (int)); + + while(1) { + unsigned int i; + int r; + fd_set fs; + + int maxfd = cookie_socket; + FD_ZERO(&fs); + FD_SET(maxfd, &fs); + + for(i = 0; i < connections->len; i++) { + int fd = g_array_index(connections, int, i); + if(fd > maxfd) maxfd = fd; + FD_SET(fd, &fs); + } + + r = select(maxfd+1, &fs, NULL, NULL, NULL); + if(r < 0) { + fprintf(stderr, "select failed (%s)\n", strerror(errno)); + continue; + } + + if(FD_ISSET(cookie_socket, &fs)) { + /* handle new connection */ + int fd = accept(cookie_socket, NULL, NULL); + g_array_append_val(connections, fd); + if(verbose) puts("got connection."); + } + + for(i = 0; i < connections->len; i++) { + /* handle activity on a connection */ + int fd = g_array_index(connections, int, i); + if(FD_ISSET(fd, &fs)) { + r = read(fd, cookie_buffer, MAX_COOKIE_LENGTH); + if(r < 0) { + fprintf(stderr, "read failed (%s)\n", strerror(errno)); + continue; + } else if(r == 0) { + if(verbose) puts("client hung up."); + g_array_remove_index(connections, i); + i--; /* other elements in the array are moved down to fill the gap */ + continue; + } + cookie_buffer[r] = 0; + + handle_request(j, cookie_buffer, r, fd); + } + } + } + + return 0; +} diff --git a/src/util.c b/src/util.c index f6c2e0a..54d1d02 100644 --- a/src/util.c +++ b/src/util.c @@ -6,7 +6,7 @@ #include "util.h" -XDG_Var XDG[] = +const XDG_Var XDG[] = { { "XDG_CONFIG_HOME", "~/.config" }, { "XDG_DATA_HOME", "~/.local/share" }, -- cgit v1.2.3 From b19783544927c6f27a9224f1287c6faaf4993c5d Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 5 Nov 2010 10:29:46 -0600 Subject: add optional whitelist --- examples/uzbl-cookie-manager.c | 140 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/uzbl-cookie-manager.c b/examples/uzbl-cookie-manager.c index b873aeb..7684fb3 100644 --- a/examples/uzbl-cookie-manager.c +++ b/examples/uzbl-cookie-manager.c @@ -1,6 +1,10 @@ +#define _POSIX_SOURCE + #include #include #include +#include +#include #include #include @@ -8,6 +12,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -48,6 +56,82 @@ int setup_socket(const char *cookied_socket_path) { return socket_fd; } +const char *whitelist_path = NULL; +GPtrArray *whitelisted_hosts = NULL; +time_t whitelist_update_time = 0; + +void whitelist_line_cb(const gchar* line, void *user_data) { + (void) user_data; + + gchar *norm_host; + + const gchar *p = line; + while(isspace(*p)) + p++; + + if(p[0] == '#' || !p[0]) /* ignore comments and blank lines */ + return; + + if(p[0] == '.') + norm_host = g_strdup(p); + else + norm_host = g_strconcat(".", p, NULL); + + g_ptr_array_add(whitelisted_hosts, g_strchomp(norm_host)); +} + +gboolean load_whitelist(const char *whitelist_path) { + if(!file_exists(whitelist_path)) + return FALSE; + + /* check if the whitelist file was updated */ + struct stat f; + if(stat(whitelist_path, &f) < 0) + return FALSE; + + if(whitelisted_hosts == NULL) + whitelisted_hosts = g_ptr_array_new(); + + if(f.st_mtime > whitelist_update_time) { + /* the file was updated, reload the whitelist */ + if(verbose) puts("reloading whitelist"); + while(whitelisted_hosts->len > 0) { + g_free(g_ptr_array_index(whitelisted_hosts, 0)); + g_ptr_array_remove_index_fast(whitelisted_hosts, 0); + } + for_each_line_in_file(whitelist_path, whitelist_line_cb, NULL); + whitelist_update_time = f.st_mtime; + } + + return TRUE; +} + +gboolean should_save_cookie(const char *host) { + if(!load_whitelist(whitelist_path)) + return TRUE; /* some error with the file, assume no whitelist */ + + /* we normalize the hostname so it has a . in front like the whitelist entries */ + gchar *test_host = (host[0] == '.') ? g_strdup(host) : g_strconcat(".", host, NULL); + int hl = strlen(test_host); + + /* test against each entry in the whitelist */ + gboolean result = FALSE; + guint i; + for(i = 0; i < whitelisted_hosts->len; i++) { + /* a match means the host ends with (or is equal to) the whitelist entry */ + const gchar *entry = g_ptr_array_index(whitelisted_hosts, i); + int el = strlen(entry); + result = (el <= hl) && !strcmp(test_host + (hl - el), entry); + + if(result) + break; + } + + g_free(test_host); + + return result; +} + void handle_request(SoupCookieJar *j, const char *buff, int len, int fd) { const char *command = buff; @@ -97,15 +181,18 @@ void handle_request(SoupCookieJar *j, const char *buff, int len, int fd) { if(verbose) puts(name_and_val); - char *eql = strchr(name_and_val, '='); - eql[0] = 0; + if(should_save_cookie(host)) { + char *eql = strchr(name_and_val, '='); + eql[0] = 0; - const char *name = name_and_val; - const char *value = eql + 1; + const char *name = name_and_val; + const char *value = eql + 1; - SoupCookie *cookie = soup_cookie_new(name, value, host, path, SOUP_COOKIE_MAX_AGE_ONE_YEAR); + SoupCookie *cookie = soup_cookie_new(name, value, host, path, SOUP_COOKIE_MAX_AGE_ONE_YEAR); - soup_cookie_jar_add_cookie(j, cookie); + soup_cookie_jar_add_cookie(j, cookie); + } else if(verbose) + puts("no, blacklisted."); if(write(fd, "", 1) < 0) fprintf(stderr, "write failed (%s)", strerror(errno)); @@ -118,11 +205,20 @@ void usage(const char *progname) { printf("%s [-s socket-path] [-f cookies.txt] [-w whitelist-file] [-v]\n", progname); } +const char *pid_file_path = NULL; +const char *cookied_socket_path = NULL; + +void cleanup_after_signal(int signal) { + (void) signal; + unlink(pid_file_path); + unlink(cookied_socket_path); + exit(0); +} + int main(int argc, char *argv[]) { int i; const char *cookies_txt_path = NULL; - const char *cookied_socket_path = NULL; for(i = 1; i < argc && argv[i][0] == '-'; i++) { switch(argv[i][1]) { @@ -132,6 +228,9 @@ int main(int argc, char *argv[]) { case 'f': cookies_txt_path = argv[++i]; break; + case 'w': + whitelist_path = argv[++i]; + break; case 'v': verbose = 1; break; @@ -142,17 +241,40 @@ int main(int argc, char *argv[]) { } if(!cookies_txt_path) - cookies_txt_path = find_xdg_file(1, "/uzbl/cookies.txt"); + cookies_txt_path = g_strconcat(get_xdg_var(XDG[1]), "/uzbl/cookies.txt", NULL); if(!cookied_socket_path) cookied_socket_path = g_strconcat(get_xdg_var(XDG[2]), "/uzbl/cookie_daemon_socket", NULL); + if(!whitelist_path) + whitelist_path = g_strconcat(get_xdg_var(XDG[0]), "/uzbl/cookie_whitelist", NULL); + + pid_file_path = g_strconcat(cookied_socket_path, ".pid", NULL); + int fd = open(pid_file_path, O_WRONLY|O_CREAT|O_EXCL, 0600); + if(fd < 0) { + if(errno == EEXIST) + fprintf(stderr, "pid file %s exists, exiting\n", pid_file_path); + else + fprintf(stderr, "couldn't open pid file %s (%s)\n", pid_file_path, strerror(errno)); + return 1; + } + + //grar grar grar + //fprintf(fd, "%d\n", getpid()); + close(fd); + g_type_init(); SoupCookieJar *j = soup_cookie_jar_text_new(cookies_txt_path, FALSE); int cookie_socket = setup_socket(cookied_socket_path); - if(cookie_socket < 0) { + if(cookie_socket < 0) + return 1; + + struct sigaction sa; + sa.sa_handler = cleanup_after_signal; + if(sigaction(SIGINT, &sa, NULL) || sigaction(SIGTERM, &sa, NULL)) { + fprintf(stderr, "sigaction failed (%s)\n", strerror(errno)); return 1; } -- cgit v1.2.3 From 4c745b7b4f7020a32a08760dad2fab0b9249094e Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 13 Nov 2010 09:44:05 -0700 Subject: daemonise. --- examples/uzbl-cookie-manager.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/uzbl-cookie-manager.c b/examples/uzbl-cookie-manager.c index 7684fb3..16ca196 100644 --- a/examples/uzbl-cookie-manager.c +++ b/examples/uzbl-cookie-manager.c @@ -202,7 +202,26 @@ void handle_request(SoupCookieJar *j, const char *buff, int len, int fd) { } void usage(const char *progname) { - printf("%s [-s socket-path] [-f cookies.txt] [-w whitelist-file] [-v]\n", progname); + printf("%s [-s socket-path] [-f cookies.txt] [-w whitelist-file] [-n] [-v]\n", progname); + puts("\t-n\tdon't daemonise the process"); + puts("\t-v\tbe verbose"); +} + +void daemonise() { + int r = fork(); + + if(r < 0) { + fprintf(stderr, "fork failed (%s)", strerror(errno)); + exit(1); + } else if (r > 0) { + /* this is the parent, which has done its job */ + exit(0); + } + + if(setsid() < 0) { + fprintf(stderr, "setsid failed (%s)", strerror(errno)); + exit(1); + } } const char *pid_file_path = NULL; @@ -219,6 +238,7 @@ int main(int argc, char *argv[]) { int i; const char *cookies_txt_path = NULL; + gboolean foreground = FALSE; for(i = 1; i < argc && argv[i][0] == '-'; i++) { switch(argv[i][1]) { @@ -231,6 +251,9 @@ int main(int argc, char *argv[]) { case 'w': whitelist_path = argv[++i]; break; + case 'n': + foreground = TRUE; + break; case 'v': verbose = 1; break; @@ -240,6 +263,12 @@ int main(int argc, char *argv[]) { } } + if(verbose) + foreground = TRUE; + + if(!foreground) + daemonise(); + if(!cookies_txt_path) cookies_txt_path = g_strconcat(get_xdg_var(XDG[1]), "/uzbl/cookies.txt", NULL); @@ -278,6 +307,13 @@ int main(int argc, char *argv[]) { return 1; } + if(!foreground) { + /* close STDIO */ + close(0); + close(1); + close(2); + } + GArray *connections = g_array_new (FALSE, FALSE, sizeof (int)); while(1) { -- cgit v1.2.3 From 94a7ef21e4036407fa800567766e20957e8d55ae Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 13 Nov 2010 10:23:37 -0700 Subject: lock the pid file to prevent multiple instances of uzbl-cookie-manager --- examples/uzbl-cookie-manager.c | 141 +++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 63 deletions(-) (limited to 'examples') diff --git a/examples/uzbl-cookie-manager.c b/examples/uzbl-cookie-manager.c index 16ca196..133a857 100644 --- a/examples/uzbl-cookie-manager.c +++ b/examples/uzbl-cookie-manager.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -32,6 +33,9 @@ int verbose = 0; char cookie_buffer[MAX_COOKIE_LENGTH]; int setup_socket(const char *cookied_socket_path) { + /* delete the cookie socket if it was left behind on a previous run */ + unlink(cookied_socket_path); + int socket_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); if(socket_fd < 0) { @@ -201,6 +205,60 @@ void handle_request(SoupCookieJar *j, const char *buff, int len, int fd) { soup_uri_free(uri); } +void +wait_for_things_to_happen_and_then_do_things(SoupCookieJar* j, int cookie_socket) { + GArray *connections = g_array_new (FALSE, FALSE, sizeof (int)); + + while(1) { + unsigned int i; + int r; + fd_set fs; + + int maxfd = cookie_socket; + FD_ZERO(&fs); + FD_SET(maxfd, &fs); + + for(i = 0; i < connections->len; i++) { + int fd = g_array_index(connections, int, i); + if(fd > maxfd) maxfd = fd; + FD_SET(fd, &fs); + } + + r = select(maxfd+1, &fs, NULL, NULL, NULL); + if(r < 0) { + fprintf(stderr, "select failed (%s)\n", strerror(errno)); + continue; + } + + if(FD_ISSET(cookie_socket, &fs)) { + /* handle new connection */ + int fd = accept(cookie_socket, NULL, NULL); + g_array_append_val(connections, fd); + if(verbose) puts("got connection."); + } + + for(i = 0; i < connections->len; i++) { + /* handle activity on a connection */ + int fd = g_array_index(connections, int, i); + if(FD_ISSET(fd, &fs)) { + r = read(fd, cookie_buffer, MAX_COOKIE_LENGTH); + if(r < 0) { + fprintf(stderr, "read failed (%s)\n", strerror(errno)); + continue; + } else if(r == 0) { + if(verbose) puts("client hung up."); + g_array_remove_index(connections, i); + i--; /* other elements in the array are moved down to fill the gap */ + continue; + } + cookie_buffer[r] = 0; + + handle_request(j, cookie_buffer, r, fd); + } + } + } +} + void usage(const char *progname) { printf("%s [-s socket-path] [-f cookies.txt] [-w whitelist-file] [-n] [-v]\n", progname); puts("\t-n\tdon't daemonise the process"); @@ -278,27 +336,25 @@ int main(int argc, char *argv[]) { if(!whitelist_path) whitelist_path = g_strconcat(get_xdg_var(XDG[0]), "/uzbl/cookie_whitelist", NULL); + /* write out and lock the pid file. + * this ensures that only one uzbl-cookie-manager is running per-socket. + * (we should probably also lock the cookies.txt to prevent accidents...) */ pid_file_path = g_strconcat(cookied_socket_path, ".pid", NULL); - int fd = open(pid_file_path, O_WRONLY|O_CREAT|O_EXCL, 0600); - if(fd < 0) { - if(errno == EEXIST) - fprintf(stderr, "pid file %s exists, exiting\n", pid_file_path); - else - fprintf(stderr, "couldn't open pid file %s (%s)\n", pid_file_path, strerror(errno)); + int lockfd = open(pid_file_path, O_RDWR|O_CREAT, 0600); + if(lockfd < 0) { + fprintf(stderr, "couldn't open pid file %s (%s)\n", pid_file_path, strerror(errno)); return 1; } - //grar grar grar - //fprintf(fd, "%d\n", getpid()); - close(fd); - - g_type_init(); - - SoupCookieJar *j = soup_cookie_jar_text_new(cookies_txt_path, FALSE); - - int cookie_socket = setup_socket(cookied_socket_path); - if(cookie_socket < 0) + if(flock(lockfd, LOCK_EX|LOCK_NB) < 0) { + fprintf(stderr, "couldn't lock pid file %s (%s)\n", pid_file_path, strerror(errno)); + fprintf(stderr, "uzbl-cookie-manager is probably already running\n"); return 1; + } + + gchar* pids = g_strdup_printf("%d\n", getpid()); + write(lockfd, pids, strlen(pids)); + g_free(pids); struct sigaction sa; sa.sa_handler = cleanup_after_signal; @@ -314,56 +370,15 @@ int main(int argc, char *argv[]) { close(2); } - GArray *connections = g_array_new (FALSE, FALSE, sizeof (int)); - - while(1) { - unsigned int i; - int r; - fd_set fs; - - int maxfd = cookie_socket; - FD_ZERO(&fs); - FD_SET(maxfd, &fs); - - for(i = 0; i < connections->len; i++) { - int fd = g_array_index(connections, int, i); - if(fd > maxfd) maxfd = fd; - FD_SET(fd, &fs); - } - - r = select(maxfd+1, &fs, NULL, NULL, NULL); - if(r < 0) { - fprintf(stderr, "select failed (%s)\n", strerror(errno)); - continue; - } + g_type_init(); - if(FD_ISSET(cookie_socket, &fs)) { - /* handle new connection */ - int fd = accept(cookie_socket, NULL, NULL); - g_array_append_val(connections, fd); - if(verbose) puts("got connection."); - } + SoupCookieJar *j = soup_cookie_jar_text_new(cookies_txt_path, FALSE); - for(i = 0; i < connections->len; i++) { - /* handle activity on a connection */ - int fd = g_array_index(connections, int, i); - if(FD_ISSET(fd, &fs)) { - r = read(fd, cookie_buffer, MAX_COOKIE_LENGTH); - if(r < 0) { - fprintf(stderr, "read failed (%s)\n", strerror(errno)); - continue; - } else if(r == 0) { - if(verbose) puts("client hung up."); - g_array_remove_index(connections, i); - i--; /* other elements in the array are moved down to fill the gap */ - continue; - } - cookie_buffer[r] = 0; + int cookie_socket = setup_socket(cookied_socket_path); + if(cookie_socket < 0) + return 1; - handle_request(j, cookie_buffer, r, fd); - } - } - } + wait_for_things_to_happen_and_then_do_things(j, cookie_socket); return 0; } -- cgit v1.2.3 From ba159dbb277adf7532e4e2f09dcfa461084c9455 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 15 Nov 2010 10:19:12 -0700 Subject: source -> . (fixes bashism) --- examples/data/scripts/download.sh | 4 ++-- examples/data/scripts/formfiller.sh | 8 ++++---- examples/data/scripts/history.sh | 2 +- examples/data/scripts/insert_bookmark.sh | 2 +- examples/data/scripts/instance-select-wmii.sh | 2 +- examples/data/scripts/load_url_from_bookmarks.sh | 6 +++--- examples/data/scripts/load_url_from_history.sh | 6 +++--- examples/data/scripts/session.sh | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 7375535..606aa62 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -2,8 +2,8 @@ # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/uzbl-args.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh # Some sites block the default wget --user-agent.. GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 6982f9a..b2e61ec 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -43,10 +43,10 @@ DMENU_LINES="3" DMENU_PROMPT="Choose profile" DMENU_OPTIONS="vertical resize" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/editor.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/dmenu.sh +. $UZBL_UTIL_DIR/editor.sh +. $UZBL_UTIL_DIR/uzbl-args.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh RAND=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c 1-5) MODELINE="> vim:ft=formfiller" diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index b91d415..b8a15e0 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -1,6 +1,6 @@ #!/bin/sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh [ -w "$UZBL_HISTORY_FILE" ] || exit 1 diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index acef37e..bd6f1bd 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,6 +1,6 @@ #!/bin/sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh [ -d "$UZBL_DATA_DIR" ] || exit 1 [ -w "$UZBL_BOOKMARKS_FILE" ] || exit 1 diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index e70a143..19d04e8 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -13,7 +13,7 @@ DMENU_SCHEME="wmii" -source $UZBL_UTIL_DIR/dmenu.sh +. $UZBL_UTIL_DIR/dmenu.sh case "$1" in "list" ) diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 564c3f8..9af83c3 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -5,9 +5,9 @@ DMENU_SCHEME="bookmarks" DMENU_OPTIONS="xmms vertical resize" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/dmenu.sh +. $UZBL_UTIL_DIR/uzbl-args.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index d094625..1f540c9 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -3,9 +3,9 @@ DMENU_SCHEME="history" DMENU_OPTIONS="xmms vertical resize" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/dmenu.sh +. $UZBL_UTIL_DIR/uzbl-args.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_HISTORY_FILE" ] || exit 1 diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 89eeb7a..046ad64 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -8,8 +8,8 @@ # and doesn't need to be called manually at any point. # Add a line like 'bind quit = /path/to/session.sh endsession' to your config -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +. $UZBL_UTIL_DIR/uzbl-args.sh +. $UZBL_UTIL_DIR/uzbl-dir.sh [ -d $UZBL_DATA_DIR ] || exit 1 -- cgit v1.2.3 From bf26eec507fed8524368e523eadc5b798a40e870 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 20 Nov 2010 11:08:55 -0700 Subject: fix busy loop in uzbl-tabbed after closing a tab this is triggered by having a handler for SIGCHLD. using gobject.spawn_async instead of subprocess.Popen means we don't need a SIGCHLD handler to reap dead children. --- examples/data/scripts/uzbl-tabbed | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed index 42837d3..9e5d715 100755 --- a/examples/data/scripts/uzbl-tabbed +++ b/examples/data/scripts/uzbl-tabbed @@ -158,7 +158,7 @@ import atexit import types from gobject import io_add_watch, source_remove, timeout_add, IO_IN, IO_HUP -from signal import signal, SIGTERM, SIGINT, SIGCHLD +from signal import signal, SIGTERM, SIGINT from optparse import OptionParser, OptionGroup from traceback import print_exc @@ -536,7 +536,6 @@ class UzblTabbed: self._timers = {} self._buffer = "" self._killed = False - self._processes = [] # A list of the recently closed tabs self._closed = [] @@ -656,9 +655,6 @@ class UzblTabbed: # Catch keyboard interrupts signal(SIGINT, lambda signum, stack_frame: self.terminate(SIGINT)) - # Catch SIGCHLD - signal(SIGCHLD, lambda signum, stack_frame: self.join_children()) - try: gtk.main() @@ -678,15 +674,6 @@ class UzblTabbed: raise - - def join_children(self): - '''Find and remove zombie children processes.''' - - for p in self._processes: - if p.poll() is not None: - self._processes.remove(p) - - def terminate(self, termsig=None): '''Handle termination signals and exit safely and cleanly.''' @@ -1017,7 +1004,7 @@ class UzblTabbed: cmd = ['uzbl-browser', '-n', name, '-s', str(sid), '--connect-socket', self.socket_path, '--uri', uri] - self._processes += [subprocess.Popen(cmd)] # TODO: do i need close_fds=True ? + gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) uzbl = UzblInstance(self, tab, name, uri, title, switch) SocketClient.instances_queue[name] = uzbl -- cgit v1.2.3 From 79bef7119a93081032e9a8f80c9f556c7d850467 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 20 Nov 2010 20:55:49 -0700 Subject: follow.js support for button elements (thanks Kirikaza) --- examples/data/scripts/follow.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index eacd52f..3a18b1b 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -127,29 +127,19 @@ function clickElem(item) { removeAllHints(); if (item) { var name = item.tagName; - if (name == 'A') { + if (name == 'BUTTON') { item.click(); - window.location = item.href; - return "XXXRESET_MODEXXX"; } else if (name == 'INPUT') { - var type; - try { - type = item.getAttribute('type').toUpperCase(); - } catch(err) { - type = 'TEXT'; - } + var type = item.type.toUpperCase(); if (type == 'TEXT' || type == 'SEARCH' || type == 'PASSWORD') { item.focus(); item.select(); - return "XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); - return "XXXRESET_MODEXXX"; } } else if (name == 'TEXTAREA' || name == 'SELECT') { item.focus(); item.select(); - return "XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); window.location = item.href; @@ -175,7 +165,7 @@ function addFormElems() { for (var f = 0; f < forms.length; f++) { for (var e = 0; e < forms[f].elements.length; e++) { var el = forms[f].elements[e]; - if (el && ['INPUT', 'TEXTAREA', 'SELECT'].indexOf(el.tagName) + 1 && isVisible(el) && elementInViewport(el)) { + if (el && ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'].indexOf(el.tagName) + 1 && isVisible(el) && elementInViewport(el)) { res[0].push(el); } } -- cgit v1.2.3 From bb1153c9bc776d0c0dde44bcc055d40c7617a998 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sun, 21 Nov 2010 23:12:48 -0700 Subject: write new history and bookmark files if they don't already exist --- examples/data/scripts/history.sh | 2 +- examples/data/scripts/insert_bookmark.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index b91d415..0cd2218 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -2,6 +2,6 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh -[ -w "$UZBL_HISTORY_FILE" ] || exit 1 +[ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1 echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $UZBL_HISTORY_FILE diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 18f643f..08d7d2b 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -3,7 +3,7 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh [ -d "$UZBL_DATA_DIR" ] || exit 1 -[ -w "$UZBL_BOOKMARKS_FILE" ] || exit 1 +[ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity &>/dev/null || exit 2 # replace tabs, they are pointless in titles and we want to use tabs as delimiter. -- cgit v1.2.3 From e660b9de3f4331ebf171735b40eb12105218b2d7 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sun, 21 Nov 2010 23:15:02 -0700 Subject: set UZBL_UTIL_DIR in uzbl-browser, get rid of the scripts_util_dir variable --- examples/config/config | 1 - src/uzbl-browser | 18 +++++++++++++++++- src/uzbl-core.c | 27 --------------------------- src/uzbl-core.h | 3 --- 4 files changed, 17 insertions(+), 32 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 847b4af..1457c71 100644 --- a/examples/config/config +++ b/examples/config/config @@ -35,7 +35,6 @@ set set_status = set status_message = # Spawn path shortcuts. In spawn the first dir+path match is used in "dir1:dir2:dir3:executable" set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scripts -set scripts_util_dir = @scripts_dir/util # === Hardcoded handlers ===================================================== diff --git a/src/uzbl-browser b/src/uzbl-browser index de4f7af..865447c 100755 --- a/src/uzbl-browser +++ b/src/uzbl-browser @@ -10,6 +10,8 @@ # But this shouldn't cause much problems.. PREFIX=/usr/local +EXAMPLES=$PREFIX/share/uzbl/examples + if [ -z "$XDG_DATA_HOME" ] then export XDG_DATA_HOME=$HOME/.local/share @@ -40,13 +42,27 @@ done # if no config exists yet in the recommended location, put the default (recommended) config there if [ ! -f $XDG_CONFIG_HOME/uzbl/config ] then - if ! cp $PREFIX/share/uzbl/examples/config/config $XDG_CONFIG_HOME/uzbl/config + if ! cp "$EXAMPLES"/config/config $XDG_CONFIG_HOME/uzbl/config then echo "Could not copy default config to $XDG_CONFIG_HOME/uzbl/config" >&2 exit 3 fi fi +# this variable is used by the default helper scripts as a location to +# load shared code from +if [ -z "$UZBL_UTIL_DIR" ] +then + if [ -d "$XDG_DATA_HOME"/uzbl/scripts/util ] + then + UZBL_UTIL_DIR=$XDG_DATA_HOME/uzbl/scripts/util + elif [ -d $EXAMPLES/data/scripts/util ] + then + UZBL_UTIL_DIR=$EXAMPLES/data/scripts/util + fi + export UZBL_UTIL_DIR +fi + # Uncomment this for a slight speedup at the expense of not having # stale cookie daemon sockets cleaned up. #if [ ! -S $XDG_CACHE_HOME/uzbl/cookie_daemon_socket ] diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 13328d0..fd589c0 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -1263,29 +1263,6 @@ sharg_append(GArray *a, const gchar *str) { g_array_append_val(a, s); } -gboolean -uzbl_setup_environ() { - gchar *util_dirs = expand("@scripts_util_dir", 0); - gchar *util_dir = NULL; - gboolean succeed = FALSE; - - if(!util_dirs) { - g_free(util_dirs); - return succeed; - } - - if(!(util_dir = find_existing_file(util_dirs))) { - g_free(util_dirs); - return succeed; - } - - succeed = g_setenv("UZBL_UTIL_DIR", util_dir, TRUE); - - g_free(util_dirs); - g_free(util_dir); - return succeed; -} - // make sure that the args string you pass can properly be interpreted (eg properly escaped against whitespace, quotes etc) gboolean run_command (const gchar *command, const guint npre, const gchar **args, @@ -1297,7 +1274,6 @@ run_command (const gchar *command, const guint npre, const gchar **args, gchar *pid = itos(getpid()); gchar *xwin = itos(uzbl.xwin); guint i; - gboolean environ_set = uzbl_setup_environ(); sharg_append(a, command); for (i = 0; i < npre; i++) /* add n args before the default vars */ @@ -1337,9 +1313,6 @@ run_command (const gchar *command, const guint npre, const gchar **args, printf("Stdout: %s\n", *output_stdout); } } - if (!environ_set) { - g_printerr("failed to set the environment for scripts"); - } if (err) { g_printerr("error on run_command: %s\n", err->message); g_error_free (err); diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 15f7299..5760423 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -273,9 +273,6 @@ chain (WebKitWebView *page, GArray *argv, GString *result); void close_uzbl (WebKitWebView *page, GArray *argv, GString *result); -gboolean -uzbl_setup_environ(); - gboolean run_command(const gchar *command, const guint npre, const gchar **args, const gboolean sync, char **output_stdout); -- cgit v1.2.3 From 6b822f7b84226aec97db7165cc4859b82eb5e1ca Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 22 Nov 2010 15:54:42 -0700 Subject: uzbl-cookie-manager: daemonise by default, even if -v is on --- examples/uzbl-cookie-manager.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'examples') diff --git a/examples/uzbl-cookie-manager.c b/examples/uzbl-cookie-manager.c index 133a857..70addf3 100644 --- a/examples/uzbl-cookie-manager.c +++ b/examples/uzbl-cookie-manager.c @@ -321,9 +321,6 @@ int main(int argc, char *argv[]) { } } - if(verbose) - foreground = TRUE; - if(!foreground) daemonise(); -- cgit v1.2.3 From 63086b80b7a07ca4fc00e270ca92c1e679edb882 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 22 Nov 2010 15:56:14 -0700 Subject: remove ancient cookies.sh example white/blacklist --- examples/config/cookies | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 examples/config/cookies (limited to 'examples') diff --git a/examples/config/cookies b/examples/config/cookies deleted file mode 100644 index 9b7374a..0000000 --- a/examples/config/cookies +++ /dev/null @@ -1,22 +0,0 @@ -# This file demonstrates how one *could* manage his cookies. this file is used by the example cookie handler script. -# stick to this format. -# trusted -> always store what we get, send what we have (TODO: by default, or when requested?) -# deny -> deny storing + sending - -# if you don't like to edit this file manually, you could even write a script that adds/removes entries using sed, and call the script from uzbl with a keybind... - - -TRUSTED -bbs.archlinux.org -archlinux.org -linux.com - - - - -DENY -www.icanhascheezburger.com - - - -# rest -> ask \ No newline at end of file -- cgit v1.2.3 From b4cfab85863b9fc14cfd3f890b53a9253841010d Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 12:43:42 -0700 Subject: insert_bookmark.sh was totally busted --- examples/data/scripts/insert_bookmark.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 08d7d2b..9303b85 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,19 +1,16 @@ #!/bin/sh +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -d "$UZBL_DATA_DIR" ] || exit 1 [ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity &>/dev/null || exit 2 -# replace tabs, they are pointless in titles and we want to use tabs as delimiter. -title=$(echo "$UZBL_TITLE" | sed 's/\t/ /') -entry=$(zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$UZBL_URL $title\t") + +tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URL:") exitstatus=$? -if [ $exitstatus -ne 0 ]; then exit $exitstatus; fi -url=$(echo $entry | awk '{print $1}') +[ $exitstatus -eq 0 ] || exit $exitstatus # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags -echo "$entry" >/dev/null #for some reason we need this.. don't ask me why -echo -e "$entry" >> $UZBL_BOOKMARKS_FILE -true +echo "$UZBL_URL $tags" >> "$UZBL_BOOKMARKS_FILE" -- cgit v1.2.3 From 7afc00bfd43ee8ee4329a664605d59a7603c9a6a Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 13:58:48 -0700 Subject: load_url_from_*: don't require socat, fix some quoting issues --- examples/data/scripts/load_url_from_bookmarks.sh | 14 +++++++------- examples/data/scripts/load_url_from_history.sh | 17 ++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 564c3f8..ed1e2e8 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -5,19 +5,19 @@ DMENU_SCHEME="bookmarks" DMENU_OPTIONS="xmms vertical resize" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +source "$UZBL_UTIL_DIR"/dmenu.sh +source "$UZBL_UTIL_DIR"/uzbl-args.sh +source "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 if [ -z "$DMENU_HAS_VERTICAL" ]; then # because they are all after each other, just show the url, not their tags. - goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU) + goto=$(awk '{print $1}' "$UZBL_BOOKMARKS_FILE" | $DMENU) else # show tags as well - goto=$($DMENU < $UZBL_BOOKMARKS_FILE | awk '{print $1}') + goto=$($DMENU < "$UZBL_BOOKMARKS_FILE" | awk '{print $1}') fi -#[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET +[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO" +#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET" diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index d094625..8582bc3 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -3,23 +3,22 @@ DMENU_SCHEME="history" DMENU_OPTIONS="xmms vertical resize" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +source "$UZBL_UTIL_DIR"/dmenu.sh +source "$UZBL_UTIL_DIR"/uzbl-args.sh +source "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -r "$UZBL_HISTORY_FILE" ] || exit 1 # choose from all entries, sorted and uniqued # goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) if [ -z "$DMENU_HAS_VERTICAL" ]; then - current=$(tail -n 1 $UZBL_HISTORY_FILE | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ - | sort -u) | $DMENU) + current=$(tail -n 1 "$UZBL_HISTORY_FILE" | awk '{print $3}'); + goto=$((echo $current; awk '{print $3}' "$UZBL_HISTORY_FILE" | grep -v "^$current\$" | sort -u) | $DMENU) else # choose an item in reverse order, showing also the date and page titles # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. - goto=$(tac $UZBL_HISTORY_FILE | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}') + goto=$(tac "$UZBL_HISTORY_FILE" | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}') fi -#[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET +[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO" +#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET" -- cgit v1.2.3 From 344bc3f53ade206bafb8466645c8ed57e49f1b62 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 14:00:07 -0700 Subject: make session.sh work with the split util scripts --- examples/data/scripts/session.sh | 66 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 29 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 89eeb7a..203cd52 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -1,32 +1,43 @@ #!/bin/sh +# +# Very simple session manager for uzbl-browser. +# To use, add a line like 'bind quit = spawn @scripts_dir/session.sh endsession' +# to your config. +# To restore the session, run this script with the argument "launch". An +# instance of uzbl-browser will be launched for each stored url. +# +# When called with "endsession" as the argument, it will backup +# $UZBL_SESSION_FILE, look for fifos in $UZBL_FIFO_DIR and instruct each of them +# to store its current url in $UZBL_SESSION_FILE and terminate. +# +# "endinstance" is used internally and doesn't need to be called manually. -# Very simple session manager for uzbl-browser. When called with "endsession" as the -# argument, it'll backup $sessionfile, look for fifos in $fifodir and -# instruct each of them to store their current url in $sessionfile and -# terminate themselves. Run with "launch" as the argument and an instance of -# uzbl-browser will be launched for each stored url. "endinstance" is used internally -# and doesn't need to be called manually at any point. -# Add a line like 'bind quit = /path/to/session.sh endsession' to your config - -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +if [ -z "$UZBL_UTIL_DIR" ]; then + # we're being run standalone, we have to figure out where $UZBL_UTIL_DIR is + # using the same logic as uzbl-browser does. + UZBL_UTIL_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/scripts/util + if ! [ -d "$UZBL_UTIL_DIR" ]; then + PREFIX=$(grep '^PREFIX' "$(which uzbl-browser)" | sed 's/.*=//') + UZBL_UTIL_DIR=$PREFIX/share/uzbl/examples/data/scripts/util + fi +fi -[ -d $UZBL_DATA_DIR ] || exit 1 +. "$UZBL_UTIL_DIR"/uzbl-dir.sh +[ -d "$UZBL_DATA_DIR" ] || exit 1 -scriptfile=$0 # this script UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. -act="$1" - -# Test if we were run alone or from uzbl -if [ -z "$UZBL_SOCKET" ]; then - # Take the old config - act="$UZBL_CONFIG" +if [ $# -gt 1 ]; then + # this script is being run from uzbl, rather than standalone + . "$UZBL_UTIL_DIR"/uzbl-args.sh fi +scriptfile=$0 # this script +act="$1" + case $act in "launch" ) - urls=$(cat $UZBL_SESSION_FILE) + urls=$(cat "$UZBL_SESSION_FILE") if [ -z "$urls" ]; then $UZBL else @@ -35,28 +46,25 @@ case $act in disown done fi - exit 0 ;; "endinstance" ) - if [ -z "$UZBL_SOCKET" ]; then + if [ -z "$UZBL_FIFO" ]; then echo "session manager: endinstance must be called from uzbl" exit 1 fi - if [ ! "$UZBL_URL" = "(null)" ]; then - echo "$UZBL_URL" >> $UZBL_SESSION_FILE - fi - echo "exit" | socat - unix-connect:$UZBL_SOCKET + [ "$UZBL_URL" != "(null)" ] && echo "$UZBL_URL" >> "$UZBL_SESSION_FILE" + echo exit > "$UZBL_FIFO" ;; "endsession" ) mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" - for sock in $UZBL_SOCKET_DIR/uzbl_fifo_*; do - if [ "$sock" != "$UZBL_SOCKET" ]; then - echo "spawn $scriptfile endinstance" | socat - unix-connect:$socket + for fifo in "$UZBL_FIFO_DIR"/uzbl_fifo_*; do + if [ "$fifo" != "$UZBL_FIFO" ]; then + echo "spawn $scriptfile endinstance" > "$fifo" fi done - echo "spawn $scriptfile endinstance" | socat - unix-connect:$UZBL_SOCKET + echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" ;; * ) -- cgit v1.2.3 From 3659b1d8bc32956d1be5e25a6c30a085953f0435 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 15:07:26 -0700 Subject: make which test silent --- examples/data/scripts/insert_bookmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index d99ff31..24f7241 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -6,7 +6,7 @@ [ -d "$UZBL_DATA_DIR" ] || exit 1 [ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1 -which zenity 2>&1 >/dev/null || exit 2 +which zenity >/dev/null 2>&1 || exit 2 tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URL:") exitstatus=$? -- cgit v1.2.3 From b5b38b968697becad4034b5803d39ff6c78aa107 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 15:13:02 -0700 Subject: make follow.sh use the utils scripts, restore mode changing functionality --- examples/data/scripts/follow.js | 15 +++++++++++---- examples/data/scripts/follow.sh | 36 +++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index 3a18b1b..d995696 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -119,30 +119,37 @@ function generateHint(el, label) { // hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px,-5px)'; return hint; } -//Here we choose what to do with an element if we -//want to "follow" it. On form elements we "select" -//or pass the focus, on links we try to perform a click, -//but at least set the href of the link. (needs some improvements) + +// Here we choose what to do with an element that the user has selected. +// Form elements get selected and/or focussed, and links and buttons are +// clicked. This function returns "XXXRESET_MODEXXX" to indicate that uzbl +// should be reset to command mode with an empty keycmd, or +// "XXX_EMIT_FORM_ACTIVEXXX" to indicate that uzbl should be set to insert mode. function clickElem(item) { removeAllHints(); if (item) { var name = item.tagName; if (name == 'BUTTON') { item.click(); + return "XXXRESET_MODEXXX"; } else if (name == 'INPUT') { var type = item.type.toUpperCase(); if (type == 'TEXT' || type == 'SEARCH' || type == 'PASSWORD') { item.focus(); item.select(); + return "XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); + return "XXXRESET_MODEXXX"; } } else if (name == 'TEXTAREA' || name == 'SELECT') { item.focus(); item.select(); + return "XXXEMIT_FORM_ACTIVEXXX"; } else { item.click(); window.location = item.href; + return "XXXRESET_MODEXXX"; } } } diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index ba59575..c8ded84 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -1,21 +1,23 @@ #!/bin/sh -config=$1; -shift -pid=$1; -shift -xid=$1; -shift -fifo=$1; -shift -socket=$1; -shift -url=$1; -shift -title=$1; -shift +# This script is just a wrapper around follow.js that lets us change uzbl's mode +# after a link is selected. -case $(echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:$socket) in - *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' | socat - unix-connect:$socket ;; - *XXXRESET_MODEXXX*) echo 'set mode=' | socat - unix-connect:$socket ;; +. "$UZBL_UTIL_DIR"/uzbl-args.sh + +# if socat is installed then we can change Uzbl's input mode once a link is +# selected; otherwise we just select a link. +if ! which socat >/dev/null 2>&1; then + echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' > "$UZBL_FIFO" + exit +fi + +result=$(echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:"$UZBL_SOCKET") +case $result in + *XXXEMIT_FORM_ACTIVEXXX*) + # a form element was selected + echo 'event FORM_ACTIVE' > "$UZBL_FIFO" ;; + *XXXRESET_MODEXXX*) + # a link was selected, reset uzbl's input mode + echo 'set mode=' > "$UZBL_FIFO" ;; esac -- cgit v1.2.3 From 518004933b6d110d2a6d140f86c759dd4e713607 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 21:56:44 -0700 Subject: add a new keybinding 'w' that opens a new window or tab --- examples/config/config | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 8189479..855f7c2 100644 --- a/examples/config/config +++ b/examples/config/config @@ -47,7 +47,7 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # === Dynamic event handlers ================================================= # Open link in new window -@on_event NEW_WINDOW sh 'uzbl-browser -u "$8"' %r +@on_event NEW_WINDOW sh 'uzbl-browser ${8:+-u "$8"}' %r # Open in current window #@on_event NEW_WINDOW uri %s # Open in new tab @@ -189,6 +189,9 @@ set ebind = @mode_bind global,-insert # a colon. @cbind :_ = %s +# open a new window or a new tab (see the on_event NEW_WINDOW settings above) +@cbind w = event NEW_WINDOW + # Page movement binds @cbind j = scroll vertical 20 @cbind k = scroll vertical -20 -- cgit v1.2.3 From b099e55133502e033f762ccd753a02404eaecf58 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 26 Nov 2010 18:07:54 +0100 Subject: fix bashism --- examples/data/scripts/load_url_from_history.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 4499e7f..ec1188d 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -13,7 +13,7 @@ DMENU_OPTIONS="xmms vertical resize" # goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) if [ -z "$DMENU_HAS_VERTICAL" ]; then current=$(tail -n 1 "$UZBL_HISTORY_FILE" | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' "$UZBL_HISTORY_FILE" | grep -v "^$current\$" | sort -u) | $DMENU) + goto=$( (echo $current; awk '{print $3}' "$UZBL_HISTORY_FILE" | grep -v "^$current\$" | sort -u) | $DMENU) else # choose an item in reverse order, showing also the date and page titles # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. -- cgit v1.2.3 From 866fda98b4766400d5ebc8639891ff93f393142b Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 26 Nov 2010 18:09:53 +0100 Subject: fix dmenu vertical detection --- examples/data/scripts/util/dmenu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index f789178..1bac6e9 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -67,7 +67,7 @@ if dmenu --help 2>&1 | grep -q '\[-xs\]'; then fi # Detect the vertical patch -if dmenu --help 2>&1 | grep -q '\[-l \]'; then +if dmenu --help 2>&1 | grep -q '\[-l lines\]'; then # Default to 10 lines if [ -z "$DMENU_LINES" ]; then DMENU_LINES=10 -- cgit v1.2.3 From aabc107241cf62beb8ac7cbce5166bda28e79f10 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 26 Nov 2010 18:18:46 +0100 Subject: fix variable name of UZBL_COOKIE_FILE --- examples/data/scripts/download.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 606aa62..0a7de5d 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -6,7 +6,7 @@ . $UZBL_UTIL_DIR/uzbl-dir.sh # Some sites block the default wget --user-agent.. -GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" +GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_FILE" url="$1" -- cgit v1.2.3 From c70c5d9708ccbce34217c9822ed0a24057f0a6af Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sat, 27 Nov 2010 00:11:37 +0100 Subject: removed disown (bashism, not available in pisx shells like dash) --- examples/data/scripts/session.sh | 1 - 1 file changed, 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 203cd52..452f5f8 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -43,7 +43,6 @@ case $act in else for url in $urls; do $UZBL --uri "$url" & - disown done fi ;; -- cgit v1.2.3 From 94924cbb5fdc28ab8c1faa2c346eebbddc966598 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 26 Nov 2010 23:06:32 +0100 Subject: improved session.sh script to work standalone - use readlink to get the absolute path of the script - works standalone as well, just run it and it will either save all running uzbl instances or reopen them - changed backup of sessionfile to launch action, so you can use endinstance from uzbl as well. For example to save a link to read it later --- examples/data/scripts/session.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 203cd52..a27c577 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -32,9 +32,13 @@ if [ $# -gt 1 ]; then . "$UZBL_UTIL_DIR"/uzbl-args.sh fi -scriptfile=$0 # this script +scriptfile=$(readlink -f $0) # this script act="$1" +if [ -z "$act" ]; then + [ -f "$UZBL_SESSION_FILE" ] && act="launch" || act="endsession" +fi + case $act in "launch" ) urls=$(cat "$UZBL_SESSION_FILE") @@ -45,6 +49,7 @@ case $act in $UZBL --uri "$url" & disown done + mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" fi ;; @@ -58,13 +63,12 @@ case $act in ;; "endsession" ) - mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" for fifo in "$UZBL_FIFO_DIR"/uzbl_fifo_*; do if [ "$fifo" != "$UZBL_FIFO" ]; then echo "spawn $scriptfile endinstance" > "$fifo" fi done - echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" + [ -z "$UZBL_FIFO" ] || echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" ;; * ) -- cgit v1.2.3 From 048734b401f6717b4e47dcffbe9c1c40f9319d08 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 11:18:19 -0700 Subject: update session.sh documentation --- examples/data/scripts/session.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index a27c577..00f4346 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -1,14 +1,17 @@ #!/bin/sh # # Very simple session manager for uzbl-browser. -# To use, add a line like 'bind quit = spawn @scripts_dir/session.sh endsession' -# to your config. -# To restore the session, run this script with the argument "launch". An -# instance of uzbl-browser will be launched for each stored url. +# To use, add a line like 'bind quit = spawn @scripts_dir/session.sh' to your +# config. This binding will exit every instance of uzbl and store the URLs they +# had open in $UZBL_SESSION_FILE. # -# When called with "endsession" as the argument, it will backup -# $UZBL_SESSION_FILE, look for fifos in $UZBL_FIFO_DIR and instruct each of them -# to store its current url in $UZBL_SESSION_FILE and terminate. +# When a session file exists this script can be run with no arguments (or the +# argument "launch") to start an instance of uzbl-browser for every stored url. +# +# If no session file exists (or if called with "endsession" as the first +# argument), this script looks for instances of uzbl that have fifos in +# $UZBL_FIFO_DIR and instructs each of them to store its current url in +# $UZBL_SESSION_FILE and terminate. # # "endinstance" is used internally and doesn't need to be called manually. -- cgit v1.2.3 From e211c19ca4729ad498a58ca6bbdf6b5ce9ef22ea Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 17:49:01 -0700 Subject: use the new $UZBL_* env vars exclusively --- examples/config/config | 34 ++++++++++++------------ examples/data/scripts/download.sh | 1 - examples/data/scripts/follow.sh | 2 -- examples/data/scripts/formfiller.sh | 1 - examples/data/scripts/go_input.sh | 19 ++----------- examples/data/scripts/history.sh | 2 +- examples/data/scripts/insert_bookmark.sh | 1 - examples/data/scripts/load_url_from_bookmarks.sh | 1 - examples/data/scripts/load_url_from_history.sh | 1 - examples/data/scripts/session.sh | 3 ++- examples/data/scripts/userscript.sh | 16 +++++------ examples/data/scripts/userscripts.sh | 2 +- examples/data/scripts/util/uzbl-args.sh | 17 ------------ examples/data/scripts/util/uzbl-window.sh | 6 ----- 14 files changed, 30 insertions(+), 76 deletions(-) delete mode 100644 examples/data/scripts/util/uzbl-args.sh (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 855f7c2..144eb00 100644 --- a/examples/config/config +++ b/examples/config/config @@ -181,7 +181,7 @@ set ebind = @mode_bind global,-insert # --- Mouse bindings --------------------------------------------------------- # Middle click open in new window -@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > $4; fi' \@SELECTED_URI +@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI # --- Keyboard bindings ------------------------------------------------------ @@ -245,14 +245,14 @@ set ebind = @mode_bind global,-insert # Exit binding @cbind ZZ = exit # Dump config to stdout -@cbind !dump = sh "echo dump_config > $4" +@cbind !dump = sh 'echo dump_config > "$UZBL_FIFO"' # Reload all variables in the config -@cbind !reload = sh "sed '/^# === Post-load misc commands/,$d' $1 | grep '^set ' > $4" +@cbind !reload = sh "sed '/^# === Post-load misc commands/,$d' \"$UZBL_CONFIG\" | grep '^set ' > \"$UZBL_FIFO\"" # Use socat to directly inject commands into uzbl-core and view events # raised by uzbl-core: -@cbind t = sh 'xterm -e "socat unix-connect:$5 -"' -#@cbind t = sh 'urxvt -e socat unix-connect:$5 -' +@cbind t = sh "xterm -e 'socat unix-connect:\"$UZBL_SOCKET\" -'" +#@cbind t = sh "urxvt -e 'socat unix-connect:\"$UZBL_SOCKET\" -'" # Uri opening prompts @cbind o_ = uri %s @@ -267,24 +267,24 @@ set ebind = @mode_bind global,-insert @cbind gh = uri http://www.uzbl.org # Yanking & pasting binds -@cbind yu = sh 'echo -n $6 | xclip' +@cbind yu = sh 'echo -n "$UZBL_URL" | xclip' @cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI -@cbind yy = sh 'echo -n $7 | xclip' +@cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' @cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI # Clone current window -@cbind c = sh 'uzbl-browser -u $6' +@cbind c = sh 'uzbl-browser -u "$UZBL_URL"' # Go the page from primary selection -@cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Go to the page in clipboard -@cbind P = sh 'echo "uri `xclip -selection clipboard -o | sed s/\\\@/%40/g`" > $4' +@cbind P = sh 'echo "uri `xclip -selection clipboard -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Start a new uzbl instance from the page in primary selection -@cbind 'p = sh 'exec uzbl-browser --uri $(xclip -o)' +@cbind 'p = sh 'exec uzbl-browser --uri "$(xclip -o)"' # paste primary selection into keycmd at the cursor position -@bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > $4' +@bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Bookmark inserting binds -@cbind b_ = sh 'echo `printf "$6 %s"` >> $XDG_DATA_HOME/uzbl/bookmarks' +@cbind b_ = sh 'echo `printf "$UZBL_URL %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks' # Or use a script to insert a bookmark. @cbind B = spawn @scripts_dir/insert_bookmark.sh @@ -319,12 +319,12 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gN = event NEW_TAB_NEXT @cbind go_ = event NEW_TAB %s @cbind gO_ = event NEW_TAB_NEXT %s -@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' -@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4' +@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' +@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Clone current tab -@cbind gd = sh 'echo "event NEW_TAB $6" > $4' -@cbind gD = sh 'echo "event NEW_TAB_NEXT $6" > $4' +@cbind gd = sh 'echo "event NEW_TAB $UZBL_URL" > "$UZBL_FIFO"' +@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URL" > "$UZBL_FIFO"' # Closing / resting @cbind gC = exit diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 606aa62..cc3cd99 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -2,7 +2,6 @@ # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do -. $UZBL_UTIL_DIR/uzbl-args.sh . $UZBL_UTIL_DIR/uzbl-dir.sh # Some sites block the default wget --user-agent.. diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index c8ded84..d1560bf 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -3,8 +3,6 @@ # This script is just a wrapper around follow.js that lets us change uzbl's mode # after a link is selected. -. "$UZBL_UTIL_DIR"/uzbl-args.sh - # if socat is installed then we can change Uzbl's input mode once a link is # selected; otherwise we just select a link. if ! which socat >/dev/null 2>&1; then diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index b2e61ec..0f04f8a 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -45,7 +45,6 @@ DMENU_OPTIONS="vertical resize" . $UZBL_UTIL_DIR/dmenu.sh . $UZBL_UTIL_DIR/editor.sh -. $UZBL_UTIL_DIR/uzbl-args.sh . $UZBL_UTIL_DIR/uzbl-dir.sh RAND=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c 1-5) diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh index c873dd8..ace0e79 100755 --- a/examples/data/scripts/go_input.sh +++ b/examples/data/scripts/go_input.sh @@ -1,20 +1,5 @@ #!/bin/sh -config=$1; -shift -pid=$1; -shift -xid=$1; -shift -fifo=$1; -shift -socket=$1; -shift -url=$1; -shift -title=$1; -shift - -case $(echo 'script @scripts_dir/go_input.js' | socat - unix-connect:$socket) in - *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' | socat - unix-connect:$socket ;; +case $(echo 'script @scripts_dir/go_input.js' | socat - unix-connect:"$UZBL_SOCKET") in + *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' > "$UZBL_FIFO" ;; esac diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index 0561fe9..167aed7 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -4,4 +4,4 @@ [ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1 -echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $UZBL_HISTORY_FILE +echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URL $UZBL_TITLE" >> $UZBL_HISTORY_FILE diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 24f7241..294d314 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,6 +1,5 @@ #!/bin/sh -. "$UZBL_UTIL_DIR"/uzbl-args.sh . "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -d "$UZBL_DATA_DIR" ] || exit 1 diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 9346526..a5d9586 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -6,7 +6,6 @@ DMENU_SCHEME="bookmarks" DMENU_OPTIONS="xmms vertical resize" . "$UZBL_UTIL_DIR"/dmenu.sh -. "$UZBL_UTIL_DIR"/uzbl-args.sh . "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 4499e7f..4782cca 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -4,7 +4,6 @@ DMENU_SCHEME="history" DMENU_OPTIONS="xmms vertical resize" . "$UZBL_UTIL_DIR"/dmenu.sh -. "$UZBL_UTIL_DIR"/uzbl-args.sh . "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -r "$UZBL_HISTORY_FILE" ] || exit 1 diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 203cd52..c69b7e3 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -29,7 +29,8 @@ UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. if [ $# -gt 1 ]; then # this script is being run from uzbl, rather than standalone - . "$UZBL_UTIL_DIR"/uzbl-args.sh + # discard the uzbl arguments + shift 7 fi scriptfile=$0 # this script diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh index 33a24ae..1e76fd2 100755 --- a/examples/data/scripts/userscript.sh +++ b/examples/data/scripts/userscript.sh @@ -2,13 +2,11 @@ if [ $# = "3" ] then - fifo="$1" - url="$2" - SCRIPT="$3" + UZBL_FIFO=$1 + UZBL_URL=$2 + SCRIPT=$3 else - fifo="$4" - url="$6" - SCRIPT="$8" + SCRIPT=$8 fi # Extract metadata chunk @@ -18,7 +16,7 @@ SHOULD_RUN=false # Assume this script will not be included for INCLUDE in `echo "$META" | grep "^\s*\/\/\s*@include"`; do # Munge into grep pattern INCLUDE="`echo "$INCLUDE" | sed -e 's/^\s*\/\/\s*@include\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" - if echo "$url" | grep -x "$INCLUDE"; then + if echo "$UZBL_URL" | grep -x "$INCLUDE"; then SHOULD_RUN=true break fi @@ -28,7 +26,7 @@ done for EXCLUDE in `echo "$META" | grep "^\s*\/\/\s*@exclude"`; do # Munge into grep pattern EXCLUDE="`echo "$EXCLUDE" | sed -e 's/^\s*\/\/\s*@exclude\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" - if echo "$url" | grep -x "$EXCLUDE"; then + if echo "$UZBL_URL" | grep -x "$EXCLUDE"; then SHOULD_RUN=false break fi @@ -36,5 +34,5 @@ done # Run the script if [ $SHOULD_RUN = true ]; then - echo "script '$SCRIPT'" > "$fifo" + echo "script '$SCRIPT'" > "$UZBL_FIFO" fi diff --git a/examples/data/scripts/userscripts.sh b/examples/data/scripts/userscripts.sh index 8896224..2c66ed8 100755 --- a/examples/data/scripts/userscripts.sh +++ b/examples/data/scripts/userscripts.sh @@ -4,5 +4,5 @@ scripts_dir="$XDG_DATA_HOME/uzbl/userscripts" for SCRIPT in $(grep -rlx "\s*//\s*==UserScript==\s*" "$scripts_dir") do - $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$4" "$6" "$SCRIPT" + $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$UZBL_FIFO" "$UZBL_URL" "$SCRIPT" done diff --git a/examples/data/scripts/util/uzbl-args.sh b/examples/data/scripts/util/uzbl-args.sh deleted file mode 100644 index 7a3dbe5..0000000 --- a/examples/data/scripts/util/uzbl-args.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# Arguments from uzbl - -UZBL_CONFIG=$1 -shift -UZBL_PID=$1 -shift -UZBL_XID=$1 -shift -UZBL_FIFO=$1 -shift -UZBL_SOCKET=$1 -shift -UZBL_URL=$1 -shift -UZBL_TITLE=$1 -shift diff --git a/examples/data/scripts/util/uzbl-window.sh b/examples/data/scripts/util/uzbl-window.sh index b2771e4..a7e92eb 100644 --- a/examples/data/scripts/util/uzbl-window.sh +++ b/examples/data/scripts/util/uzbl-window.sh @@ -1,12 +1,6 @@ #!/bin/sh # uzbl window detection -if [ -z "$UZBL_XID" ]; then - echo "Error: UZBL_XID not set" - echo "Please source uzbl-args.sh first" - exit 1 -fi - UZBL_WIN_POS=$(xwininfo -id $UZBL_XID | \ sed -ne 's/Corners:[ ]*[+-]\([0-9]*\)[+-]\([0-9]*\).*$/\1 \2/p') UZBL_WIN_SIZE=$(xwininfo -id $UZBL_XID | \ -- cgit v1.2.3 From 0faed45023a73e446f606871b2480a317e4d8d2d Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 17:55:07 -0700 Subject: $UZBL_URL -> $UZBL_URI (for consistency with the rest of our interface) --- examples/config/config | 10 +++++----- examples/data/scripts/formfiller.sh | 2 +- examples/data/scripts/history.sh | 2 +- examples/data/scripts/insert_bookmark.sh | 4 ++-- examples/data/scripts/session.sh | 2 +- examples/data/scripts/userscript.sh | 6 +++--- examples/data/scripts/userscripts.sh | 2 +- src/callbacks.c | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 144eb00..22414ad 100644 --- a/examples/config/config +++ b/examples/config/config @@ -267,13 +267,13 @@ set ebind = @mode_bind global,-insert @cbind gh = uri http://www.uzbl.org # Yanking & pasting binds -@cbind yu = sh 'echo -n "$UZBL_URL" | xclip' +@cbind yu = sh 'echo -n "$UZBL_URI" | xclip' @cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI @cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' @cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI # Clone current window -@cbind c = sh 'uzbl-browser -u "$UZBL_URL"' +@cbind c = sh 'uzbl-browser -u "$UZBL_URI"' # Go the page from primary selection @cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Go to the page in clipboard @@ -284,7 +284,7 @@ set ebind = @mode_bind global,-insert @bind = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Bookmark inserting binds -@cbind b_ = sh 'echo `printf "$UZBL_URL %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks' +@cbind b_ = sh 'echo `printf "$UZBL_URI %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks' # Or use a script to insert a bookmark. @cbind B = spawn @scripts_dir/insert_bookmark.sh @@ -323,8 +323,8 @@ set formfiller = spawn @scripts_dir/formfiller.sh @cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"' # Clone current tab -@cbind gd = sh 'echo "event NEW_TAB $UZBL_URL" > "$UZBL_FIFO"' -@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URL" > "$UZBL_FIFO"' +@cbind gd = sh 'echo "event NEW_TAB $UZBL_URI" > "$UZBL_FIFO"' +@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URI" > "$UZBL_FIFO"' # Closing / resting @cbind gC = exit diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 0f04f8a..c6822e6 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -55,7 +55,7 @@ MODELINE="> vim:ft=formfiller" action=$1 -domain=$(echo $UZBL_URL | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') +domain=$(echo $UZBL_URI | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ]; then action="new" diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index 167aed7..266d65d 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -4,4 +4,4 @@ [ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1 -echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URL $UZBL_TITLE" >> $UZBL_HISTORY_FILE +echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URI $UZBL_TITLE" >> $UZBL_HISTORY_FILE diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 294d314..f67e67a 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -7,9 +7,9 @@ which zenity >/dev/null 2>&1 || exit 2 -tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URL:") +tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:") exitstatus=$? [ $exitstatus -eq 0 ] || exit $exitstatus # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags -echo "$UZBL_URL $tags" >> "$UZBL_BOOKMARKS_FILE" +echo "$UZBL_URI $tags" >> "$UZBL_BOOKMARKS_FILE" diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index c69b7e3..c5c4172 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -54,7 +54,7 @@ case $act in echo "session manager: endinstance must be called from uzbl" exit 1 fi - [ "$UZBL_URL" != "(null)" ] && echo "$UZBL_URL" >> "$UZBL_SESSION_FILE" + [ "$UZBL_URI" != "(null)" ] && echo "$UZBL_URI" >> "$UZBL_SESSION_FILE" echo exit > "$UZBL_FIFO" ;; diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh index 1e76fd2..fd95fdc 100755 --- a/examples/data/scripts/userscript.sh +++ b/examples/data/scripts/userscript.sh @@ -3,7 +3,7 @@ if [ $# = "3" ] then UZBL_FIFO=$1 - UZBL_URL=$2 + UZBL_URI=$2 SCRIPT=$3 else SCRIPT=$8 @@ -16,7 +16,7 @@ SHOULD_RUN=false # Assume this script will not be included for INCLUDE in `echo "$META" | grep "^\s*\/\/\s*@include"`; do # Munge into grep pattern INCLUDE="`echo "$INCLUDE" | sed -e 's/^\s*\/\/\s*@include\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" - if echo "$UZBL_URL" | grep -x "$INCLUDE"; then + if echo "$UZBL_URI" | grep -x "$INCLUDE"; then SHOULD_RUN=true break fi @@ -26,7 +26,7 @@ done for EXCLUDE in `echo "$META" | grep "^\s*\/\/\s*@exclude"`; do # Munge into grep pattern EXCLUDE="`echo "$EXCLUDE" | sed -e 's/^\s*\/\/\s*@exclude\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`" - if echo "$UZBL_URL" | grep -x "$EXCLUDE"; then + if echo "$UZBL_URI" | grep -x "$EXCLUDE"; then SHOULD_RUN=false break fi diff --git a/examples/data/scripts/userscripts.sh b/examples/data/scripts/userscripts.sh index 2c66ed8..4f76c90 100755 --- a/examples/data/scripts/userscripts.sh +++ b/examples/data/scripts/userscripts.sh @@ -4,5 +4,5 @@ scripts_dir="$XDG_DATA_HOME/uzbl/userscripts" for SCRIPT in $(grep -rlx "\s*//\s*==UserScript==\s*" "$scripts_dir") do - $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$UZBL_FIFO" "$UZBL_URL" "$SCRIPT" + $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$UZBL_FIFO" "$UZBL_URI" "$SCRIPT" done diff --git a/src/callbacks.c b/src/callbacks.c index 2637810..4f0e4ac 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -437,7 +437,7 @@ load_status_change_cb (WebKitWebView* web_view, GParamSpec param_spec) { g_free (uzbl.state.uri); GString* newuri = g_string_new (webkit_web_frame_get_uri (frame)); uzbl.state.uri = g_string_free (newuri, FALSE); - g_setenv("UZBL_URL", uzbl.state.uri, TRUE); + g_setenv("UZBL_URI", uzbl.state.uri, TRUE); send_event(LOAD_COMMIT, webkit_web_frame_get_uri (frame), NULL); break; -- cgit v1.2.3 From 212ab31b4b3161995968a312546e156cafa4e8d1 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 30 Nov 2010 18:32:35 -0700 Subject: uzbl-tabbed shouldn't freak out if no status_background is set --- examples/data/scripts/uzbl-tabbed | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed index 9e5d715..0086c04 100755 --- a/examples/data/scripts/uzbl-tabbed +++ b/examples/data/scripts/uzbl-tabbed @@ -471,8 +471,9 @@ class UzblInstance: elif var == "gtk_tab_pos": self.parent.update_gtk_tab_pos() elif var == "status_background": - col = gtk.gdk.color_parse(config['status_background']) - self.parent.ebox.modify_bg(gtk.STATE_NORMAL, col) + if config['status_background'].strip(): + col = gtk.gdk.color_parse(config['status_background']) + self.parent.ebox.modify_bg(gtk.STATE_NORMAL, col) elif var == "tab_titles" or var == "tab_indexes": for tab in self.parent.notebook: self.parent.tabs[tab].title_changed(True) -- cgit v1.2.3 From e1bff5432860622327dc8d81b8f9ef374588c5cb Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 30 Nov 2010 20:20:02 -0700 Subject: remove parseenv(). it's not documented, it doesn't do anything that @(echo $X)@ can't, and it's not very efficient (it iterates through the entire environment every time an event is sent) --- examples/config/config | 10 ++++++---- src/events.c | 13 ++----------- src/uzbl-core.c | 42 ++++-------------------------------------- src/uzbl-core.h | 3 --- 4 files changed, 12 insertions(+), 56 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 22414ad..e282bb9 100644 --- a/examples/config/config +++ b/examples/config/config @@ -3,8 +3,10 @@ # === Core settings ========================================================== -# Install location prefix. -set prefix = /usr/local +# common directory locations +set prefix = @(echo $PREFIX)@ +set data_home = @(echo $XDG_DATA_HOME)@ +set cache_home = @(echo $XDG_CACHE_HOME)@ # Interface paths. set fifo_dir = /tmp @@ -34,13 +36,13 @@ set set_mode = set mode = set set_status = set status_message = # Spawn path shortcuts. In spawn the first dir+path match is used in "dir1:dir2:dir3:executable" -set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scripts +set scripts_dir = @data_home/uzbl:@prefix/share/uzbl/examples/data:scripts # === Hardcoded handlers ===================================================== # These handlers can't be moved to the new event system yet as we don't # support events that can wait for a response from a script. -set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket +set cookie_handler = talk_to_socket @cache_home/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py diff --git a/src/events.c b/src/events.c index 20e3675..3b42b3f 100644 --- a/src/events.c +++ b/src/events.c @@ -136,24 +136,16 @@ send_event_stdout(GString *msg) { void send_event(int type, const gchar *details, const gchar *custom_event) { GString *event_message = g_string_new(""); - gchar *buf, *p_val = NULL; - - /* expand shell vars */ - if(details) { - buf = g_strdup(details); - p_val = parseenv(buf ? g_strchug(buf) : " "); - g_free(buf); - } /* check for custom events */ if(custom_event) { g_string_printf(event_message, "EVENT [%s] %s %s\n", - uzbl.state.instance_name, custom_event, p_val); + uzbl.state.instance_name, custom_event, details); } /* check wether we support the internal event */ else if(type < LAST_EVENT) { g_string_printf(event_message, "EVENT [%s] %s %s\n", - uzbl.state.instance_name, event_table[type], p_val); + uzbl.state.instance_name, event_table[type], details); } if(event_message->str) { @@ -163,7 +155,6 @@ send_event(int type, const gchar *details, const gchar *custom_event) { g_string_free(event_message, TRUE); } - g_free(p_val); } /* Transform gdk key events to our own events */ diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 3a04027..5adc4e1 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -414,36 +414,6 @@ find_existing_file(gchar* path_list) { return NULL; } - -/* Returns a new string with environment $variables expanded */ -gchar* -parseenv (gchar* string) { - extern char** environ; - gchar* tmpstr = NULL, * out; - int i = 0; - - if(!string) - return NULL; - - out = g_strdup(string); - while (environ[i] != NULL) { - gchar** env = g_strsplit (environ[i], "=", 2); - gchar* envname = g_strconcat ("$", env[0], NULL); - - if (g_strrstr (string, envname) != NULL) { - tmpstr = out; - out = str_replace(envname, env[1], out); - g_free (tmpstr); - } - - g_free (envname); - g_strfreev (env); // somebody said this breaks uzbl - i++; - } - - return out; -} - void clean_up(void) { if(uzbl.info.pid_str) { @@ -695,9 +665,8 @@ set_var(WebKitWebView *page, GArray *argv, GString *result) { gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2); if (split[0] != NULL) { - gchar *value = parseenv(split[1] ? g_strchug(split[1]) : " "); + gchar *value = split[1] ? g_strchug(split[1]) : " "; set_var_value(g_strstrip(split[0]), value); - g_free(value); } g_strfreev(split); } @@ -927,14 +896,12 @@ void include(WebKitWebView *page, GArray *argv, GString *result) { (void) page; (void) result; - gchar *pe = NULL, - *path = NULL; + gchar *path = argv_idx(argv, 0); - if(!argv_idx(argv, 0)) + if(!path) return; - pe = parseenv(argv_idx(argv, 0)); - if((path = find_existing_file(pe))) { + if((path = find_existing_file(path))) { if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) { gchar *tmp = g_strdup_printf("File %s can not be read.", path); send_event(COMMAND_ERROR, tmp, NULL); @@ -944,7 +911,6 @@ include(WebKitWebView *page, GArray *argv, GString *result) { send_event(FILE_INCLUDED, path, NULL); g_free(path); } - g_free(pe); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..6c926c6 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -228,9 +228,6 @@ itos(int val); gchar* strfree(gchar *str); -gchar* -parseenv (gchar* string); - void clean_up(void); -- cgit v1.2.3 From 3722315bbccef62b9bf9bcdb041868f2fcbe7c15 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 1 Dec 2010 10:00:51 -0700 Subject: dmenu 4.1 and 4.2 have different help messages, support both --- examples/data/scripts/util/dmenu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 1bac6e9..da61cae 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -67,7 +67,7 @@ if dmenu --help 2>&1 | grep -q '\[-xs\]'; then fi # Detect the vertical patch -if dmenu --help 2>&1 | grep -q '\[-l lines\]'; then +if dmenu --help 2>&1 | grep -q '\[-l <\?lines>\?\]'; then # Default to 10 lines if [ -z "$DMENU_LINES" ]; then DMENU_LINES=10 -- cgit v1.2.3 From 081c95aee6d6490fdaf67e22c3d6245009462908 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 1 Dec 2010 12:09:13 -0700 Subject: positional arguments still exist: fix download.sh, follow.sh and the formfiller --- examples/data/scripts/download.sh | 1 + examples/data/scripts/follow.sh | 2 ++ examples/data/scripts/formfiller.sh | 2 ++ 3 files changed, 5 insertions(+) (limited to 'examples') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index cc3cd99..de03b1f 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -2,6 +2,7 @@ # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do +shift 7 . $UZBL_UTIL_DIR/uzbl-dir.sh # Some sites block the default wget --user-agent.. diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index d1560bf..2d666a2 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -3,6 +3,8 @@ # This script is just a wrapper around follow.js that lets us change uzbl's mode # after a link is selected. +shift 7 + # if socat is installed then we can change Uzbl's input mode once a link is # selected; otherwise we just select a link. if ! which socat >/dev/null 2>&1; then diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index c6822e6..6e04573 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -53,6 +53,8 @@ MODELINE="> vim:ft=formfiller" [ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 [ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1 +shift 7 + action=$1 domain=$(echo $UZBL_URI | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') -- cgit v1.2.3 From 59adc0787f7b77922c671964e471d0fd2dd7fc90 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 13:47:09 -0700 Subject: let webkit handle downloads (breaks backward compatibility) --- README | 9 ++- examples/config/config | 1 + examples/data/scripts/download.sh | 34 +++++------ src/callbacks.c | 125 ++++++++++++++++++++++++++++++++++++-- src/callbacks.h | 5 +- src/events.c | 7 ++- src/events.h | 3 +- src/uzbl-core.c | 1 + src/uzbl-core.h | 1 + 9 files changed, 154 insertions(+), 32 deletions(-) (limited to 'examples') diff --git a/README b/README index 34556f2..6dddb35 100644 --- a/README +++ b/README @@ -668,8 +668,13 @@ Events have this format: * `EVENT [uzbl_instance_name] TITLE_CHANGED title_name`: When the title of the page (and hence maybe, the window title) changed. `title_name` is the new title. -* `EVENT [uzbl_instance_name] DOWNLOAD_REQUEST download_uri`: When content needs - to be downloaded, `download_uri` is the URI to get. +* `EVENT [uzbl_instance_name] DOWNLOAD_STARTED destination_path`: A download + has been started, the file will be saved to `destination_path`. +* `EVENT [uzbl_instance_name] DOWNLOAD_PROGRESS destination_path progress`: + While a download is active this event notifies you of the progress. + `progress` is a decimal between 0 and 1. +* `EVENT [uzbl_instance_name] DOWNLOAD_COMPLETE destination_path`: The + download being saved to `destination_path` is now complete. * `EVENT [uzbl_instance_name] LINK_HOVER uri`: The mouse hovers over the link `uri`. * `EVENT [uzbl_instance_name] LINK_UNHOVER uri`: The mouse leaves the link diff --git a/examples/config/config b/examples/config/config index 855f7c2..64e1c94 100644 --- a/examples/config/config +++ b/examples/config/config @@ -43,6 +43,7 @@ set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scri set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py +set download_handler = sync_spawn @scripts_dir/download.sh # === Dynamic event handlers ================================================= diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 606aa62..c6d95f7 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,26 +1,26 @@ #!/bin/sh -# just an example of how you could handle your downloads -# try some pattern matching on the uri to determine what we should do +# +# uzbl's example configuration sets this script up as its download_handler. +# when uzbl starts a download it runs this script. +# if the script prints a file path to stdout, uzbl will save the download to +# that path. +# if nothing is printed to stdout, the download will be cancelled. . $UZBL_UTIL_DIR/uzbl-args.sh . $UZBL_UTIL_DIR/uzbl-dir.sh -# Some sites block the default wget --user-agent.. -GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" +# the URL that is being downloaded +uri=$1 -url="$1" +# a filename suggested by the server or based on the URL +suggested_filename=${2:-$(echo "$uri" | sed 's/\W/-/g')} -http_proxy="$2" -export http_proxy +# the mimetype of the file being downloaded +content_type=$3 -if [ -z "$url" ]; then - echo "you must supply a url! ($url)" - exit 1 -fi +# the size of the downloaded file in bytes. this is not always accurate, since +# the server might not have sent a size with its response headers. +total_size=$4 -# only changes the dir for the $get sub process -if echo "$url" | grep -E '.*\.torrent' >/dev/null; then - ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") -else - ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") -fi +# just save the file to the default directory with the suggested name +echo $UZBL_DOWNLOAD_DIR/$suggested_filename diff --git a/src/callbacks.c b/src/callbacks.c index f596472..803428d 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -771,13 +771,128 @@ create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer us return NULL; } +void +download_progress_cb(WebKitDownload *download, GParamSpec *pspec, gpointer user_data) { + (void) pspec; (void) user_data; + + gdouble progress; + g_object_get(download, "progress", &progress, NULL); + + const gchar *dest_uri = webkit_download_get_destination_uri(download); + const gchar *dest_path = dest_uri + strlen("file://"); + + gchar *details = g_strdup_printf("%s %.2lf", dest_path, progress); + send_event(DOWNLOAD_PROGRESS, details, NULL); + g_free(details); +} + +void +download_status_cb(WebKitDownload *download, GParamSpec *pspec, gpointer user_data) { + (void) pspec; (void) user_data; + + WebKitDownloadStatus status; + g_object_get(download, "status", &status, NULL); + + switch(status) { + case WEBKIT_DOWNLOAD_STATUS_CREATED: + case WEBKIT_DOWNLOAD_STATUS_STARTED: + case WEBKIT_DOWNLOAD_STATUS_ERROR: + case WEBKIT_DOWNLOAD_STATUS_CANCELLED: + return; /* these are irrelevant */ + case WEBKIT_DOWNLOAD_STATUS_FINISHED: + { + const gchar *dest_uri = webkit_download_get_destination_uri(download); + const gchar *dest_path = dest_uri + strlen("file://"); + send_event(DOWNLOAD_COMPLETE, dest_path, NULL); + } + } +} + gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) { - (void) web_view; - (void) user_data; +download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_data) { + (void) web_view; (void) user_data; - send_event(DOWNLOAD_REQ, webkit_download_get_uri ((WebKitDownload*)download), NULL); - return (FALSE); + /* get the URI being downloaded */ + const gchar *uri = webkit_download_get_uri(download); + + if (uzbl.state.verbose) + printf("Download requested -> %s\n", uri); + + if (!uzbl.behave.download_handler) { + webkit_download_cancel(download); + return FALSE; /* reject downloads when there's no download handler */ + } + + /* get a reasonable suggestion for a filename */ + const gchar *suggested_filename; + g_object_get(download, "suggested-filename", &suggested_filename, NULL); + + /* get the mimetype of the download */ + const gchar *content_type; + WebKitNetworkResponse *r = webkit_download_get_network_response(download); + /* downloads can be initiated from the context menu, in that case there is + no network response yet and trying to get one would crash. */ + if(WEBKIT_IS_NETWORK_RESPONSE(r)) { + SoupMessage *m = webkit_network_response_get_message(r); + SoupMessageHeaders *h; + g_object_get(m, "response-headers", &h, NULL); + content_type = soup_message_headers_get_one(h, "Content-Type"); + } else + content_type = "application/octet-stream"; + + /* get the filesize of the download, as given by the server. + (this may be inaccurate, there's nothing we can do about that.) */ + unsigned int total_size = webkit_download_get_total_size(download); + + gchar *ev = g_strdup_printf("'%s' '%s' '%s' %d", uri, suggested_filename, + content_type, total_size); + run_handler(uzbl.behave.download_handler, ev); + g_free(ev); + + /* no response, cancel the download */ + if(!uzbl.comm.sync_stdout) { + webkit_download_cancel(download); + return FALSE; + } + + /* no response, cancel the download */ + if(uzbl.comm.sync_stdout[0] == 0) { + webkit_download_cancel(download); + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); + return FALSE; + } + + /* we got a response, it's the path we should download the file to */ + gchar *destination_path = uzbl.comm.sync_stdout; + uzbl.comm.sync_stdout = NULL; + + /* presumably people don't need newlines in their filenames. */ + char *p = strchr(destination_path, '\n'); + if ( p != NULL ) *p = '\0'; + + /* set up progress callbacks */ + g_signal_connect(download, "notify::status", G_CALLBACK(download_status_cb), NULL); + g_signal_connect(download, "notify::progress", G_CALLBACK(download_progress_cb), NULL); + + /* convert relative path to absolute path */ + if(destination_path[0] != '/') { + gchar *rel_path = destination_path; + gchar *cwd = g_get_current_dir(); + destination_path = g_strconcat(cwd, "/", destination_path, NULL); + g_free(cwd); + g_free(rel_path); + } + + send_event(DOWNLOAD_STARTED, destination_path, NULL); + + /* convert absolute path to file:// URI */ + gchar *destination_uri = g_strconcat("file://", destination_path, NULL); + g_free(destination_path); + + webkit_download_set_destination_uri(download, destination_uri); + g_free(destination_uri); + + return TRUE; } gboolean diff --git a/src/callbacks.h b/src/callbacks.h index a4258f2..40fa80d 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -133,9 +133,6 @@ cmd_load_start(); WebKitWebSettings* view_settings(); -gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); - void toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result); @@ -197,7 +194,7 @@ request_starting_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitWebRes create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data); gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); +download_cb (WebKitWebView *web_view, WebKitDownload *download, gpointer user_data); void populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c); diff --git a/src/events.c b/src/events.c index 20e3675..55775a8 100644 --- a/src/events.c +++ b/src/events.c @@ -22,7 +22,6 @@ const char *event_table[LAST_EVENT] = { "REQUEST_STARTING" , "KEY_PRESS" , "KEY_RELEASE" , - "DOWNLOAD_REQUEST" , "COMMAND_EXECUTED" , "LINK_HOVER" , "TITLE_CHANGED" , @@ -45,10 +44,12 @@ const char *event_table[LAST_EVENT] = { "PLUG_CREATED" , "COMMAND_ERROR" , "BUILTINS" , - "PTR_MOVE" "PTR_MOVE" , "SCROLL_VERT" , - "SCROLL_HORIZ" + "SCROLL_HORIZ" , + "DOWNLOAD_STARTED" , + "DOWNLOAD_PROGRESS", + "DOWNLOAD_COMPLETE" }; void diff --git a/src/events.h b/src/events.h index bc7960d..4b04dd2 100644 --- a/src/events.h +++ b/src/events.h @@ -7,7 +7,7 @@ enum event_type { LOAD_START, LOAD_COMMIT, LOAD_FINISH, LOAD_ERROR, REQUEST_STARTING, - KEY_PRESS, KEY_RELEASE, DOWNLOAD_REQ, COMMAND_EXECUTED, + KEY_PRESS, KEY_RELEASE, COMMAND_EXECUTED, LINK_HOVER, TITLE_CHANGED, GEOMETRY_CHANGED, WEBINSPECTOR, NEW_WINDOW, SELECTION_CHANGED, VARIABLE_SET, FIFO_SET, SOCKET_SET, @@ -16,6 +16,7 @@ enum event_type { FOCUS_LOST, FOCUS_GAINED, FILE_INCLUDED, PLUG_CREATED, COMMAND_ERROR, BUILTINS, PTR_MOVE, SCROLL_VERT, SCROLL_HORIZ, + DOWNLOAD_STARTED, DOWNLOAD_PROGRESS, DOWNLOAD_COMPLETE, /* must be last entry */ LAST_EVENT diff --git a/src/uzbl-core.c b/src/uzbl-core.c index cb20fd7..c960936 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -93,6 +93,7 @@ const struct var_name_to_ptr_t { { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, cmd_set_cookie_handler)}, { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)}, { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, + { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)}, { "socket_dir", PTR_V_STR(uzbl.behave.socket_dir, 1, cmd_socket_dir)}, { "http_debug", PTR_V_INT(uzbl.behave.http_debug, 1, cmd_http_debug)}, diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..a62c3a6 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -133,6 +133,7 @@ typedef struct { gchar* fantasy_font_family; gchar* cursive_font_family; gchar* scheme_handler; + gchar* download_handler; gboolean show_status; gboolean forward_keys; gboolean status_top; -- cgit v1.2.3 From 5ab073d90e3c66a53e116c78299c657a13847d5c Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 14:55:47 -0700 Subject: display active downloads in the status bar --- examples/config/config | 4 ++- examples/data/plugins/downloads.py | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/data/plugins/downloads.py (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 64e1c94..a8547d2 100644 --- a/examples/config/config +++ b/examples/config/config @@ -105,7 +105,9 @@ set name_section = \@[\@NAME]\@ set status_section = \@status_message set selected_section = \@[\@SELECTED_URI]\@ -set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section +set download_section = \@downloads + +set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section @download_section set title_format_long = \@keycmd_prompt \@raw_modcmd \@raw_keycmd \@TITLE - Uzbl browser <\@NAME> \@SELECTED_URI diff --git a/examples/data/plugins/downloads.py b/examples/data/plugins/downloads.py new file mode 100644 index 0000000..7bf32d7 --- /dev/null +++ b/examples/data/plugins/downloads.py @@ -0,0 +1,69 @@ +# this plugin does a very simple display of download progress. to use it, add +# @downloads to your status_format. + +import os +ACTIVE_DOWNLOADS = {} + +# after a download's status has changed this is called to update the status bar +def update_download_section(uzbl): + global ACTIVE_DOWNLOADS + + if len(ACTIVE_DOWNLOADS): + # add a newline before we list downloads + result = ' downloads:' + for path in ACTIVE_DOWNLOADS: + # add each download + fn = os.path.basename(path) + progress, = ACTIVE_DOWNLOADS[path] + + dl = " %s (%d%%)" % (fn, progress * 100) + + # replace entities to make sure we don't break our markup + # (this could be done with an @[]@ expansion in uzbl, but then we + # can't use the above to make a new line) + dl = dl.replace("&", "&").replace("<", "<") + result += dl + else: + result = '' + + # and the result gets saved to an uzbl variable that can be used in + # status_format + if uzbl.config.get('downloads', '') != result: + uzbl.config['downloads'] = result + +def download_started(uzbl, destination_path): + # add to the list of active downloads + global ACTIVE_DOWNLOADS + ACTIVE_DOWNLOADS[destination_path] = (0.0,) + + # update the progress + update_download_section(uzbl) + +def download_progress(uzbl, args): + # parse the arguments + s = args.rindex(' ') + destination_path = args[:s] + progress = float(args[s+1:]) + + # update the progress + global ACTIVE_DOWNLOADS + ACTIVE_DOWNLOADS[destination_path] = (progress,) + + # update the status bar variable + update_download_section(uzbl) + +def download_complete(uzbl, destination_path): + # remove from the list of active downloads + global ACTIVE_DOWNLOADS + del ACTIVE_DOWNLOADS[destination_path] + + # update the status bar variable + update_download_section(uzbl) + +# plugin init hook +def init(uzbl): + connect_dict(uzbl, { + 'DOWNLOAD_STARTED': download_started, + 'DOWNLOAD_PROGRESS': download_progress, + 'DOWNLOAD_COMPLETE': download_complete, + }) -- cgit v1.2.3 From 123e73552c199e1efad6c2fb15e2d7128bc2b7e2 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 15:17:15 -0700 Subject: removed DOWNLOAD_REQUEST from the example config there's always one thing i forget to commit :( --- examples/config/config | 3 --- 1 file changed, 3 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index a8547d2..372b5cc 100644 --- a/examples/config/config +++ b/examples/config/config @@ -54,9 +54,6 @@ set download_handler = sync_spawn @scripts_dir/download.sh # Open in new tab #@on_event NEW_WINDOW event NEW_TAB %s -# Download handler -@on_event DOWNLOAD_REQUEST spawn @scripts_dir/download.sh %s \@proxy_url - # Load start handler @on_event LOAD_START @set_status wait # Reset the keycmd on navigation -- cgit v1.2.3