malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.23k stars 30 forks source link

Feature request: Option in Tee to remove color #108

Open JimF42 opened 1 year ago

JimF42 commented 1 year ago

Please consider an option for Tee to strip off color escape sequences when writing to the output file.

For example, I ran du | tee <file>, and I had to manually edit out all of the color escape sequences after it was finished.

malxau commented 1 year ago

Thanks for the report.

I'll probably end up doing the simple thing, but I'm asking in case you can see a "better" alternative. Outside of tee, this would normally be solved with pipes. Specifically, cvtvt -text can be used to strip VT escapes. Unfortunately that doesn't work for tee, which is writing to a file directly and has no way to insert pipes into that stream.

So, considering that this is open source, there's a single repo that implements piping and execution that also has tee. It seems like it ought to be possible for tee to support pipes on the file stream, and the challenge is inventing a syntax to let it do so that doesn't create more problems than it solves.

Would it make sense to be able to do something like: df | tee -c "cvtvt -text" file ?

Another option would be to optionally invert tee's behavior. Currently tee writes to a file (without pipe support), and writes to stdout (which can be further piped.) An inverted tee would write to the display (without pipe support) and write to stdout (which can be further piped, ultimately to a file.)

Part of the reason I'm asking is because I think there are other operations that make sense to perform on the file as well (eg. iconv.)

Of course, there may be other options too. Do you see any more generic/elegant approach to this aside from hardcoding one specific operation into tee?

JimF42 commented 1 year ago

While I think the idea of having the double pipe sounds cool, to be able to pipe to cvtvt first, I will have to leave that decision up to you because of effort needed.

I'm really new to using Yori, so I can't say right now how else I would use the new piping engine that would be required to do this for tee

As far as inverting tee, that bothers me a bit as tee in general is so well known, that it may be confusing to some, and no longer backwards compatible for existing users. If you did this, you would either need a new command to avoid confusion, or, a non-default set of switches that inverts the default behavior.

In some ways, I think your example of df | tee -c "cvtvt -text" file makes the best sense if you are not going to simply "hardcode" the cvtvt features into tee.

Otherwise, it would probably be something like df | tee -c[onsole] | cvtvt -text file, if you want to allow for an inverted tee (if that's even possible since they will both ultimately be going to the console).