bang: hide lines when they are useless
This commit is contained in:
parent
e1cb770709
commit
ec545d5e11
14
bang.py
14
bang.py
|
@ -53,10 +53,13 @@ def list_bangs(config):
|
||||||
print(f"- {handle}: {name}")
|
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")
|
rofi_path = config.get("rofi_path", "rofi")
|
||||||
|
args = ["-dmenu", "-p", title]
|
||||||
|
if no_lines:
|
||||||
|
args += ["-l", "0"]
|
||||||
completed_process = subprocess.run(
|
completed_process = subprocess.run(
|
||||||
[rofi_path, "-dmenu", "-p", title],
|
[rofi_path] + args,
|
||||||
text=True,
|
text=True,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
input=input_text,
|
input=input_text,
|
||||||
|
@ -111,7 +114,10 @@ def main():
|
||||||
queries.append(" ".join(bang_args[1:]))
|
queries.append(" ".join(bang_args[1:]))
|
||||||
# Else show a Rofi with the list of available bangs.
|
# Else show a Rofi with the list of available bangs.
|
||||||
else:
|
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)
|
output = run_rofi(config, input_text=process_input)
|
||||||
parts = output.split(maxsplit=1)
|
parts = output.split(maxsplit=1)
|
||||||
if len(parts) < 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 no queries were obtained during options parsing, show Rofi now to get a single query.
|
||||||
if not queries:
|
if not queries:
|
||||||
queries.append(run_rofi(config, title=handle))
|
queries.append(run_rofi(config, title=handle, no_lines=True))
|
||||||
|
|
||||||
for query in queries:
|
for query in queries:
|
||||||
open_bang(config, handle, query)
|
open_bang(config, handle, query)
|
||||||
|
|
Loading…
Reference in a new issue