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
粘贴时不包含时间戳环境
这些不是时间戳。它们是颜色代码。
根据v0.91 变更日志,tldr
在 2021 年 7 月合并了一项禁用颜色的功能,方法是设置NO_COLOR
环境变量或使用新的--no-color
命令行选项。
不幸的是,v0.91比 Debian 中当前的版本 (0.6.4)新得多tldr
......所以,要么卸载 Debian 软件包并自己编译/安装它(*),要么提交错误报告要求新版本待包装。或两者。
这才是长期的解决方案。在短期内,使用sed
或某种方法从输出中删除颜色代码(如 @GMaster 的答案)可能是最好的选择。
(*) 我通常不会建议从程序的打包版本切换到自编译版本(因为这样做可能会导致兼容性问题或将来的升级问题),但是硬编码的颜色代码可以'不被禁用是 UI 令人厌恶的。