aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar keis <keijser@gmail.com>2011-01-01 03:24:14 +0100
committerGravatar keis <keijser@gmail.com>2011-01-01 03:24:14 +0100
commit484c060355bd44abba5d96261411f513bda48dbf (patch)
treeaf9e574728a1473f8c98e9522aaa85ef98db3fd8 /examples
parent7cf3fb88d1e094da5b516699a61d5e589c039e8f (diff)
parent8c8bd0fbd5644d91ff3cdd2b13c07f28e7e0f716 (diff)
Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into history
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config67
-rw-r--r--examples/data/per-site-settings3
-rw-r--r--examples/data/plugins/cookies.py176
-rw-r--r--examples/data/plugins/downloads.py69
-rwxr-xr-xexamples/data/scripts/auth.py2
-rwxr-xr-xexamples/data/scripts/download.sh35
-rwxr-xr-xexamples/data/scripts/follow.sh2
-rwxr-xr-xexamples/data/scripts/formfiller.sh3
-rwxr-xr-xexamples/data/scripts/go_input.sh19
-rwxr-xr-xexamples/data/scripts/history.sh2
-rwxr-xr-xexamples/data/scripts/insert_bookmark.sh5
-rwxr-xr-xexamples/data/scripts/load_cookies.sh20
-rwxr-xr-xexamples/data/scripts/load_url_from_bookmarks.sh1
-rwxr-xr-xexamples/data/scripts/load_url_from_history.sh3
-rwxr-xr-xexamples/data/scripts/per-site-settings.py117
-rw-r--r--examples/data/scripts/pipermail.js71
-rwxr-xr-xexamples/data/scripts/scheme.py2
-rwxr-xr-xexamples/data/scripts/session.sh35
-rwxr-xr-xexamples/data/scripts/userscript.sh40
-rwxr-xr-xexamples/data/scripts/userscripts.sh8
-rw-r--r--examples/data/scripts/util/dmenu.sh14
-rw-r--r--examples/data/scripts/util/uzbl-args.sh17
-rw-r--r--examples/data/scripts/util/uzbl-window.sh6
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed5
24 files changed, 550 insertions, 172 deletions
diff --git a/examples/config/config b/examples/config/config
index fe08a41..7b9fba2 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,28 +36,25 @@ 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 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 =================================================
# Open link in new window
-@on_event NEW_WINDOW sh 'uzbl-browser ${8:+-u "$8"}' %r
+@on_event NEW_WINDOW sh 'uzbl-browser ${1:+-u "$1"}' %r
# Open in current window
#@on_event NEW_WINDOW uri %s
# 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 <span foreground="khaki">wait</span>
# Reset the keycmd on navigation
@@ -64,8 +63,8 @@ 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
+# Userscripts/per-site-settings. See the script and the example configuration for details
+#@on_event LOAD_COMMIT spawn @scripts_dir/per-site-settings.py @data_home/uzbl/per-site-settings
# Load finish handlers
@on_event LOAD_FINISH @set_status <span foreground="gold">done</span>
@@ -104,7 +103,9 @@ set name_section = <span foreground="khaki">\@[\@NAME]\@</span>
set status_section = <span foreground="orange">\@status_message</span>
set selected_section = <span foreground="#606060">\@[\@SELECTED_URI]\@</span>
-set status_format = <span font_family="monospace">@mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section</span>
+set download_section = <span foreground="white">\@downloads</span>
+
+set status_format = <span font_family="monospace">@mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @scroll_section @selected_section @download_section</span>
set title_format_long = \@keycmd_prompt \@raw_modcmd \@raw_keycmd \@TITLE - Uzbl browser <\@NAME> \@SELECTED_URI
@@ -120,6 +121,10 @@ set progress.pending =
set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MICRO}) (@(+uname -sm)@ [@ARCH_UZBL]) (Commit @COMMIT)
+# === Configure cookie blacklist ========================================================
+# Drop google analytics tracking cookies
+#request BLACKLIST_COOKIE name '^__utm.$'
+
# === Key binding configuration ==============================================
# --- Internal modmapping and ignoring ---------------------------------------
@@ -190,7 +195,7 @@ set ebind = @mode_bind global,-insert
# === Mouse bindings =========================================================
# Middle click open in new window
-@bind <Button2> = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > $4; fi' \@SELECTED_URI
+@bind <Button2> = sh 'if [ "$1" ]; then uzbl-browser -u "$1"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' '\@SELECTED_URI'
# --- Keyboard bindings ------------------------------------------------------
@@ -254,14 +259,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 <Ctrl><Alt>t = sh 'xterm -e "socat unix-connect:$5 -"'
-#@cbind <Ctrl><Alt>t = sh 'urxvt -e socat unix-connect:$5 -'
+@cbind <Ctrl><Alt>t = sh 'xterm -e "socat unix-connect:\"$UZBL_SOCKET\" -"'
+#@cbind <Ctrl><Alt>t = sh 'urxvt -e socat unix-connect:"$UZBL_SOCKET" -'
# Uri opening prompts
@cbind o<uri:>_ = uri %s
@@ -276,24 +281,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 $8 | xclip' \@SELECTED_URI
-@cbind yy = sh 'echo -n $7 | xclip'
-@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI
+@cbind yu = sh 'echo -n "$UZBL_URI" | xclip'
+@cbind yU = sh 'echo -n "$1" | xclip' \@SELECTED_URI
+@cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip'
+@cbind yY = sh 'echo -n "$1" | xclip' \@SELECTED_URI
# Clone current window
-@cbind c = sh 'uzbl-browser -u $6'
+@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`" > $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 <Shift-Insert> = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > $4'
+@bind <Shift-Insert> = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > "$UZBL_FIFO"'
# Bookmark inserting binds
-@cbind <Ctrl>b<tags:>_ = sh 'echo `printf "$6 %s"` >> $XDG_DATA_HOME/uzbl/bookmarks'
+@cbind <Ctrl>b<tags:>_ = 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
@@ -328,12 +333,12 @@ set formfiller = spawn @scripts_dir/formfiller.sh
@cbind gN = event NEW_TAB_NEXT
@cbind go<uri:>_ = event NEW_TAB %s
@cbind gO<uri:>_ = 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_URI" > "$UZBL_FIFO"'
+@cbind gD = sh 'echo "event NEW_TAB_NEXT $UZBL_URI" > "$UZBL_FIFO"'
# Closing / resting
@cbind gC = exit
@@ -398,6 +403,8 @@ set stack = @mode_config stack
set default_mode = command
# === Post-load misc commands ================================================
+sync_spawn_exec @scripts_dir/load_cookies.sh
+sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt
# Set the "home" page.
set uri = uzbl.org/doesitwork/@COMMIT
diff --git a/examples/data/per-site-settings b/examples/data/per-site-settings
new file mode 100644
index 0000000..78bade4
--- /dev/null
+++ b/examples/data/per-site-settings
@@ -0,0 +1,3 @@
+.*
+ .*/\d+-\w+/(thread|subject|author|date).html
+ script @data_home/uzbl/scripts/pipermail.js
diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py
new file mode 100644
index 0000000..c9fe2c3
--- /dev/null
+++ b/examples/data/plugins/cookies.py
@@ -0,0 +1,176 @@
+""" Basic cookie manager
+ forwards cookies to all other instances connected to the event manager"""
+
+from collections import defaultdict
+import os, re
+
+# these are symbolic names for the components of the cookie tuple
+symbolic = {'domain': 0, 'path':1, 'name':2, 'value':3, 'scheme':4, 'expires':5}
+
+_splitquoted = re.compile("( |\\\".*?\\\"|'.*?')")
+def splitquoted(text):
+ return [str(p.strip('\'"')) for p in _splitquoted.split(text) if p.strip()]
+
+# allows for partial cookies
+# ? allow wildcard in key
+def match(key, cookie):
+ for k,c in zip(key,cookie):
+ if k != c:
+ return False
+ return True
+
+class NullStore(object):
+ def add_cookie(self, rawcookie, cookie):
+ pass
+
+ def delete_cookie(self, rkey, key):
+ pass
+
+class ListStore(list):
+ def add_cookie(self, rawcookie, cookie):
+ self.append(rawcookie)
+
+ def delete_cookie(self, rkey, key):
+ self[:] = [x for x in self if not match(key, splitquoted(x))]
+
+class TextStore(object):
+ def __init__(self, filename):
+ self.filename = filename
+
+ def as_event(self, cookie):
+ if cookie[0].startswith("#HttpOnly_"):
+ domain = cookie[0][len("#HttpOnly_"):]
+ elif cookie[0].startswith('#'):
+ return None
+ else:
+ domain = cookie[0]
+ return (domain,
+ cookie[2],
+ cookie[5],
+ cookie[6],
+ 'https' if cookie[3] == 'TRUE' else 'http',
+ cookie[4])
+
+ def as_file(self, cookie):
+ return (cookie[0],
+ 'TRUE' if cookie[0].startswith('.') else 'FALSE',
+ cookie[1],
+ 'TRUE' if cookie[4] == 'https' else 'FALSE',
+ cookie[5],
+ cookie[2],
+ cookie[3])
+
+ def add_cookie(self, rawcookie, cookie):
+ assert len(cookie) == 6
+
+ # delete equal cookies (ignoring expire time, value and secure flag)
+ self.delete_cookie(None, cookie[:-3])
+
+ first = not os.path.exists(self.filename)
+ with open(self.filename, 'a') as f:
+ if first:
+ print >> f, "# HTTP Cookie File"
+ print >> f, '\t'.join(self.as_file(cookie))
+
+ def delete_cookie(self, rkey, key):
+ if not os.path.exists(self.filename):
+ return
+
+ # read all cookies
+ with open(self.filename, 'r') as f:
+ cookies = f.readlines()
+
+ # write those that don't match the cookie to delete
+ with open(self.filename, 'w') as f:
+ for l in cookies:
+ c = self.as_event(l.split('\t'))
+ if c is None or not match(key, c):
+ print >> f, l,
+
+xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(os.environ['HOME'], '.local/share'))
+DefaultStore = TextStore(os.path.join(xdg_data_home, 'uzbl/cookies.txt'))
+SessionStore = TextStore(os.path.join(xdg_data_home, 'uzbl/session-cookies.txt'))
+
+def match_list(_list, cookie):
+ for component, match in _list:
+ if match(cookie[component]) is not None:
+ return True
+ return False
+
+# accept a cookie only when:
+# a. there is no whitelist and the cookie is in the blacklist
+# b. the cookie is in the whitelist and not in the blacklist
+def accept_cookie(uzbl, cookie):
+ if uzbl.cookie_whitelist:
+ if match_list(uzbl.cookie_whitelist, cookie):
+ return not match_list(uzbl.cookie_blacklist, cookie)
+ return False
+
+ return not match_list(uzbl.cookie_blacklist, cookie)
+
+def expires_with_session(uzbl, cookie):
+ return cookie[5] == ''
+
+def get_recipents(uzbl):
+ """ get a list of Uzbl instances to send the cookie too. """
+ # This could be a lot more interesting
+ return [u for u in uzbl.parent.uzbls.values() if u is not uzbl]
+
+def get_store(uzbl, session=False):
+ if session:
+ return SessionStore
+ return DefaultStore
+
+def add_cookie(uzbl, cookie):
+ splitted = splitquoted(cookie)
+ if accept_cookie(uzbl, splitted):
+ for u in get_recipents(uzbl):
+ u.send('add_cookie %s' % cookie)
+
+ get_store(uzbl, expires_with_session(uzbl, splitted)).add_cookie(cookie, splitted)
+ else:
+ logger.debug('cookie %r is blacklisted' % splitted)
+ uzbl.send('delete_cookie %s' % cookie)
+
+def delete_cookie(uzbl, cookie):
+ for u in get_recipents(uzbl):
+ u.send('delete_cookie %s' % cookie)
+
+ splitted = splitquoted(cookie)
+ if len(splitted) == 6:
+ get_store(uzbl, expires_with_session(uzbl, splitted)).delete_cookie(cookie, splitted)
+ else:
+ for store in set([get_store(uzbl, session) for session in (True, False)]):
+ store.delete_cookie(cookie, splitted)
+
+# add a cookie matcher to a whitelist or a blacklist.
+# a matcher is a (component, re) tuple that matches a cookie when the
+# "component" part of the cookie matches the regular expression "re".
+# "component" is one of the keys defined in the variable "symbolic" above,
+# or the index of a component of a cookie tuple.
+def add_cookie_matcher(_list, arg):
+ component, regexp = splitquoted(arg)
+ try:
+ component = symbolic[component]
+ except KeyError:
+ component = int(component)
+ assert component <= 5
+ _list.append((component, re.compile(regexp).search))
+
+def blacklist(uzbl, arg):
+ add_cookie_matcher(uzbl.cookie_blacklist, arg)
+
+def whitelist(uzbl, arg):
+ add_cookie_matcher(uzbl.cookie_whitelist, arg)
+
+def init(uzbl):
+ connect_dict(uzbl, {
+ 'ADD_COOKIE': add_cookie,
+ 'DELETE_COOKIE': delete_cookie,
+ 'BLACKLIST_COOKIE': blacklist,
+ 'WHITELIST_COOKIE': whitelist
+ })
+ export_dict(uzbl, {
+ 'cookie_blacklist' : [],
+ 'cookie_whitelist' : []
+ })
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 = '&#10;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 &#10; above to make a new line)
+ dl = dl.replace("&", "&amp;").replace("<", "&lt;")
+ 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,
+ })
diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py
index 9c1b4fc..592a2c6 100755
--- a/examples/data/scripts/auth.py
+++ b/examples/data/scripts/auth.py
@@ -46,7 +46,7 @@ def getText(authInfo, authHost, authRealm):
return rv, output
if __name__ == '__main__':
- rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10])
+ rv, output = getText(sys.argv[1], sys.argv[2], sys.argv[3])
if (rv == gtk.RESPONSE_OK):
print output;
else:
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index 606aa62..c410ad2 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -1,26 +1,25 @@
#!/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/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..c6822e6 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)
@@ -56,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/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..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')" $6 $7" >> $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 24f7241..f67e67a 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
@@ -8,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/load_cookies.sh b/examples/data/scripts/load_cookies.sh
new file mode 100755
index 0000000..17ec2ad
--- /dev/null
+++ b/examples/data/scripts/load_cookies.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ "$1" != "" ]; then
+ cookie_file=$1
+else
+ cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt
+fi
+
+awk -F \\t '
+BEGIN {
+ scheme["TRUE"] = "https";
+ scheme["FALSE"] = "http";
+}
+$0 ~ /^#HttpOnly_/ {
+printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5)
+}
+$0 !~ /^#/ {
+printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5)
+}
+' $cookie_file
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..59ad492 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
@@ -13,7 +12,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.
diff --git a/examples/data/scripts/per-site-settings.py b/examples/data/scripts/per-site-settings.py
new file mode 100755
index 0000000..89df4e6
--- /dev/null
+++ b/examples/data/scripts/per-site-settings.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+# Per-site settings plugin
+
+# Example configuration usage:
+#
+# @on_event LOAD_COMMIT spawn @scripts_dir/per-site-settings.py @data_home/uzbl/per-site-settings
+
+# Format of the settings file:
+#
+# <url>
+# <path>
+# <command>
+#
+# - url
+# May either be a regex, or literal. If literal, it will block any
+# subdomains as well.
+# - path
+# May either be a regex, or literal. If literal, it will block any
+# decendent paths as well.
+# - command
+# Given to uzbl verbatim.
+#
+# Matches are attempted on a literal match first.
+#
+# Any of the specifications can be repeated and acts as a fall-through to the
+# next level. Make sure indentation lines up locally. Any indentation addition
+# is considered as a fall through to the next level and any decrease is
+# considered a pop back (zero is always urls). This works because it's only 3
+# deep. Four and we'd have to keep track of things.
+
+import os
+import re
+import socket
+import stat
+import subprocess
+import tempfile
+import urlparse
+import sys
+
+
+def match_url(url, patt):
+ return url.endswith(patt) or re.match(patt, url)
+
+
+def match_path(path, patt):
+ return path.startswith(patt) or re.match(patt, path)
+
+
+def grep_url(url, path, fin):
+ entries = []
+ cur_indent = 0
+ passing = [False, False]
+ # 0 == url
+ # 1 == path
+ # 2 == command
+ state = 0
+ for line in fin:
+ raw = line.strip()
+
+ indent = len(line) - len(raw) - 1
+ if not indent:
+ # Reset state
+ passing = [False, False]
+ state = 0
+ else:
+ # previous level
+ if indent < cur_indent:
+ if state == 1:
+ passing[0] = False
+ elif state == 2:
+ passing[1] = False
+ state -= 1
+ # next level
+ elif cur_indent < indent:
+ state += 1
+
+ # parse the line
+ if state == 0:
+ if not passing[0] and match_url(url, raw):
+ passing[0] = True
+ elif state == 1 and passing[0]:
+ if not passing[1] and match_path(path, raw):
+ passing[1] = True
+ elif state == 2 and passing[1]:
+ entries.append(raw)
+
+ cur_indent = indent
+
+ return entries
+
+
+def write_to_socket(commands, sockpath):
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(sockpath)
+ for command in commands:
+ sock.send(command)
+ sock.close()
+
+
+if __name__ == '__main__':
+ sockpath = os.environ['UZBL_SOCKET']
+ url = urlparse.urlparse(os.environ['UZBL_URI'])
+ filepath = sys.argv[1]
+
+ mode = os.stat(filepath)[stat.ST_MODE]
+
+ if mode & stat.S_IEXEC:
+ fin = tempfile.TemporaryFile()
+ subprocess.Popen([filepath], stdout=fin).wait()
+ else:
+ fin = open(filepath, 'r')
+
+ commands = grep_url(url.hostname, url.path, fin)
+
+ fin.close()
+
+ write_to_socket(commands, sockpath)
diff --git a/examples/data/scripts/pipermail.js b/examples/data/scripts/pipermail.js
new file mode 100644
index 0000000..5ec4aa4
--- /dev/null
+++ b/examples/data/scripts/pipermail.js
@@ -0,0 +1,71 @@
+// this is a userscript inspired by "Pipermail Navigation Links" by Michael
+// Stone <http://userscripts.org/scripts/show/3174>.
+
+// it adds previous month/next month navigation links in pipermail mailing
+// list archives.
+
+// we wrap the whole thing in a function (that gets called immediately) so
+// that this script doesn't interfere with any javascript in the page.
+(function() {
+
+// figure out what page we're looking at right now
+var urlparts = document.location.toString().split("/");
+var currView = urlparts[urlparts.length-1].split("#")[0];
+var currDate = urlparts[urlparts.length-2].split("-");
+
+// figure out the URLs to the next month and previous month
+var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July',
+ 'August', 'September', 'October', 'November', 'December' ];
+
+var thisMonth = currDate[1];
+var prevMonth;
+var nextMonth;
+
+var thisYear = currDate[0];
+var prevYear = thisYear;
+var nextYear = thisYear;
+
+if(thisMonth == 'January') {
+ prevMonth = "December";
+ nextMonth = "February";
+ prevYear = parseInt(thisYear) - 1;
+} else if(thisMonth == 'December') {
+ prevMonth = "November";
+ nextMonth = "January";
+ nextYear = parseInt(thisYear) + 1;
+} else {
+ var monthNum = months.indexOf(thisMonth);
+ prevMonth = months[monthNum - 1];
+ nextMonth = months[monthNum + 1];
+}
+
+var prevHref = "../" + prevYear + "-" + prevMonth + "/" + currView;
+var nextHref = "../" + nextYear + "-" + nextMonth + "/" + currView;
+
+// find the navigation header and footer
+var selector = "a[href='date.html#start']";
+
+// if we're on a "date" page then the date link isn't displayed
+if(currView == "date.html")
+ selector = "a[href='author.html#start']";
+
+var navLinks = document.querySelectorAll(selector);
+
+// append the prev/next links to the navigation header and footer
+for(var i = 0; i < navLinks.length; i++) {
+ var victim = navLinks[i].parentNode;
+
+ var prevEl = document.createElement("a");
+ prevEl.textContent = "[ prev month ]";
+ prevEl.href = prevHref;
+
+ var nextEl = document.createElement("a");
+ nextEl.textContent = "[ next month ]";
+ nextEl.href = nextHref;
+
+ victim.appendChild(prevEl);
+ victim.appendChild(document.createTextNode(" "));
+ victim.appendChild(nextEl);
+}
+
+})();
diff --git a/examples/data/scripts/scheme.py b/examples/data/scripts/scheme.py
index 0916466..4b0b7ca 100755
--- a/examples/data/scripts/scheme.py
+++ b/examples/data/scripts/scheme.py
@@ -13,7 +13,7 @@ def detach_open(cmd):
print 'USED'
if __name__ == '__main__':
- uri = sys.argv[8]
+ uri = sys.argv[1]
u = urlparse.urlparse(uri)
if u.scheme == 'mailto':
detach_open(['xterm', '-e', 'mail', u.path])
diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh
index 203cd52..ee09cf2 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.
@@ -27,14 +30,13 @@ fi
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
-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")
@@ -43,8 +45,8 @@ case $act in
else
for url in $urls; do
$UZBL --uri "$url" &
- disown
done
+ mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~"
fi
;;
@@ -53,18 +55,17 @@ 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"
;;
"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"
;;
* )
diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh
deleted file mode 100755
index 33a24ae..0000000
--- a/examples/data/scripts/userscript.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/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
deleted file mode 100755
index 8896224..0000000
--- a/examples/data/scripts/userscripts.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/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
diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh
index f789178..354d7d1 100644
--- a/examples/data/scripts/util/dmenu.sh
+++ b/examples/data/scripts/util/dmenu.sh
@@ -60,14 +60,20 @@ fi
if dmenu --help 2>&1 | grep -q '\[-xs\]'; then
DMENU_XMMS_ARGS="-xs"
DMENU_HAS_XMMS=1
+fi
- if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then
- DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS"
- fi
+# Detect the tok patch
+if dmenu --help 2>&1 | grep -q '\[-t\]'; then
+ DMENU_XMMS_ARGS="-t"
+ DMENU_HAS_XMMS=1
+fi
+
+if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then
+ DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS"
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
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 | \
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)