bash PS1 256 colors with bold
Solution 1
You can write it as any of those:
echo -e "\e[1;38;05;${code}m $code: Test"
echo -e "\e[1m\e[38;05;${code}m $code: Test";
echo -e "\e[38;05;${code}m\e[1m $code: Test";
echo -e "\e[38;05;${code};1m $code: Test";
tput bold; tput setaf "$code" # provided the terminfo database is
# properly populated
You can run tput bold
only once provided you don't reset the boldness with a tput sgr0
or \e[m
or \e[0m
.
Solution 2
To supplement Stephane's example, here's a quick shell function to list all 256 colors:
#!/bin/bash
esc=$'\033'
for row in {0..15} ;
do
rowtext=
for col in {0..15};
do
color=$(( $row * 16 + $col))
BG="${esc}[48;5;${color}m"
rowtext=${rowtext}$BG\
if [[ $color -lt 100 ]]; then rowtext=${rowtext}$BG\ ;fi
if [[ $color -lt 10 ]]; then rowtext=${rowtext}$BG\ ;fi
rowtext=${rowtext}$BG${color}
rowtext=${rowtext}$BG\
done
echo "${rowtext}${esc}[00m "
done
This is a quick "port" of a zsh function I have to bash. I seems to work (in bash), or at least well enough.
The color code number is displayed in the color block. This is what you'd use in your prompt or elsewhere to set the color.
Related videos on Youtube
mouthpiec
Updated on September 18, 2022Comments
-
mouthpiec over 1 year
I have a table named People in the following format:
Date | Name
.When I count the people by Grouping By Name with
Select Date, Name, count(*) From People Group By Date, Name;
Will give the following
Date Name count(*) 10 Peter 25 10 John 30 10 Mark 25 11 Peter 15 11 John 10 11 Mark 5
But I would like the following result:
Date Peter John Mark 10 25 30 25 11 15 10 5
Is this possible? This is a simple example of a more complicated database. If someone helps me in solving this problem I will use the concept to implement it in my table
Thanks!
-
Damien_The_Unbeliever over 12 yearsWhat SQL product are you using (hint: search for pivot and whatever RDBMS you're using, and you should find the answer)?
-
Andreas Rohde over 12 yearsHi, which RDBMS do you use? If you use MS-SQL try to use the
PIVOT
- Statement. -
El Ronnoco over 12 yearsFurther to @Damian's comment - I would seatch for your RDBMS platform with search terms
pivot
andcrosstab
and you should find out if this is possible or not... -
Widor over 12 yearsThis is usually known as a Pivot (table). Depending on your RDBMS there may be non-standard functions to do this, else you'll find yourself hard-coding each
Name
inCASE
statements. Reporting tools are better at handling this sort of output. -
Andriy M about 12 yearsDuplicate of column value in a single row and likely many others.
-
Stéphane Chazelas over 10 yearsAdd
1;
in it:\e[1;38;05;${code}m
. Better to usetput setaf "$code"; tput bold
. -
piotrekkr over 10 years@StephaneChazelas Wow I didn't know I could add another code inside sequence. I was certain whet there could be max three parts. For example:
\e[38;05;44m
or\e[1;31m
. Does the order of codes between semicolons matter? Your answer is correct. Please write reply and I will accept it. Thx. -
slm over 5 years
-
-
manatwork over 10 yearsSome escape characters seems to get lost during the copy-paste.
-
Gilles 'SO- stop being evil' over 10 yearsAn escape character at the beginning of
BG
got lost. You should use escape sequences instead to avoid this kind of mishap. You can't use$BG[0]
in bash, you have to write it${BG:0:1}
(for an array it would be${array[0]}
).