New answers tagged colors
Is there some environment variable? Yes. It is the TERM environment variable. This is because there are several things that are used as part of the decision process. It's difficult to generalize here, because not all programs agree on a single decision flowchart. In fact GNU grep, mentioned in M. Kitt's answer, is a good example of an outlier that ...
Most such programs only output colour codes to a terminal by default; they check to see if their output is a TTY, using isatty(3). There are usually options to override this behaviour: disable colours in all cases, or enable colours in all cases. For GNU grep for example, --color=never disables colours and --color=always enables them. In a shell you can ...
You may be after: \e[32m style escape sequences in your string such as echo -e "Doing ls\n\e[32m$(ls --color=never)\e[33m ^^^\n \e[36m ls \e[39m output" printf "\e[35mHello\e[41mWorld\e[0m!" There are a few articles & listings of colours including: http://www.bashguru.com/2010/01/shell-colors-colorizing-shell-scripts.html?m=1
The 2 and 5 come from ITU T.416 (the same as ISO 8613-6), entitled Open Document Architecture (ODA) and Interchange Format: Character Content Architectures. Quoting from ISO/IEC 8613-6 : 1994 (E), page 41: The first parameter element indicates a choice between: 0 implementation defined (only applicable for the character foreground colour) 1 ...
You are using the wrong escape sequence. It's close (begins with escape[, ends with m), but the wrong parameters. There are at least three SGR (select graphic rendition) escape sequences which are used to print colors in xterm and similar terminals: ANSI (colors 0-7), which use parameters 30-37 (foreground) and 40-47 (background) aixterm (colors 8-15), ...
You need to understand that the $'...' is a feature of the shell to write escaped characters. A $'\033' is an actual escape ESC. Therefore, you need to move the $' ' from inside the sed command: sed -e $'s/ *[^ ]* /\033[1;33m&\033[0m/6' To the actual variables you will use: fg_normal=$'\033[0m' fg_yellow=$'\033[1;33m' With that simple change, this ...
You could use: fg_normal=$(echo -e "\033[0m") fg_yellow=$(echo -e "\033[1;33m") or with tput: fg_normal=$(tput sgr0) fg_yellow=$(tput setaf 3)
You could use printf's %b specifier to assemble the sed command, preserving the correct backslash escape sequences: ps -eo pid,ppid,time,user,tty,%cpu,%mem,vsize,command --sort -%cpu | head | sed -e "$(printf 's/ *[^ ]* /%b&%b/6' "$fg_yellow" "$fg_normal")"
don_crissti posted an extremely easy solution, just adding the desired column number before the very last closing quote: ps -eo pid,ppid,time,user,tty,%cpu,%mem,vsize,command --sort -%cpu | head | sed -e $'s/ *[^ ]* /\033[1;33m&\033[0m/6'
I solved the problem by writing a simple python script to replace the ANSI codes with tmux color variables. #!/usr/local/bin/python s = raw_input("") s = s.replace('\x1b[32m', '#[fg=colour10]') s = s.replace('\x1b[93m', '#[fg=colour11]') s = s.replace('\x1b[0m', '#[fg=colour255]') print s I just pipe the output to the script: istats | grep "CPU temp" | ...
Thank you so much @enzotib for your solution ! Just as an addition to your solution, here is a way to make it explicitly callable by the user: ;; M-x display-ansi-colors to explicitly decode ANSI color escape sequences ...
I remembered the package ... it is called xcolorsel.
Any decent editor is able to highlight diffs conveniently. You can generally persuade your editor by using the .diff extension, or by setting the filetype to diff otherwise.
You could hack something together that would read a line of the file, check the first char on the line, and print it in the appropriate color: green if the first char is a +, red if the first char is a -, and the default color (white? black?) otherwise. "Friendly" terminal color names in shell scripts? Handling the cyan @@ lines would be ...
Once the output of ls is on the terminal, it stays colored. But if you run ls again, whether the output is colored depends on the options you pass to ls this time. The ls command doesn't remember settings from one time to the next. If you want to have default settings for a command, define an alias for it. For bash, the file where aliases are defined is ...
Top 50 recent answers are included