1
0
Fork 0

Compare commits

..

2 commits

Author SHA1 Message Date
Adrien Abraham ec545d5e11 bang: hide lines when they are useless 2023-10-17 10:44:36 +02:00
Adrien Abraham e1cb770709 print-colors.sh 2023-10-17 10:44:36 +02:00
2 changed files with 20 additions and 4 deletions

14
bang.py
View file

@ -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)

10
print-colors.sh Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env sh
# From https://github.com/alacritty/alacritty-theme, license Apache 2.0.
printf "|039| \033[39mDefault \033[m |049| \033[49mDefault \033[m |037| \033[37mLight gray \033[m |047| \033[47mLight gray \033[m\n"
printf "|030| \033[30mBlack \033[m |040| \033[40mBlack \033[m |090| \033[90mDark gray \033[m |100| \033[100mDark gray \033[m\n"
printf "|031| \033[31mRed \033[m |041| \033[41mRed \033[m |091| \033[91mLight red \033[m |101| \033[101mLight red \033[m\n"
printf "|032| \033[32mGreen \033[m |042| \033[42mGreen \033[m |092| \033[92mLight green \033[m |102| \033[102mLight green \033[m\n"
printf "|033| \033[33mYellow \033[m |043| \033[43mYellow \033[m |093| \033[93mLight yellow \033[m |103| \033[103mLight yellow \033[m\n"
printf "|034| \033[34mBlue \033[m |044| \033[44mBlue \033[m |094| \033[94mLight blue \033[m |104| \033[104mLight blue \033[m\n"
printf "|035| \033[35mMagenta \033[m |045| \033[45mMagenta \033[m |095| \033[95mLight magenta \033[m |105| \033[105mLight magenta \033[m\n"
printf "|036| \033[36mCyan \033[m |046| \033[46mCyan \033[m |096| \033[96mLight cyan \033[m |106| \033[106mLight cyan \033[m\n"