#!/usr/bin/python import os, sys import os.path import subprocess as sp import re sockfile = sys.argv[5] dmenu_colors = ["-nb", "#303030", "-nf", "khaki", "-sb", "#CCFFAA", "-sf", "#303030"] dmenu_cmd = ["dmenu", "-i"] dmenu_vert = ["-b", "-xs", "-rs", "-l", "10"] dmenu_vp = re.compile("\[-rs\] \[-ni\] \[-nl\] \[-xs\]") urlparse = re.compile(r'^"([\.\s\w-]+)"\s+"([\/\.\w-]+)"') # try to find the bookmarks file... XDG_DATA_HOME = os.getenv("XDG_DATA_HOME") if XDG_DATA_HOME: bookmarks = os.path.join(XDG_DATA_HOME, 'uzbl', 'bookmarks') else: bookmarks = os.path.join(os.getenv('HOME'), '.local', 'share', 'uzbl', 'bookmarks') if not os.path.isfile(bookmarks): sys.exit() # check for dmenu and if it has the vertical patch... try: dmenuhelp = sp.Popen(["dmenu", "--help"], stderr = sp.PIPE).communicate()[1] except OSError: sys.exit() if dmenu_vp.search(dmenuhelp): # add options for vertical dmenu_cmd.extend(dmenu_vert) # add the color info #dmenu_cmd.extend(dmenu_colors) # read the file... try: f = open(bookmarks, "r") uri_lookup = dict([ urlparse.match(i).group(1,2) for i in f ]) except IOError: sys.exit() else: f.close() # now run dmenu selection = sp.Popen(dmenu_cmd, stdin=sp.PIPE, stdout=sp.PIPE).communicate('\n'.join(uri_lookup.keys()))[0] # now tell uzbl where to go... if selection: address = uri_lookup[selection] cmd = 'echo "uri %s" | socat -U %s stdin' % (address, sockfile) sp.Popen([cmd], shell=True)