1
0
Fork 0

bang: hide lines when they are useless

This commit is contained in:
Adrien Abraham 2023-10-17 10:43:20 +02:00
parent e1cb770709
commit ec545d5e11

14
bang.py
View file

@ -53,10 +53,13 @@ def list_bangs(config):
print(f"- {handle}: {name}")
def run_rofi(config, input_text="", title="bang"):
def run_rofi(config, input_text="", title="bang", no_lines=False):
rofi_path = config.get("rofi_path", "rofi")
args = ["-dmenu", "-p", title]
if no_lines:
args += ["-l", "0"]
completed_process = subprocess.run(
[rofi_path, "-dmenu", "-p", title],
[rofi_path] + args,
text=True,
capture_output=True,
input=input_text,
@ -111,7 +114,10 @@ def main():
queries.append(" ".join(bang_args[1:]))
# Else show a Rofi with the list of available bangs.
else:
process_input = "\n".join(i["handle"] for i in config["bangs"]) + "\n"
process_input = "\n".join(
i["handle"]
for i in sorted(config["bangs"], key=lambda bang: bang["handle"])
) + "\n"
output = run_rofi(config, input_text=process_input)
parts = output.split(maxsplit=1)
if len(parts) < 1:
@ -122,7 +128,7 @@ def main():
# If no queries were obtained during options parsing, show Rofi now to get a single query.
if not queries:
queries.append(run_rofi(config, title=handle))
queries.append(run_rofi(config, title=handle, no_lines=True))
for query in queries:
open_bang(config, handle, query)