为什么tldr | xclip 输出看起来像时间戳的转义码,如何删除它?

dun*_*ian 1 gui clipboard timestamps xclip

问题

我想将 tldr 的输出复制到剪贴板,然后将其粘贴到文本编辑器。

我执行:tldr pwd | xclip -sel clip

当我从剪贴板粘贴时,我得到:

pwd
[0mPrint name of current/working directory.More information: https://www.gnu.org/software/coreutils/pwd.

 - [23;22;24;25;32mPrint the current directory:
[23;22;24;25;33m   pwd
[0m
 - [23;22;24;25;32mPrint the current directory, and resolve all symlinks (i.e. show the "physical" path):
[23;22;24;25;33m   pwd -P
[0m[0m
Run Code Online (Sandbox Code Playgroud)

我想摆脱时间戳,也想知道为什么会发生这种情况。

观察

  • tldr pwd(不传递到 xclip)不显示时间戳
  • man pwd | xclip -sel clip粘贴时不包含时间戳
  • 所以,只有当将 tldr 传递给 xclip 时,我才会发现这种情况发生
  • 时间戳看起来像转义码

环境

  • 静态主机名:debian
  • 图标名称:电脑桌面
  • 机箱: 台式
  • 操作系统:Debian GNU/Linux 10 (buster)
  • 内核:Linux 4.19.0-17-amd64
  • 架构:x86-64

cas*_*cas 7

这些不是时间戳。它们是颜色代码。

根据v0.91 变更日志tldr在 2021 年 7 月合并了一项禁用颜色的功能,方法是设置NO_COLOR环境变量或使用新的--no-color命令行选项。

不幸的是,v0.91比 Debian 中当前的版本 (0.6.4)新得多tldr......所以,要么卸载 Debian 软件包并自己编译/安装它(*),要么提交错误报告要求新版本待包装。或两者。

这才是长期的解决方案。在短期内,使用sed或某种方法从输出中删除颜色代码(如 @GMaster 的答案)可能是最好的选择。

(*) 我通常不会建议从程序的打包版本切换到自编译版本(因为这样做可能会导致兼容性问题或将来的升级问题),但是硬编码的颜色代码可以'不被禁用是 UI 令人厌恶的。

  • “_无法禁用的硬编码颜色代码是 UI 令人厌恶的_”除非检测到 TTY 作为输出目标,否则不会自动禁用颜色的终端程序是 UI 令人厌恶的,因此“tldr”仍然符合恕我直言。你_不能_禁用的颜色,那是......我什至不知道那是什么,它在某种程度上比可憎更糟糕。这是**#KILLITWITHFIRE**。 (2认同)