Skip to content

option to set initial query #7

Description

@thinlines

Hi! Great script, thanks for writing it. I wanted to be able to set the initial query string to make pmenu more useful in bash scripting, so I went ahead and made a few changes. It seems to work okay, though I'm barely a novice in python. Here's a patch:

diff --unified --recursive a/pmenu b/pmenu
--- a/pmenu	2021-07-06 01:33:36.554971843 +0800
+++ b/pmenu	2021-07-06 01:00:54.000000000 +0800
@@ -21,6 +21,7 @@
 def get_args():
     parser = argparse.ArgumentParser(usage="pipe newline-separated menu items to stdin and/or pass them as positional arguments")
     parser.add_argument('item', nargs='*', help="the menu item text")
+    parser.add_argument('-q', '--query', help="start with the given query")
     parser.add_argument('-c', '--command', help="the shell command which output will populate the menu items on every keystroke ({} will be replaced by the current input text)")
     parser.add_argument('-n', '--name', help="the cache file name with the most recently used items")
     parser.add_argument('-p', '--prompt', help="the prompt text")
@@ -34,6 +35,14 @@
 
     return args
 
+def get_query_text():
+    if not args.query:
+        query_text = ''
+        return query_text
+
+    query_text = args.query
+    return query_text
+
 def get_mru_path():
     if not args.name:
         return
@@ -268,7 +277,7 @@
 
 if __name__ == '__main__':
     args = get_args()
-    query_text = ''
+    query_text = get_query_text()
     input_items = get_input_items()
     mru_path = get_mru_path()
     mru_items = get_mru_items(mru_path, input_items)

Just thought I'd throw this on here in case anyone's interested. If you want me to submit a pull request, I'd be glad to. Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions