Colorize error output by default when running Julia script

On my system (Ubuntu 19.10), Julia does not colorize error output when run through the shebang of an executable script. That is, if I create a script foo.jl with a shebang as

#!/usr/bin/env julia

...

and run it as ./foo.jl, I get non-highlighted error message, but if I call it as julia --color=yes foo.jl, I get all the works. Is there a way to enable colorized output from within the script, or by setting a corresponding option somewhere in ~/.julia?

https://docs.julialang.org/en/v1/manual/faq/#How-do-I-pass-options-to-julia-using-#!/usr/bin/env?-1

1 Like

Thank you very much for the reply - I should have found that solution myself :grimacing: However, since the solution is rather restrictive (works only for specific files and then forces the behavior for all users), I will keep looking.

I am not sure I understand this, it should work for all scripts.

And of course users running the same script get the same behavior, but I always thought of that as a feature rather than a bug.

Yes, all scripts that I can control. I am looking for a way to set it locally for all Julia scripts. Also, it adds unnecessary boilerplate to short scripts, is confusing for new users and adds another layer of execution, which IMHO is not the most elegant solution.

I am rather looking for something like export JULIA_CMDLINE_OPTIONS="--color=yes" or a ~/.julia/config file with default options.

You can just run the file with whatever options you want by using

$ julia --color=yes foo.jl
1 Like

Sorry for the back and forth, I think I should have been more specific in my original post:

I am looking for an answer that allows so set “colors” as the default behavior for all users and files on a given system, but which allows each user to override this behavior in a general way (i.e., for all files) for herself. That is, something like setting an environment variable in /etc/profile.d/julia.sh that can be then customized/overriden by each user.

If this is currently not possible in a sane way (i.e., without wrapping the julia executable in a shell script that passes --color=yes to each invocation), I’d be happy with that answer as well, as I can stop looking :wink: