diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/workspaces.py b/workspaces.py index 2a332b8..91da02c 100755 --- a/workspaces.py +++ b/workspaces.py @@ -524,6 +524,8 @@ def pick_workspace_with_iterfzf(workspaces: list[Path]) -> Path | None: """Use iterfzf (Python library) to pick a workspace from a list of paths. """ names = [w.name for w in workspaces] + if not names: + return None choice = iterfzf(names, prompt="pick a workspace> ") if not choice: @@ -1434,6 +1436,7 @@ def create_if_needed_and_attach( - If session doesn't exist: create_detached_session() - Then `tmux switch-client -t session_name` """ + session_name = session_name.strip().replace(" ", "_").replace(':', '_').replace('.', '_').replace('/', '_') if not_in_tmux(): r = run_tmux( ["new-session", "-As", session_name, "-c", str(path_name)], @@ -1503,7 +1506,8 @@ def tmux_cli_attach( ), ), ): - """Attach or create a session for a repo in a workspace. + """ + Attach or create a session for a repo in a workspace. """ _settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx) ws_dir = find_workspace_dir(workspaces_dir, workspace) @@ -1608,6 +1612,13 @@ def attach( ), ), ): + _settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx) + if len(list_workspaces(workspaces_dir)) == 0: + import sys + cmd = sys.executable + console.print("[red]No workspaces found. Exiting.[/red]") + console.print(f"Create a workspace with `[yellow]workspaces create[/yellow]` first.") + raise typer.Exit(1) if in_tmux(): tmux_cli_attach(ctx, workspace)