From ff64a2d37fa68015e70928a9dc7867c8d1c3815e Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Sun, 6 Dec 2009 16:21:12 +0800 Subject: Standardise expansion across plugins. --- examples/data/uzbl/plugins/bind.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'examples') 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 " ...".''' + + 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) -- cgit v1.2.3