diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2010-08-25 16:10:45 +0200 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2010-08-25 16:10:45 +0200 |
commit | c9375206cb3509cac1c6ff8aec057126468b9754 (patch) | |
tree | ce792e588adb47dcdfb85524c5f0b096c6454967 | |
parent | 8fbe72f35afa9953c7b150c636fa26f182a9fce7 (diff) | |
parent | 733d83d0ada566b0353fd2c305a3838cc2eed131 (diff) |
Merge remote branch 'paradoq/master' into experimental
-rw-r--r-- | examples/config/config | 3 | ||||
-rwxr-xr-x | examples/data/scripts/userscript.sh | 40 | ||||
-rwxr-xr-x | examples/data/scripts/userscripts.sh | 8 |
3 files changed, 51 insertions, 0 deletions
diff --git a/examples/config/config b/examples/config/config index b6d9fe3..51f68d9 100644 --- a/examples/config/config +++ b/examples/config/config @@ -64,6 +64,9 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # Load commit handlers @on_event LOAD_COMMIT @set_status <span foreground="green">recv</span> +# 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 <span foreground="gold">done</span> @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 |