Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions config/bash/zellij.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,19 @@ if declare -F _red_zellij_launch >/dev/null 2>&1; then
)"

_red_zellij_status=1
while IFS= read -r _red_zellij_session; do
# Read candidates on fd 9 so an interactive attach keeps the terminal on
# stdin. Feeding this loop with a plain here-document replaces fd 0 with a
# pipe for every command in the body. Zellij's stdin threads then spin on
# EOF while its output still targets the tty, freezing the terminal client.
while IFS= read -r _red_zellij_session <&9; do
[ -n "$_red_zellij_session" ] || continue
printf '%s\n' "$_red_zellij_session" >"$_red_zellij_last.tmp-$$" 2>/dev/null &&
mv -f "$_red_zellij_last.tmp-$$" "$_red_zellij_last" 2>/dev/null
RED_IN_ZELLIJ=1 _red_zellij_launch attach "$_red_zellij_session" \
2>>"$_red_zellij_log"
_red_zellij_status=$?
[ "$_red_zellij_status" -eq 0 ] && break
done <<EOF
done 9<<EOF
$_red_zellij_candidates
EOF

Expand Down
12 changes: 11 additions & 1 deletion src/zellij-autostart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ if [ "\${1:-}" = "attach" ]; then
create=1
shift
fi
echo "STUB RED_IN_ZELLIJ=$RED_IN_ZELLIJ ATTACH=\${1:-} CREATE=$create"
stdin_tty=0
[ -t 0 ] && stdin_tty=1
echo "STUB RED_IN_ZELLIJ=$RED_IN_ZELLIJ ATTACH=\${1:-} CREATE=$create STDIN_TTY=$stdin_tty"
if [ "\${1:-}" = "\${STUB_BAD_SESSION:-}" ]; then
echo "invalid saved session: \${1:-}" >&2
exit 7
Expand Down Expand Up @@ -162,6 +164,14 @@ describe("zellij autostart", () => {
});

describe("resumes the last valid session", () => {
test("keeps the terminal on stdin while reading session candidates", () => {
const r = run({
STUB_SESSIONS: "live [Created 2h ago]",
}, true);

expect(r.out).toContain("ATTACH=live CREATE=0 STDIN_TTY=1");
});

test("prefers the newest live session over serialized exited sessions", () => {
const r = run({
STUB_SESSIONS:
Expand Down