Skip to content

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

Closed

Description

@hanwsf

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

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Jan 23, 2026
  2. github-actions commented on Jan 23, 2026

    @github-actions
    Contributor

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

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

  3. hanwsf commented on Jan 24, 2026

    @hanwsf
    Author

    在 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 中工作正常。

  4. rudironsoni commented on Jan 24, 2026

    @rudironsoni
  5. entrptaher commented on Feb 25, 2026

    @entrptaher

    Just installing this resolved my issue on linux mint.

    sudo apt update && sudo apt install xclip xsel wl-clipboard
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions