# HG changeset patch # User Jeff Hammel # Date 1368240227 25200 # Node ID 03d62a2cbe62deccb877bd37da3e8c5f5c3d449c # Parent e1a861bbb5593d1dff5e76d9a6690db7708570d4 update demnu to almost a real program diff -r e1a861bbb559 -r 03d62a2cbe62 python/dmenu.py --- a/python/dmenu.py Fri May 10 14:25:29 2013 -0700 +++ b/python/dmenu.py Fri May 10 19:43:47 2013 -0700 @@ -5,14 +5,19 @@ import subprocess import sys -def choose_file(directory, dmenu='dmenu'): +def choose_file(directory, dmenu='dmenu', + args=('-i', '-nb', 'black', '-nf', 'white')): """choose a file in the directory with dmenu""" directory = os.path.abspath(directory) files = os.listdir(directory) string = '\n'.join(files) + if isinstance(dmenu, basestring): + dmenu = [dmenu] + dmenu = list(dmenu) + dmenu.extend(args) - process = subprocess.Popen([dmenu, '-i'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + process = subprocess.Popen(dmenu, stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout, _ = process.communicate(input=string) if process.returncode: return @@ -23,7 +28,19 @@ def main(args=sys.argv[1:]): parser = optparse.OptionParser() - print choose_file(os.getcwd()) + parser.add_option('-d', '--directory', dest='directory', + default=os.getcwd(), + help="call on this directory [Default: current directory]") + parser.add_option('-e', '--exec', dest='executable', + help="call this proram with the result") + options, args = parser.parse_args(args) + chosen = choose_file(options.directory) + if chosen: + if options.executable: + pass + print chosen + else: + sys.exit(1) if __name__ == '__main__': main()