1
0
Fork 0

Compare commits

...

2 commits

Author SHA1 Message Date
Adrien Abraham 308f3a6ece rofibangs: add option to specify bang 2022-08-18 11:10:44 +02:00
Adrien Abraham 48ed29efb5 install-pylsp 2022-08-18 11:10:14 +02:00
2 changed files with 30 additions and 18 deletions

13
install-pylsp.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
pip3 install python-lsp-server
ask_install() {
packages="$@"
read -p "Install $packages? [y/n] " -n 1 -r ; echo
[[ "$REPLY" = y ]] && pip3 install $packages
}
ask_install pyflakes
ask_install black python-lsp-black
ask_install mypy pylsp-mypy

View file

@ -28,9 +28,8 @@ import webbrowser
def load_config(config_path=None):
if config_path is None:
config_path = os.environ.get(
"ROFIBANGS_CONFIG_PATH",
os.path.expanduser("~/.config/rofibangs.json")
config_path = os.environ.get("ROFIBANGS_CONFIG_PATH") or os.path.expanduser(
"~/.config/rofibangs.json"
)
try:
with open(config_path, "rt") as bangs_file:
@ -52,7 +51,7 @@ def run_rofi(config, input_text="", title="bang"):
[rofi_path, "-dmenu", "-p", title],
text=True,
capture_output=True,
input=input_text
input=input_text,
)
output = completed_process.stdout
if not output:
@ -73,12 +72,9 @@ def open_bang(config, handle, query):
def main():
ap = argparse.ArgumentParser()
ap.add_argument(
"-c", "--config", help="path to JSON config file"
)
ap.add_argument(
"-l", "--list", action="store_true", help="show available bangs"
)
ap.add_argument("-c", "--config", help="path to JSON config file")
ap.add_argument("-l", "--list", action="store_true", help="show available bangs")
ap.add_argument("-b", "--bang", help="launch with this bang already set")
args = ap.parse_args()
config = load_config()
@ -89,6 +85,9 @@ def main():
list_bangs(config)
return
if handle := args.bang:
query = run_rofi(config, title=handle)
else:
process_input = "\n".join(i["handle"] for i in config["bangs"]) + "\n"
output = run_rofi(config, input_text=process_input)
parts = output.split(maxsplit=1)