diff options
author | Mason Larobina <mason.larobina@gmail.com> | 2010-01-03 00:19:44 +0800 |
---|---|---|
committer | Mason Larobina <mason.larobina@gmail.com> | 2010-01-03 00:19:44 +0800 |
commit | de0cdb5c493ebe433d6b42b48758e0758cb0d68c (patch) | |
tree | fe7df27e98a12a218766cca7478c31e855762e14 /examples/data/uzbl | |
parent | d55f6c7e55a94161924e1380dd70ef72624cecd7 (diff) | |
parent | 9b23103c2c042b126c5701634530e2dc4c2d1b84 (diff) |
Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into experimental
Diffstat (limited to 'examples/data/uzbl')
-rw-r--r-- | examples/data/uzbl/plugins/bind.py | 17 | ||||
-rw-r--r-- | examples/data/uzbl/plugins/cmd_expand.py | 43 | ||||
-rw-r--r-- | examples/data/uzbl/plugins/on_event.py | 18 | ||||
-rwxr-xr-x | examples/data/uzbl/scripts/insert_bookmark.sh | 2 | ||||
-rwxr-xr-x | examples/data/uzbl/scripts/uzbl-tabbed | 2 |
5 files changed, 51 insertions, 31 deletions
diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py index 1cba7b2..9614df6 100644 --- a/examples/data/uzbl/plugins/bind.py +++ b/examples/data/uzbl/plugins/bind.py @@ -303,20 +303,6 @@ class Bind(object): return self._repr_cache -def expand(cmd, args): - '''Replaces "%s %1 %2 %3..." with "<all args> <arg 0> <arg 1>...".''' - - if '%s' in cmd: - cmd = cmd.replace('%s', ' '.join(map(unicode, args))) - - for (index, arg) in enumerate(args): - index += 1 - if '%%%d' % index in cmd: - cmd = cmd.replace('%%%d' % index, unicode(arg)) - - return cmd - - def exec_bind(uzbl, bind, *args, **kargs): '''Execute bind objects.''' @@ -332,8 +318,9 @@ def exec_bind(uzbl, bind, *args, **kargs): raise ArgumentError('cannot supply kargs for uzbl commands') commands = [] + cmd_expand = uzbl.cmd_expand for cmd in bind.commands: - cmd = expand(cmd, args) + cmd = cmd_expand(cmd, args) uzbl.send(cmd) diff --git a/examples/data/uzbl/plugins/cmd_expand.py b/examples/data/uzbl/plugins/cmd_expand.py new file mode 100644 index 0000000..a5c279d --- /dev/null +++ b/examples/data/uzbl/plugins/cmd_expand.py @@ -0,0 +1,43 @@ +__export__ = ['cmd_expand',] + + +def escape(str): + for (level, char) in [(3, '\\'), (2, "'"), (2, '"'), (1, '@')]: + str = str.replace(char, (level * '\\') + char) + + return str + + +def cmd_expand(uzbl, cmd, args): + '''Exports a function that provides the following + expansions in any uzbl command string: + + %s = replace('%s', ' '.join(args)) + %r = replace('%r', "'%s'" % escaped(' '.join(args))) + %1 = replace('%1', arg[0]) + %2 = replace('%2', arg[1]) + %n = replace('%n', arg[n-1]) + ''' + + # Ensure (1) all string representable and (2) correct string encoding. + args = map(unicode, args) + + # Direct string replace. + if '%s' in cmd: + cmd = cmd.replace('%s', ' '.join(args)) + + # Escaped and quoted string replace. + if '%r' in cmd: + cmd = cmd.replace('%r', "'%s'" % escape(' '.join(args))) + + # Arg index string replace. + for (index, arg) in enumerate(args): + index += 1 + if '%%%d' % index in cmd: + cmd = cmd.replace('%%%d' % index, unicode(arg)) + + return cmd + + +def init(*args): + pass diff --git a/examples/data/uzbl/plugins/on_event.py b/examples/data/uzbl/plugins/on_event.py index afee4e6..f1ad0c9 100644 --- a/examples/data/uzbl/plugins/on_event.py +++ b/examples/data/uzbl/plugins/on_event.py @@ -2,6 +2,7 @@ Formatting options: %s = space separated string of the arguments + %r = escaped and quoted version of %s %1 = argument 1 %2 = argument 2 %n = argument n @@ -44,20 +45,6 @@ def get_on_events(uzbl): return UZBLS[uzbl] -def expand(cmd, args): - '''Replaces "%s %1 %2 %3..." with "<all args> <arg 0> <arg 1>...".''' - - if '%s' in cmd: - cmd = cmd.replace('%s', ' '.join(map(unicode, args))) - - for (index, arg) in enumerate(args): - index += 1 - if '%%%d' % index in cmd: - cmd = cmd.replace('%%%d' % index, unicode(arg)) - - return cmd - - def event_handler(uzbl, *args, **kargs): '''This function handles all the events being watched by various on_event definitions and responds accordingly.''' @@ -68,8 +55,9 @@ def event_handler(uzbl, *args, **kargs): return commands = events[event] + cmd_expand = uzbl.cmd_expand for cmd in commands: - cmd = expand(cmd, args) + cmd = cmd_expand(cmd, args) uzbl.send(cmd) diff --git a/examples/data/uzbl/scripts/insert_bookmark.sh b/examples/data/uzbl/scripts/insert_bookmark.sh index e04e6d4..c34e7db 100755 --- a/examples/data/uzbl/scripts/insert_bookmark.sh +++ b/examples/data/uzbl/scripts/insert_bookmark.sh @@ -6,6 +6,8 @@ file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks which zenity &>/dev/null || exit 2 entry=`zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$6 $7\t"` +exitstatus=$? +if [ $exitstatus -ne 0 ]; then exit $exitstatus; fi url=`echo $entry | awk '{print $1}'` # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags diff --git a/examples/data/uzbl/scripts/uzbl-tabbed b/examples/data/uzbl/scripts/uzbl-tabbed index bb9b9a2..d93a3f4 100755 --- a/examples/data/uzbl/scripts/uzbl-tabbed +++ b/examples/data/uzbl/scripts/uzbl-tabbed @@ -1010,7 +1010,7 @@ class UzblTabbed: instance.''' binds = [] - bind_format = r'bind %s = sh "echo \"%s\" > \"%s\""' + bind_format = r'@bind %s = sh "echo \"%s\" > \"%s\""' bind = lambda key, action: binds.append(bind_format % (key, action,\ self.fifo_socket)) |