Skip to content

Commit f0ca87c

Browse files
committed
Fix session renaming issue
1 parent d91bb3e commit f0ca87c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

tests/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ RUN chown -R alice:alice /home/alice/.config
4949
COPY ./tests/package.json ./package.json
5050
COPY ./tests/tui-test.config.js ./tui-test.config.js
5151
COPY ./tests/main.test.js ./main.test.js
52+
COPY ./tests/session-rename.test.js ./session-rename.test.js
5253
COPY ./tests/stable-id.test.js ./stable-id.test.js
5354
COPY ./tests/test-utils.js ./test-utils.js
5455
RUN chown -R alice:alice /tests

tests/session-rename.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { test, expect } from "@microsoft/tui-test";
2+
import {
3+
writeLine,
4+
expectViewToContain,
5+
maybeApprovePermissions,
6+
} from "./test-utils.js";
7+
8+
test.use({ program: { file: "/bin/zsh" } });
9+
10+
const initialSessionName = `rename-session-${Date.now()}`;
11+
const renamedSessionName = `${initialSessionName}-renamed`;
12+
const targetDir = `renamed-session-test-${Date.now()}`;
13+
const backgroundSessionName = `${initialSessionName}-background`;
14+
15+
test("continues handling cd after renaming the session with multiple sessions present", async ({ terminal }) => {
16+
await expect(
17+
terminal.getByText("Using config /home/alice/.zshrc", { full: true }),
18+
).toBeVisible();
19+
20+
writeLine(terminal, "cd");
21+
await expect(terminal.getByText("~ $", { strict: false })).toBeVisible();
22+
23+
writeLine(terminal, `zellij attach -b ${backgroundSessionName}`);
24+
await expectViewToContain(terminal, "~ $", 10000);
25+
26+
writeLine(terminal, `zellij attach -c ${initialSessionName}`);
27+
await expect(terminal.getByText("Pane #1", { full: true })).toBeVisible({
28+
timeout: 10000,
29+
});
30+
await maybeApprovePermissions(terminal);
31+
await expect(
32+
terminal.getByText("Using config /home/alice/.zshrc", { full: true }),
33+
).toBeVisible();
34+
await expect(terminal.getByText("~ $", { strict: false })).toBeVisible();
35+
await expectViewToContain(terminal, `Zellij (${initialSessionName}) Tab #1`);
36+
37+
writeLine(terminal, `mkdir ${targetDir}`);
38+
await expectViewToContain(terminal, "~ $", 10000);
39+
40+
writeLine(terminal, `zellij action rename-session ${renamedSessionName}`);
41+
writeLine(terminal, "env | sort | grep '^ZELLIJ_SESSION_NAME='");
42+
await expectViewToContain(
43+
terminal,
44+
`ZELLIJ_SESSION_NAME=${renamedSessionName}`,
45+
10000,
46+
);
47+
48+
writeLine(terminal, `cd ${targetDir}`);
49+
await expectViewToContain(terminal, `~/${targetDir} $`, 10000);
50+
51+
writeLine(terminal, "pwd");
52+
await expectViewToContain(terminal, `/home/alice/${targetDir}`, 10000);
53+
});

zellij-tabula.plugin.zsh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
export ZELLIJ_TABULA_ZSH_PLUGIN_VERSION="0.2.0"
22

3+
zellij() {
4+
command zellij "$@"
5+
local exit_code=$?
6+
7+
# Zellij keeps the old session name in existing shells after
8+
# `action rename-session`, which makes later CLI calls like `pipe` hang.
9+
if [[ $exit_code -eq 0 && "$1" == "action" && "$2" == "rename-session" && -n "$3" ]]; then
10+
export ZELLIJ_SESSION_NAME="$3"
11+
fi
12+
13+
if [[ $exit_code -eq 0 && "$1" == "ac" && "$2" == "rename-session" && -n "$3" ]]; then
14+
export ZELLIJ_SESSION_NAME="$3"
15+
fi
16+
17+
return $exit_code
18+
}
19+
320
chpwd() {
421
if [[ -n $ZELLIJ ]]; then
522
zellij pipe --name tabula -- "'$ZELLIJ_PANE_ID' '$PWD'"

0 commit comments

Comments
 (0)