From b1b605ef4b4bcdb4ae080cb9a596ce39892e58f4 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 30 Dec 2009 02:10:35 +0200 Subject: uzbl-tabbed bind '@' fix --- examples/data/uzbl/scripts/uzbl-tabbed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') 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)) -- cgit v1.2.3 From aaa0654ffaf3c081ce8f0721340e61b2a3ce15e6 Mon Sep 17 00:00:00 2001 From: tczy Date: Tue, 29 Dec 2009 18:40:42 +0200 Subject: fixed http://www.uzbl.org/bugs/index.php?do=details&task_id=165 using supplied patch --- examples/data/uzbl/scripts/insert_bookmark.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples') 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 -- cgit v1.2.3 From 5fab9b5f81ff0d7eeebbd1bf07f4b945e1454165 Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Wed, 23 Dec 2009 21:15:18 +0800 Subject: Added the escaped and quoted %r replace for on_event and bind args. --- examples/data/uzbl/plugins/bind.py | 10 ++++++++++ examples/data/uzbl/plugins/on_event.py | 11 +++++++++++ 2 files changed, 21 insertions(+) (limited to 'examples') diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py index 1cba7b2..668b595 100644 --- a/examples/data/uzbl/plugins/bind.py +++ b/examples/data/uzbl/plugins/bind.py @@ -306,9 +306,19 @@ class Bind(object): def expand(cmd, args): '''Replaces "%s %1 %2 %3..." with " ...".''' + # Direct string replace. if '%s' in cmd: cmd = cmd.replace('%s', ' '.join(map(unicode, args))) + # Escaped and quoted string replace. + if '%r' in cmd: + joined = ('%r' % ' '.join(map(unicode, args)))[1:] + for char in ['\\', '@']: + joined = joined.replace(char, '\\'+char) + + cmd = cmd.replace('%r', joined) + + # Arg index string replace. for (index, arg) in enumerate(args): index += 1 if '%%%d' % index in cmd: diff --git a/examples/data/uzbl/plugins/on_event.py b/examples/data/uzbl/plugins/on_event.py index afee4e6..9d2525b 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 @@ -47,9 +48,19 @@ def get_on_events(uzbl): def expand(cmd, args): '''Replaces "%s %1 %2 %3..." with " ...".''' + # Direct string replace. if '%s' in cmd: cmd = cmd.replace('%s', ' '.join(map(unicode, args))) + # Escaped and quoted string replace. + if '%r' in cmd: + joined = ('%r' % ' '.join(map(unicode, args)))[1:] + for char in ['\\', '@']: + joined = joined.replace(char, '\\'+char) + + cmd = cmd.replace('%r', joined) + + # Arg index string replace. for (index, arg) in enumerate(args): index += 1 if '%%%d' % index in cmd: -- cgit v1.2.3 From d324593e958f89bf15478f60269688b2ca0c1b4a Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Thu, 24 Dec 2009 00:27:19 +0800 Subject: Moved expand function to external plugin to reduce code duplication. --- examples/data/uzbl/plugins/bind.py | 27 ++------------------ examples/data/uzbl/plugins/cmd_expand.py | 43 ++++++++++++++++++++++++++++++++ examples/data/uzbl/plugins/on_event.py | 27 ++------------------ 3 files changed, 47 insertions(+), 50 deletions(-) create mode 100644 examples/data/uzbl/plugins/cmd_expand.py (limited to 'examples') diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py index 668b595..9614df6 100644 --- a/examples/data/uzbl/plugins/bind.py +++ b/examples/data/uzbl/plugins/bind.py @@ -303,30 +303,6 @@ class Bind(object): return self._repr_cache -def expand(cmd, args): - '''Replaces "%s %1 %2 %3..." with " ...".''' - - # Direct string replace. - if '%s' in cmd: - cmd = cmd.replace('%s', ' '.join(map(unicode, args))) - - # Escaped and quoted string replace. - if '%r' in cmd: - joined = ('%r' % ' '.join(map(unicode, args)))[1:] - for char in ['\\', '@']: - joined = joined.replace(char, '\\'+char) - - cmd = cmd.replace('%r', joined) - - # 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 exec_bind(uzbl, bind, *args, **kargs): '''Execute bind objects.''' @@ -342,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 9d2525b..f1ad0c9 100644 --- a/examples/data/uzbl/plugins/on_event.py +++ b/examples/data/uzbl/plugins/on_event.py @@ -45,30 +45,6 @@ def get_on_events(uzbl): return UZBLS[uzbl] -def expand(cmd, args): - '''Replaces "%s %1 %2 %3..." with " ...".''' - - # Direct string replace. - if '%s' in cmd: - cmd = cmd.replace('%s', ' '.join(map(unicode, args))) - - # Escaped and quoted string replace. - if '%r' in cmd: - joined = ('%r' % ' '.join(map(unicode, args)))[1:] - for char in ['\\', '@']: - joined = joined.replace(char, '\\'+char) - - cmd = cmd.replace('%r', joined) - - # 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 event_handler(uzbl, *args, **kargs): '''This function handles all the events being watched by various on_event definitions and responds accordingly.''' @@ -79,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) -- cgit v1.2.3 From cf98a9a7f1713c81ba855f79de2a48aa1f994714 Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Sat, 26 Dec 2009 19:27:56 +0800 Subject: URIEncode search string component of web searching binds. --- examples/config/uzbl/config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index 9dc4a35..a6be6d6 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -230,9 +230,9 @@ set open_new_window = sh 'uzbl-browser -u \@SELECTED_URI' @cbind N = search_reverse # --- Web searching binds --- -@cbind gg_ = uri http://www.google.com/search?q=%s -@cbind \\awiki_ = uri http://wiki.archlinux.org/index.php/Special:Search?search=%s&go=Go -@cbind \\wiki_ = uri http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s&go=Go +@cbind gg_ = uri http://www.google.com/search?q=\@\@ +@cbind \\awiki_ = uri http://wiki.archlinux.org/index.php/Special:Search?search=\@\@&go=Go +@cbind \\wiki_ = uri http://en.wikipedia.org/w/index.php?title=Special:Search&search=\@\@&go=Go # --- Handy binds --- # Set function shortcut -- cgit v1.2.3