Props to https://perpetualpc.net/6429_colors.html
Misc ∞
Resizing can be done with: ^[[8;<lines>;<cols>t
, which is only supported by xterm and the rxvt family of terminals (rxvt-unicode, urxvt, etc)
Colour ∞
http://web.archive.org/web/20050211025928/http://www.linux.com/howtos/Bash-Prompt-HOWTO/c327.shtml
Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37
ISO 6429 color sequences are composed of sequences of numbers separated by semicolons. The most common codes are: 0 to restore default color 1 for brighter colors 4 for underlined text 5 for flashing text 30 for black foreground 31 for red foreground 32 for green foreground 33 for yellow (or brown) foreground 34 for blue foreground 35 for purple foreground 36 for cyan foreground 37 for white (or gray) foreground 40 for black background 41 for red background 42 for green background 43 for yellow (or brown) background 44 for blue background 45 for purple background 46 for cyan background 47 for white (or gray) background Not all commands will work on all systems or display devices. ls uses the following defaaults: NORMAL 0 Normal (non-filename) text FILE 0 Regular file DIR 32 Directory LINK 36 Symbolic link ORPHAN undefined Orphanned symbolic link MISSING undefined Missing file FIFO 31 Named pipe (FIFO) SOCK 33 Socket BLK 44;37 Block device CHR 44;37 Character device EXEC 35 Executable file
Functions ∞
in ~/.bashrc
I did
reset_colour() { # darkgrey on black # TODO: What if there is a different foreground or background colour preference? # Learn the current colours, and restore them intelligently? printf "\x1b\x5b0;40;40m" } black() { printf "\x1b\x5b0;30;40m$1\n";reset_colour ; } darkgray() { printf "\x1b\x5b1;30;40m$1\n";reset_colour ; } blue() { printf "\x1b\x5b0;34;40m$1\n";reset_colour ; } lightblue() { printf "\x1b\x5b1;34;40m$1\n";reset_colour ; } green() { printf "\x1b\x5b0;32;40m$1\n";reset_colour ; } lightgreen() { printf "\x1b\x5b1;32;40m$1\n";reset_colour ; } cyan() { printf "\x1b\x5b0;36;40m$1\n";reset_colour ; } lightcyan() { printf "\x1b\x5b1;36;40m$1\n";reset_colour ; } red() { printf "\x1b\x5b0;31;40m$1\n";reset_colour ; } lightred() { printf "\x1b\x5b1;31;40m$1\n";reset_colour ; } purple() { printf "\x1b\x5b0;35;40m$1\n";reset_colour ; } lightpurple() { printf "\x1b\x5b1;35;40m$1\n";reset_colour ; } brown() { printf "\x1b\x5b0;33;40m$1\n";reset_colour ; } yellow() { printf "\x1b\x5b1;33;40m$1\n";reset_colour ; } lightgrey() { printf "\x1b\x5b0;37;40m$1\n";reset_colour ; } white() { printf "\x1b\x5b1;37;40m$1\n";reset_colour ; }
echo ∞
Like so:
\echo -e "\x1b\x5b0;32;40mgreen text"
Escape Sequences ∞
\a Bell (ASCII 7) \b Backspace (ASCII 8) \e Escape (ASCII 27) \f Form feed (ASCII 12) \n Newline (ASCII 10) \r Carriage Return (ASCII 13) \t Tab (ASCII 9) \v Vertical Tab (ASCII 11) \? Delete (ASCII 127) \nnn Any character (octal notation) \xnnn Any character (hexadecimal notation) \_ Space \\ Backslash (\) \^ Caret (^) \# Hash mark (#)
Notes ∞
Great notes here: https://wiki.archlinux.org/title/Bash/Prompt_customization [ 1 ] was https://wiki.archlinux.org/index.php/Bash/Prompt_customization
My spinner in an old 'Bash automated testing' project uses this remember/restore trick.
# cursor's current position is saved through an escape sequence echo -n -e "\033[s" # restore the cursor to whatever was its previous position echo -n -e "\033[u"
Last updated 2021-06-05 at 05:09:48