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
2 changes: 1 addition & 1 deletion home-manager/modules/local-scripts/clipboard-copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

# OSC 52 fallback: works over SSH if the terminal supports it
# (ghostty, iTerm2, kitty, alacritty, tmux, etc.)
if [[ -t 1 ]] || [[ -n ${TMUX:-} ]] || [[ -n ${SSH_TTY:-} ]]; then
if [[ -t 1 ]] || [[ -n ${TMUX:-} ]] || [[ -n ${ZELLIJ:-} ]] || [[ -n ${SSH_TTY:-} ]]; then
data=$(base64 | tr -d '\n')
printf '\033]52;c;%s\a' "$data"
exit 0
Expand Down
42 changes: 41 additions & 1 deletion spec/clipboard_copy_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,46 @@ The output should start with $'\033]52;c;'
End
End

Describe 'when no clipboard backend but ZELLIJ is set'
setup() {
MOCK_BIN="$(mktemp -d)"
MOCK_ORIGINAL_PATH="${PATH:-}"
MOCK_ORIGINAL_WAYLAND="${WAYLAND_DISPLAY:-}"
MOCK_ORIGINAL_ZELLIJ="${ZELLIJ:-}"
# Symlink only the commands the script needs into MOCK_BIN to avoid
# leaking pbcopy/xclip/etc. from shared directories like /usr/bin
local cmd
for cmd in bash base64 tr printf; do
ln -sf "$(command -v "$cmd")" "$MOCK_BIN/$cmd"
done
export PATH="$MOCK_BIN"
unset WAYLAND_DISPLAY

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new Zellij test is not isolated: SSH_TTY/TMUX are left untouched, so it can false-pass via another OSC 52 trigger instead of validating Zellij detection.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At spec/clipboard_copy_spec.sh, line 136:

<comment>The new Zellij test is not isolated: `SSH_TTY`/`TMUX` are left untouched, so it can false-pass via another OSC 52 trigger instead of validating Zellij detection.</comment>

<file context>
@@ -120,6 +120,46 @@ The output should start with $'\033]52;c;'
+    ln -sf "$(command -v "$cmd")" "$MOCK_BIN/$cmd"
+  done
+  export PATH="$MOCK_BIN"
+  unset WAYLAND_DISPLAY
+  export ZELLIJ=0
+  export MOCK_BIN MOCK_ORIGINAL_PATH MOCK_ORIGINAL_WAYLAND MOCK_ORIGINAL_ZELLIJ
</file context>

export ZELLIJ=0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setup sets ZELLIJ=0 and unsets WAYLAND_DISPLAY, but doesn't unset TMUX or SSH_TTY. If the suite runs inside a tmux pane or over SSH, the OSC 52 fallback would fire from those variables and the test would pass even if the new ZELLIJ branch in clipboard-copy.sh were broken.

The "no backend" cleanup already does unset WAYLAND_DISPLAY SSH_TTY TMUX ZELLIJ (line 171) for exactly this reason — worth doing the same here:

MOCK_ORIGINAL_TMUX="${TMUX:-}"
MOCK_ORIGINAL_SSH_TTY="${SSH_TTY:-}"unset WAYLAND_DISPLAY TMUX SSH_TTY
export ZELLIJ=0

and restore both in cleanup(). The pre-existing SSH_TTY block (lines 83–121) has the same gap and would benefit from the same treatment.

export MOCK_BIN MOCK_ORIGINAL_PATH MOCK_ORIGINAL_WAYLAND MOCK_ORIGINAL_ZELLIJ
}
cleanup() {
export PATH="$MOCK_ORIGINAL_PATH"
if [ -n "$MOCK_ORIGINAL_WAYLAND" ]; then
export WAYLAND_DISPLAY="$MOCK_ORIGINAL_WAYLAND"
fi
if [ -n "$MOCK_ORIGINAL_ZELLIJ" ]; then
export ZELLIJ="$MOCK_ORIGINAL_ZELLIJ"
else
unset ZELLIJ
fi
rm -rf "$MOCK_BIN"
unset MOCK_BIN MOCK_ORIGINAL_PATH MOCK_ORIGINAL_WAYLAND MOCK_ORIGINAL_ZELLIJ
}
Before 'setup'
After 'cleanup'

It 'uses OSC 52 escape sequence'
When run bash "$SCRIPT" <<<"hello"
The status should be success
The output should start with $'\033]52;c;'
End
End

Describe 'when no clipboard backend is available'
setup() {
MOCK_BIN="$(mktemp -d)"
Expand All @@ -128,7 +168,7 @@ setup() {
MOCK_ORIGINAL_SSH_TTY="${SSH_TTY:-}"
ln -sf "$(command -v bash)" "$MOCK_BIN/bash"
export PATH="$MOCK_BIN"
unset WAYLAND_DISPLAY SSH_TTY TMUX
unset WAYLAND_DISPLAY SSH_TTY TMUX ZELLIJ
export MOCK_BIN MOCK_ORIGINAL_PATH MOCK_ORIGINAL_WAYLAND MOCK_ORIGINAL_SSH_TTY
}
cleanup() {
Expand Down
Loading