New answers tagged

1

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 ...


1

As already explained by ZimbiX, use double quotes et cetera. An alternative to his method is to use the $'…' syntax where escape sequences are interpreted. I.e.: \e => ASCII ESC (0x1b, 033) \033 => ASCII ESC (0x1b, 033) \x1b => ASCII ESC (0x1b, 033) So: red=$'\e[31m' blue=$'\e[34m' Then: printf $blue && sed "s/2/${red}2$blue/g" ...


2

Firstly, double quotes are required for interpolation: $ sed "s/2/${RED}2${BLUE}/" Hello.txt 1233[0;31m2233[0;34m53125213 233[0;31m2233[0;34m13532135 233[0;31m2233[0;34m3513125215 However, the ASCII escape sequences contain characters that affect sed, so you have to convert the escape character sequence into the actual control characters. This can be done ...


0

I wanted this feature as well. I basically merged everything into this .tmux.conf # cat <<__DATA__ >/dev/null # Embed shell scripts set -g status-utf8 on set -g utf8 on set -g default-terminal "screen-256color" run "cut -c3- ~/.tmux.conf | bash -s apply_configuration" # __DATA__ # # apply_configuration() { # tmux set -g status-bg ...


6

With zsh: autoload colors; colors for color (${(k)fg}) eval "$color() {print -n \$fg[$color]; cat; print -n \$reset_color}" And then: $ echo "while" | blue while


12

Here's a little script that does just that. Save this as color in a directory in your $PATH (for example, ~/bin if that's in your $PATH): #!/usr/bin/env perl use strict; use warnings; use Term::ANSIColor; my $color=shift; while (<>) { print color("$color").$_.color("reset"); } Then, pass your text through the script, giving . as the pattern ...


16

You'd use tput for that: tput setaf 1 echo This is red tput sgr0 echo This is back to normal This can be used to build a pipe: red() { tput setaf 1; cat; tput sgr0; } echo This is red | red The basic colours are respectively black (0), red (1), green, yellow, blue, magenta, cyan and white (7). You'll find all the details in the terminfo(5) manpage.


4

Just a quick hack: when grep is sending output to a pipe, it also commutes to no-changing-color mode x | grep hello | cat


12

You could do this, x | grep --color=never hello To quickly test it, you can do, ls -l /etc/ --color=always | grep --color=never .


0

It depends on the terminal. As a rule, you cannot do this using "ANSI colors", because (while some terminals interpret the bold video attribute as "bright colors"), there is no standard way to change the brightness of the background. Some terminals support escape sequences for changing the color palette used by the terminal independently of "ANSI colors". ...


1

The /etc/motd file is data (cannot contain a script, such as "echo -e"), and is presented to all logins irregardless of their actual terminal type. While you can do this for some configurations, the usual recommendation is that /etc/motd should be plain text (no escape sequences) because: attempting to print colored text does not take into account whether ...


1

I would advise not following those instructions. The motd is presented to all interactive logins, regardless of terminal type. This means that embedding control characters in the output is going to be wrong for at least one user, at least once. If you feel you really must, then use tput to generate the correct codes for the user's terminal. That's much ...


0

Depending on your terminal emulator, it may be possible to redefine the color "white" in the terminal's color scheme: echo -en "\e]PFffffff" setterm --foreground blue --background white --blink on


2

It seems you can't do this with dircolors, but you can do it by modifying LS_COLORS directly: eval "$(dircolors)" LS_COLORS="${LS_COLORS}*~=01;34:" export LS_COLORS dircolors only seems to handle three types of descriptors: terminal names (starting with TERM), file types (e.g. DIR), and extensions starting with .. The latter get expanded by prefixing them ...



Top 50 recent answers are included