aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-12-06 16:21:12 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-12-06 16:21:12 +0800
commitff64a2d37fa68015e70928a9dc7867c8d1c3815e (patch)
treeb7a7c3c294c8b5a21d4024120c49db2ee1a39d55 /examples
parent5c514a0d42324efbb60c657d171e93720ba422b1 (diff)
Standardise expansion across plugins.
Diffstat (limited to 'examples')
-rw-r--r--examples/data/uzbl/plugins/bind.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py
index 10cce6a..076d712 100644
--- a/examples/data/uzbl/plugins/bind.py
+++ b/examples/data/uzbl/plugins/bind.py
@@ -224,6 +224,20 @@ 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.'''
@@ -240,14 +254,7 @@ def exec_bind(uzbl, bind, *args, **kargs):
commands = []
for cmd in bind.commands:
- if '%s' in cmd:
- if len(args) > 1:
- for arg in args:
- cmd = cmd.replace('%s', arg, 1)
-
- elif len(args) == 1:
- cmd = cmd.replace('%s', args[0])
-
+ cmd = expand(cmd, args)
uzbl.send(cmd)