Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to set initial query #7

Open
thinlines opened this issue Jul 5, 2021 · 1 comment
Open

option to set initial query #7

thinlines opened this issue Jul 5, 2021 · 1 comment

Comments

@thinlines
Copy link

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!

@sgtpep
Copy link
Owner

sgtpep commented Jul 13, 2021

Hi, @thinlines! I'm happy to hear that you find the script useful. Thanks for your suggestion, it totally makes sense to make it customizable. Will be happy to accept a PR. How about simplifying to a bit to something like this:

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', default='', 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_mru_path():
     if not args.name:
         return
@@ -268,7 +277,7 @@
 
 if __name__ == '__main__':
     args = get_args()
-    query_text = ''
+    query_text = args.query
     input_items = get_input_items()
     mru_path = get_mru_path()
     mru_items = get_mru_items(mru_path, input_items)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants