opencode
opencode copied to clipboard
copying to clipboard doesn't work in a remote session (like a devcontainer)
Description
For example: /share is great but it appears to only support copying directly to the clipboard. It'd be nice to print the actual URL so people can copy it from a terminal themselves, or even better it'd be nice to support copying out to the host automatically.
The wrapper helped me in a vscode devcontainer:
diff --git a/.devcontainer/osc52-clipboard b/.devcontainer/osc52-clipboard
new file mode 100644
index 00000000..0f350c2b
--- /dev/null
+++ b/.devcontainer/osc52-clipboard
@@ -0,0 +1,17 @@
+#!/bin/bash
+# OSC 52 clipboard wrapper for devcontainers
+# Sends clipboard data to the host terminal via OSC 52 escape sequences
+# This works in VS Code terminal and most modern terminal emulators
+
+# Read from stdin and base64 encode
+data=$(cat | base64 | tr -d '\n')
+
+# Write directly to the controlling terminal, bypassing any TUI that might
+# be capturing stdout. This ensures the escape sequence reaches VS Code.
+if [ -n "$TTY" ]; then
+ printf "\e]52;c;%s\a" "$data" > "$TTY"
+elif [ -e /dev/tty ]; then
+ printf "\e]52;c;%s\a" "$data" > /dev/tty
+else
+ printf "\e]52;c;%s\a" "$data"
+fi
diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh
index 8118ff3e..0a708fbe 100644
--- a/.devcontainer/setup.sh
+++ b/.devcontainer/setup.sh
@@ -1,5 +1,12 @@
#!/bin/bash -ex
+# Install OSC 52 clipboard wrapper (enables clipboard in devcontainer -> host)
+cp .devcontainer/osc52-clipboard /usr/local/bin/
+chmod +x /usr/local/bin/osc52-clipboard
+# Create symlinks so tools that call xclip/xsel use our OSC 52 wrapper
+ln -sf /usr/local/bin/osc52-clipboard /usr/local/bin/xclip
+ln -sf /usr/local/bin/osc52-clipboard /usr/local/bin/xsel
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response