From 5bc6cff38469541751d90627b6cd15750bf17a34 Mon Sep 17 00:00:00 2001 From: DavHau Date: Mon, 9 Sep 2024 20:48:44 +0200 Subject: [PATCH] select-shell: show available names if provided name is incorrect --- pkgs/scripts/select-shell.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/scripts/select-shell.py b/pkgs/scripts/select-shell.py index c4e25b915..4360d680b 100644 --- a/pkgs/scripts/select-shell.py +++ b/pkgs/scripts/select-shell.py @@ -32,7 +32,7 @@ def print_current_shell() -> None: print("No devshell selected") -def print_devshells() -> None: +def list_devshells() -> list[str]: project_root = os.environ.get("PRJ_ROOT") flake_show = subprocess.run( [ @@ -47,7 +47,12 @@ def print_devshells() -> None: stdout=subprocess.PIPE, ) names = json.loads(flake_show.stdout.decode()) - print("Available devshells:\n") + return names + + +def print_devshells() -> None: + names = list_devshells() + print("Available devshells:") print("\n".join(names)) @@ -55,6 +60,9 @@ def select_shell(shell: str) -> None: if shell == get_current_shell(): print(f"{shell} devshell already selected. No changes made.") sys.exit(0) + elif shell not in (names := list_devshells()): + print(f"devshell '{shell}' not found. Available devshells:") + print("\n".join(names)) else: with selected_shell_file.open("w") as f: f.write(shell)