···11# Changelog
2233+## Unreleased
44+55+- Add `--cwd` flag to `pty run` to start a session in a specific directory without needing to `cd` first
66+37## 0.6.0
4859### Breaking changes
+1-1
completions/pty.bash
···7070 done
7171 # Before --, complete flags
7272 if [[ "${cur}" == -* ]]; then
7373- COMPREPLY=($(compgen -W "--detach -d --attach -a --ephemeral -e --name --tag" -- "${cur}"))
7373+ COMPREPLY=($(compgen -W "--detach -d --attach -a --ephemeral -e --name --cwd --tag" -- "${cur}"))
7474 fi
7575 ;;
7676 esac
+1
completions/pty.fish
···6868complete -c pty -n '__pty_using_command run' -s a -l attach -d 'Attach if already running'
6969complete -c pty -n '__pty_using_command run' -s e -l ephemeral -d 'Auto-remove on exit'
7070complete -c pty -n '__pty_using_command run' -l name -x -d 'Session name (auto-generated if omitted)'
7171+complete -c pty -n '__pty_using_command run' -l cwd -x -a '(__fish_complete_directories)' -d 'Working directory'
7172complete -c pty -n '__pty_using_command run' -l tag -x -d 'Tag session (key=value, repeatable)'
7273complete -c pty -n '__pty_using_command run' -F
7374
+1
completions/pty.zsh
···123123 '(-a --attach)'{-a,--attach}'[Attach if already running]' \
124124 '(-e --ephemeral)'{-e,--ephemeral}'[Auto-remove on exit]' \
125125 '--name[Session name]:name:' \
126126+ '--cwd[Working directory]:dir:_directories' \
126127 '*--tag[Tag session with key=value]:tag:'
127128 ;;
128129 esac
+7-2
src/cli.ts
···3434 pty run -d -- <command> [args...] Create in the background
3535 pty run -a -- <command> [args...] Create or attach if already running
3636 pty run --tag key=value -- <command> Tag a session with metadata
3737+ pty run --cwd /path -- <command> Run in a specific directory
3738 pty attach <name> Attach to an existing session
3839 pty attach -r <name> Attach, auto-restart if exited
3940 pty peek <name> Print current screen and exit
···105106 let attachExisting = false;
106107 let ephemeral = false;
107108 let name: string | null = null;
109109+ let cwd: string | null = null;
108110 const tags: Record<string, string> = {};
109111 let i = 1;
110112 while (i < args.length && args[i] !== "--") {
···112114 else if (args[i] === "-a" || args[i] === "--attach") { attachExisting = true; i++; }
113115 else if (args[i] === "-e" || args[i] === "--ephemeral") { ephemeral = true; i++; }
114116 else if (args[i] === "--name" && i + 1 < args.length) { name = args[i + 1]; i += 2; }
117117+ else if (args[i] === "--cwd" && i + 1 < args.length) { cwd = args[i + 1]; i += 2; }
115118 else if (args[i] === "--tag" && i + 1 < args.length) {
116119 const eq = args[i + 1].indexOf("=");
117120 if (eq === -1) {
···204207 process.exit(1);
205208 }
206209207207- await cmdRun(name, cmd, cmdArgs, detach, attachExisting, displayCmd, ephemeral, tags);
210210+ await cmdRun(name, cmd, cmdArgs, detach, attachExisting, displayCmd, ephemeral, tags, cwd);
208211 break;
209212 }
210213···476479 displayCommand: string,
477480 ephemeral = false,
478481 tags: Record<string, string> = {},
482482+ explicitCwd: string | null = null,
479483): Promise<void> {
480484 const session = await getSession(name);
481485 if (session?.status === "running") {
···507511508512 try {
509513 const tagOpt = Object.keys(tags).length > 0 ? tags : previousTags;
510510- await spawnDaemon({ name, command, args, displayCommand, cwd: previousCwd, ephemeral, tags: tagOpt });
514514+ const cwdOpt = explicitCwd ?? previousCwd;
515515+ await spawnDaemon({ name, command, args, displayCommand, cwd: cwdOpt, ephemeral, tags: tagOpt });
511516 } finally {
512517 releaseLock(name);
513518 }