Closed gilliek closed 9 years ago
Thanks :)
Simply ccat foo.go > bar.go ;-) One of the use case of cat(1). This way, ccat can be used as a replacement of cat(1).
ccat foo.go > bar.go
should work without your check of terminal since it outputs to stdout? The >
is actually piping stdout to a file.
Oh okay, or you want ccat
to fall back to cat
when there's a >
?
Yes it works, but it also outputs the color codes
Precisely :)
I'm thinking having a flag so that people could disable syntax highlighting like this: ccat -p main.go > foo
(p
stands for plain text). It's a more generic solution adapting to all cases.
It could be nice too :)
But my point is that the output, outside of a terminal, is completely useless since the ANSI escape codes only work within a terminal so I see no reason in favor of colorizing when there is a >
. I think it's more convenient to fallback to a cat
like behavior in this very case.
Ah, make sense :+1:. I merged it in https://github.com/jingweno/ccat/commit/25c0ff0882947c36556bcce03664c15e15cb1991
Thanks :)
The behavior proposed by @gilliek here is similar to --color=auto
on some GNU tools (see ls
man page for instance) and is the expected behavior by most users I'd say. I would not use a new flag for that and as @gilliek stated, there is no point in having ANSI escape codes in a text file.
@Rolinh Sure, the change is in master, feel free to try it out :smiley_cat:
The code looks good. But could you give me a use case of not using
ccat
in a terminal?