Ubuntu terminal opencode can't copy the text in the window, "Copied to clipboard" showed #7294

Closed
opened 2026-02-16 18:06:44 -05:00 by yindo · 3 comments
Owner

Originally created by @hanwsf on GitHub (Jan 23, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Ubuntu terminal opencode can't copy the text in the window, "Copied to clipboard" showed when use cusor to select the text

Plugins

No response

OpenCode version

V1.1.31, V1.1.33

Steps to reproduce

In any tasks

Screenshot and/or share link

Image

Operating System

Ubuntu 22.04

Terminal

Terminal

Originally created by @hanwsf on GitHub (Jan 23, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description Ubuntu terminal opencode can't copy the text in the window, "Copied to clipboard" showed when use cusor to select the text ### Plugins _No response_ ### OpenCode version V1.1.31, V1.1.33 ### Steps to reproduce In any tasks ### Screenshot and/or share link <img width="1040" height="370" alt="Image" src="https://github.com/user-attachments/assets/f6d2ea65-28b3-45d3-a5a9-23453363d5bc" /> ### Operating System Ubuntu 22.04 ### Terminal Terminal
yindo added the opentuibug labels 2026-02-16 18:06:44 -05:00
yindo closed this issue 2026-02-16 18:06:44 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 23, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #7048: Copy Text "Copied to clipboard" does never work - Similar Ubuntu terminal copy issue
  • #4283: Copy To Clipboard is not working - Ubuntu 24.04 default terminal with same symptoms
  • #10128: [WSL][tmux] opencode cannot copy text in WSL tmux - Related terminal environment copy issues
  • #5879: Clipboard copy in WSL - WSL clipboard copy failures
  • #6110: Wayland clipboard copy doesn't populate primary clipboard selection - Linux clipboard sync issue
  • #9942: Copy-on-Select fails when running opencode via Tmux in Kitty terminal (Linux) - Similar Linux/tmux environment issue
  • #8046: [BUG] Clipboard copy only works first time after upgrading to v1.1.14 - Clipboard regression issue

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 23, 2026): This issue might be a duplicate of existing issues. Please check: - #7048: Copy Text "Copied to clipboard" does never work - Similar Ubuntu terminal copy issue - #4283: Copy To Clipboard is not working - Ubuntu 24.04 default terminal with same symptoms - #10128: [WSL][tmux] opencode cannot copy text in WSL tmux - Related terminal environment copy issues - #5879: Clipboard copy in WSL - WSL clipboard copy failures - #6110: Wayland clipboard copy doesn't populate primary clipboard selection - Linux clipboard sync issue - #9942: Copy-on-Select fails when running opencode via Tmux in Kitty terminal (Linux) - Similar Linux/tmux environment issue - #8046: [BUG] Clipboard copy only works first time after upgrading to v1.1.14 - Clipboard regression issue Feel free to ignore if none of these address your specific case.
Author
Owner

@hanwsf commented on GitHub (Jan 24, 2026):

在 Ubuntu GNOME Terminal 中为 OpenCode 启用复制功能:完整总结
🎯 核心问题
在 GNOME Terminal 3.44 中使用 OpenCode 时,虽然显示 "Copied to clipboard",但实际上并未复制成功。这是因为 GNOME Terminal(基于 VTE)不支持 OSC52 剪贴板协议。
已验证的解决方案
通过创建 Shell 桥接脚本 + 安装剪贴板工具 的方式,成功在 Ubuntu 22.04 的 GNOME Terminal 中实现复制功能。

📋 完整实施步骤
第一步:安装系统剪贴板工具
根据你的桌面环境选择安装:

通用安装(推荐)

sudo apt update && sudo apt install xclip xsel wl-clipboard

第二步:创建 OSC52 桥接脚本

创建脚本目录

mkdir -p ~/.local/bin

创建 osc52 脚本

cat > ~/.local/bin/osc52 << 'EOF'
#!/bin/bash
if [ ! -t 0 ]; then
data=$(cat)
else
data="$*"
fi

if [ -z "$data" ]; then
echo "用法: echo '文本' | osc52 或 osc52 '文本'"
exit 1
fi

if command -v xclip > /dev/null 2>&1; then
echo -n "$data" | xclip -selection clipboard -quiet 2>/dev/null && echo "已复制到剪贴板 (xclip)。"
elif command -v xsel > /dev/null 2>&1; then
echo -n "$data" | xsel --clipboard --input 2>/dev/null && echo "已复制到剪贴板 (xsel)。"
elif command -v wl-copy > /dev/null 2>&1 && [ -n "$WAYLAND_DISPLAY" ]; then
echo -n "$data" | wl-copy 2>/dev/null && echo "已复制到剪贴板 (wl-copy)。"
else
echo "错误: 未找到支持的剪贴板工具。" >&2
exit 1
fi
EOF

赋予执行权限

chmod +x ~/.local/bin/osc52

第三步:添加到系统路径
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

第四步:测试脚本功能

测试

echo "测试 OpenCode 复制功能" | osc52

应该看到"已复制到剪贴板 (xclip)。"提示

现在可以尝试 Ctrl+V 粘贴到任何地方


⚙️ 配置 OpenCode

  1. 确定 OpenCode 使用的编辑器
    在 OpenCode 中执行:
    :version

查看是 Vim 还是 NeoVim。
2. 根据编辑器类型配置
方案 A:如果是 NeoVim
编辑 ~/.config/nvim/init.vim:
let g:clipboard = {
\ 'name': 'osc52',
\ 'copy': {
\ '+': {lines, regtype -> system('osc52', join(lines, "\n"))},
\ '': {lines, regtype -> system('osc52', join(lines, "\n"))},
\ },
\ 'paste': {
\ '+': {-> []},
\ '
': {-> []},
\ },
\ }

方案 B:如果是 Vim
编辑 ~/.vimrc:
" 使用 \c 快捷键复制选中内容到剪贴板
vnoremap c :w !osc52

  1. 重启 OpenCode 使配置生效

🔧 故障排除
问题解决方法osc52: 未找到命令运行 source ~/.bashrc 或重新打开终端仍显示"未找到剪贴板工具"确保已安装 xclip:sudo apt install xclip快捷键不工作确认编辑器类型和配置文件路径正确只能复制一行文本这是脚本限制,多行文本可能需要调整 Vim 配置

💡 替代方案比较
方案优点缺点推荐度本方案 (脚本桥接) 无需更换终端
兼容 GNOME Terminal
配置一次,长期使用⚠️ 需要额外配置更换终端 (Kitty/Alacritty) 原生支持 OSC52
零配置⚠️ 需改变使用习惯依赖鼠标选中+快捷键 无需任何配置⚠️ 无法"选中即复制"
⚠️ 操作繁琐

📝 验证流程
1. 安装 xclip/xsel
2. 创建并测试 osc52 脚本
3. 配置 OpenCode/Vim
4. 在 OpenCode 中尝试复制 → 粘贴到其他应用
🎉 最终效果
配置完成后,在 OpenCode 中:

  • ���用 Vim 的 可视模式选中文本 + \c 快捷键(如果使用 Vim 方案)
  • 或直接使用 "+y 等 Vim 原生剪贴板命令
  • 文本将真正复制到系统剪贴板,可在任何地方粘贴

关键要点:GNOME Terminal 本身不支持 OSC52,因此需要外部脚本作为“翻译器”,将 OpenCode 的复制命令转换为系统剪贴板能理解的指令。此方案已验证在 Ubuntu 22.04 + GNOME Terminal 3.44 中工作正常。

@hanwsf commented on GitHub (Jan 24, 2026): 在 Ubuntu GNOME Terminal 中为 OpenCode 启用复制功能:完整总结 🎯 核心问题 在 GNOME Terminal 3.44 中使用 OpenCode 时,虽然显示 "Copied to clipboard",但实际上并未复制成功。这是因为 GNOME Terminal(基于 VTE)不支持 OSC52 剪贴板协议。 ✅ 已验证的解决方案 通过创建 Shell 桥接脚本 + 安装剪贴板工具 的方式,成功在 Ubuntu 22.04 的 GNOME Terminal 中实现复制功能。 -------------------------------------------------------------------------------- 📋 完整实施步骤 第一步:安装系统剪贴板工具 根据你的桌面环境选择安装: # 通用安装(推荐) sudo apt update && sudo apt install xclip xsel wl-clipboard 第二步:创建 OSC52 桥接脚本 # 创建脚本目录 mkdir -p ~/.local/bin # 创建 osc52 脚本 cat > ~/.local/bin/osc52 << 'EOF' #!/bin/bash if [ ! -t 0 ]; then data=$(cat) else data="$*" fi if [ -z "$data" ]; then echo "用法: echo '文本' | osc52 或 osc52 '文本'" exit 1 fi if command -v xclip > /dev/null 2>&1; then echo -n "$data" | xclip -selection clipboard -quiet 2>/dev/null && echo "已复制到剪贴板 (xclip)。" elif command -v xsel > /dev/null 2>&1; then echo -n "$data" | xsel --clipboard --input 2>/dev/null && echo "已复制到剪贴板 (xsel)。" elif command -v wl-copy > /dev/null 2>&1 && [ -n "$WAYLAND_DISPLAY" ]; then echo -n "$data" | wl-copy 2>/dev/null && echo "已复制到剪贴板 (wl-copy)。" else echo "错误: 未找到支持的剪贴板工具。" >&2 exit 1 fi EOF # 赋予执行权限 chmod +x ~/.local/bin/osc52 第三步:添加到系统路径 echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc source ~/.bashrc 第四步:测试脚本功能 # 测试 echo "测试 OpenCode 复制功能" | osc52 # 应该看到"已复制到剪贴板 (xclip)。"提示 # 现在可以尝试 Ctrl+V 粘贴到任何地方 -------------------------------------------------------------------------------- ⚙️ 配置 OpenCode 1. 确定 OpenCode 使用的编辑器 在 OpenCode 中执行: :version 查看是 Vim 还是 NeoVim。 2. 根据编辑器类型配置 方案 A:如果是 NeoVim 编辑 ~/.config/nvim/init.vim: let g:clipboard = { \ 'name': 'osc52', \ 'copy': { \ '+': {lines, regtype -> system('osc52', join(lines, "\n"))}, \ '*': {lines, regtype -> system('osc52', join(lines, "\n"))}, \ }, \ 'paste': { \ '+': {-> []}, \ '*': {-> []}, \ }, \ } 方案 B:如果是 Vim 编辑 ~/.vimrc: " 使用 \c 快捷键复制选中内容到剪贴板 vnoremap <leader>c :w !osc52<CR><CR> 3. 重启 OpenCode 使配置生效 -------------------------------------------------------------------------------- 🔧 故障排除 问题解决方法osc52: 未找到命令运行 source ~/.bashrc 或重新打开终端仍显示"未找到剪贴板工具"确保已安装 xclip:sudo apt install xclip快捷键不工作确认编辑器类型和配置文件路径正确只能复制一行文本这是脚本限制,多行文本可能需要调整 Vim 配置 -------------------------------------------------------------------------------- 💡 替代方案比较 方案优点缺点推荐度本方案 (脚本桥接)✅ 无需更换终端<br>✅ 兼容 GNOME Terminal<br>✅ 配置一次,长期使用⚠️ 需要额外配置⭐⭐⭐⭐⭐更换终端 (Kitty/Alacritty)✅ 原生支持 OSC52<br>✅ 零配置⚠️ 需改变使用习惯⭐⭐⭐⭐依赖鼠标选中+快捷键✅ 无需任何配置⚠️ 无法"选中即复制"<br>⚠️ 操作繁琐⭐⭐ -------------------------------------------------------------------------------- 📝 验证流程 1.✅ 安装 xclip/xsel 2.✅ 创建并测试 osc52 脚本 3.✅ 配置 OpenCode/Vim 4.✅ 在 OpenCode 中尝试复制 → 粘贴到其他应用 🎉 最终效果 配置完成后,在 OpenCode 中: - ���用 Vim 的 可视模式选中文本 + \c 快捷键(如果使用 Vim 方案) - 或直接使用 "+y 等 Vim 原生剪贴板命令 - 文本将真正复制到系统剪贴板,可在任何地方粘贴 -------------------------------------------------------------------------------- 关键要点:GNOME Terminal 本身不支持 OSC52,因此需要外部脚本作为“翻译器”,将 OpenCode 的复制命令转换为系统剪贴板能理解的指令。此方案已验证在 Ubuntu 22.04 + GNOME Terminal 3.44 中工作正常。
Author
Owner

@rudironsoni commented on GitHub (Jan 24, 2026):

https://github.com/anomalyco/opencode/issues/10128#issuecomment-3793471308

@rudironsoni commented on GitHub (Jan 24, 2026): https://github.com/anomalyco/opencode/issues/10128#issuecomment-3793471308
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7294