zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
21.62k stars 652 forks source link

NO_COLOR or --no-color options #3057

Open sebastien opened 10 months ago

sebastien commented 10 months ago

zellij does not seem to support the NO_COLOR environment variable, or have a a --no-color option, which makes it hard to script the CLI as for instance:

LAST_SESSION="$(zellij list-sessions|head -n1|cut -d' ' -f1)"
echo "$LAST_SESSION"
zellij attach "$LAST_SESSION"

will fail with

No session with the name 'zippy-megalodon' found!

while

▷ zellij list-sessions
zippy-megalodon [Created 0s ago] (EXITED - attach to resurrect)

The reason is that LAST_SESSION contains the color codes. Now, if we do this instead, this will work.

LAST_SESSION="$(zellij list-sessions|sed 's/\x1B\[[0-9;]*m//g'|head -n1|cut -d' ' -f1)"
echo "$LAST_SESSION"
zellij attach "$LAST_SESSION"

TL;DR supporting NO_COLOR or --no-color would make scripting zellij with the shell much easier.

cristiand391 commented 10 months ago

Even supporting NO_COLOR, change to the output could break scripts like these. I would prefer support for json output.

In the meantime, you should be using zellij list-sessions --no-formatting --short in your script.

imsnif commented 10 months ago

What's wrong with the --no-formatting option? That's exactly the reason for it.

sebastien commented 10 months ago

I didn't know there was a --no-formatting option (not listed in --help), but it does the trick. It would be nice to turn the --no-formatting flag on when NO_COLOR is set, but this solves my problem.