Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-301.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `pluk send --session=<name>` / `pluk-send --session=<name>` 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.
7 changes: 5 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
18 changes: 18 additions & 0 deletions test/cli-branches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading