diff --git a/changelog.d/fixed-301.md b/changelog.d/fixed-301.md new file mode 100644 index 0000000..df4009e --- /dev/null +++ b/changelog.d/fixed-301.md @@ -0,0 +1 @@ +- `pluk send --session=` / `pluk-send --session=` no longer drops a positional text word that happens to equal the session name; the leading positional is treated as the session only when `--session` is absent. diff --git a/src/cli.ts b/src/cli.ts index 5b6b76b..3c8fdf6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -355,8 +355,11 @@ function cmdPatterns(args: string[]): void { function cmdSend(args: string[]): void { const { positional, flags } = parseArgs(args); - const session = flags['session'] ?? positional[0]; - const text = flags['text'] ?? positional.slice(session === positional[0] ? 1 : 0).join(' '); + // The leading positional is the session only when --session was not given; + // deciding by value would drop a text word that happens to equal the name. + const sessionFromFlag = flags['session'] !== undefined; + const session = sessionFromFlag ? flags['session'] : positional[0]; + const text = flags['text'] ?? positional.slice(sessionFromFlag ? 0 : 1).join(' '); if (!session) { console.error(`${paintStderr(ANSI_RED, 'Error:')} session name is required`); diff --git a/test/cli-branches.test.js b/test/cli-branches.test.js index d89253b..3227c06 100644 --- a/test/cli-branches.test.js +++ b/test/cli-branches.test.js @@ -111,6 +111,24 @@ test('pluk-send --session takes all positional args as text', () => { assert.deepEqual(calls, ['send-keys -t =agent-q: -- ping pong']); }); +test('send --session keeps a positional text word equal to the session name', () => { + rmSync(tmuxLog, { force: true }); + const { code } = runCli(['send', '--session=foo', 'foo', 'bar']); + assert.equal(code, 0); + const calls = readFileSync(tmuxLog, 'utf-8').trim().split('\n'); + assert.deepEqual(calls, ['send-keys -t =foo: -- foo bar']); +}); + +test('pluk-send --session sends a single positional word equal to the session name', () => { + const link = join(scratch, 'pluk-send'); + try { symlinkSync(CLI, link); } catch {} + rmSync(tmuxLog, { force: true }); + const { code } = runCli(['--session=foo', 'foo'], { argv1: link }); + assert.equal(code, 0); + const calls = readFileSync(tmuxLog, 'utf-8').trim().split('\n'); + assert.deepEqual(calls, ['send-keys -t =foo: -- foo']); +}); + // --- watch: default session, --patterns-dir ------------------------------------ test('watch without a session labels events "stdin" and honors --patterns-dir', () => {