Consider the following env exports from my .bashrc:
LESS_TERMCAP_mb=$(printf "\e[1;31m")
LESS_TERMCAP_md=$(printf "\e[1;31m")
LESS_TERMCAP_me=$(printf "\e[0m")
LESS_TERMCAP_se=$(printf "\e[0m")
LESS_TERMCAP_so=$(printf "\e[1;44;33m")
LESS_TERMCAP_ue=$(printf "\e[0m")
LESS_TERMCAP_us=$(printf "\e[1;32m")
This is fine and works as expected, but unfortunately when I dump env to the console it outputs the ansi colors and basically messes up the display of the terminal. I can pipe env to less to clean the ansi codes, but I was thinking that there is probably a better way to do this.
I created the following function which basically sets these variables inline before calling some terminal applications, but it doesnt set it for all applications.
less() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
less "$@"
}
Is there a better way, or any way, to script environment variables in such a way that they contain ANSI escape sequences but they dont evaluate when displayed via env?