1

Problem

I want to copy the output of tldr to clipboard, and then paste that to text editor.

I execute: tldr pwd | xclip -sel clip

When I paste from clipboard, I get:

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 

I want to get rid of timestamps and also want to know why this is happening.

Observation

  • tldr pwd (without passing into xclip) doesn't display timestamps
  • man pwd | xclip -sel clip doesn't include timestamps when pasted
  • So, only when passing tldr to xclip I find this happening
  • The timestamps looks like escape codes

Environment

  • Static hostname: debian
  • Icon name: computer-desktop
  • Chassis: desktop
  • Operating System: Debian GNU/Linux 10 (buster)
  • Kernel: Linux 4.19.0-17-amd64
  • Architecture: x86-64
2
  • 4
    Those aren't timestamps. Looks like escape codes for colouring and formatting the text. Commented Oct 23, 2021 at 3:01
  • 2
    Better-written software automatically turns of color codes when its stdout is not directed to a TTY. Commented Oct 23, 2021 at 15:25

2 Answers 2

7

Those are not timestamps. They are colour-codes.

According to the v0.91 Changelog, tldr merged a feature to disable colours in July 2021, either by setting a NO_COLOR environment variable or using a new --no-color command-line option.

Unfortunately, v0.91 of tldr is much newer than the version currently in Debian (0.6.4)....so, either uninstall the Debian package and compile/install it yourself(*) or submit a bug report asking for the new version to be packaged. Or both.

That's the long-term solution. In the short-term, using sed or something to remove the colour codes from the output (as in @GMaster's answer) is probably the best you do.

(*) I wouldn't normally suggest switching from a packaged version of a program to a self-compiled version (because doing that is likely to cause compatibility problems or issues with upgrading in future), but hard-coded colour codes that can't be disabled are a UI abomination.

1
  • 2
    "hard-coded colour codes that can't be disabled are a UI abomination" Terminal programs that don't auto-disable color unless a TTY is detected as the output destination are a UI abomination, so tldr still qualifies IMHO. Color that you can't disable, that's... I don't even know what that is, it's somehow worse than abominable. It's #KILLITWITHFIRE. Commented Oct 24, 2021 at 1:55
3

Those are color codes generated by tldr. Unfortunately tldr does not have any option to turn off the colors. But you can pass the tldr output through sed and get rid of the color codes. Try this:

tldr pwd | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' | xclip -sel clip 

Alternatively, based on the package jpa mentioned:

# install colorized-logs package (for ubuntu) sudo apt install colorized-logs tldr pwd | ansi2txt | xclip -sel clip 
2
  • 1
    I might suggest putting the sed command into a small shell script in $HOME/bin, perhaps called decolor. That way you don't have to remember the precise escape codes or the detailed sed syntax. Commented Oct 23, 2021 at 23:28
  • 2
    There is also ansi2txt from package colorized-logs that does the same. Commented Oct 24, 2021 at 6:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.