Add section on shell prompt usage

This commit is contained in:
The Magician 2023-11-07 11:59:14 +00:00
parent cfb168958b
commit 9467c031d6
1 changed files with 9 additions and 73 deletions

View File

@ -381,7 +381,15 @@ section_inverse() {
section_using_escape_sequences_in_shell_prompt() { section_using_escape_sequences_in_shell_prompt() {
title "Using Escape Sequences in Shell Prompts" title "Using Escape Sequences in Shell Prompts"
printf 'TODO\n'
printf "When using these sequences in a Bash prompt (e.g. $PS1), it's possible for issues to arise because of Bash \"miscounting\" the number of characters in the prompt string.\n"
printf "This is often the source of difficult-to-debug (or describe) issues with the terminal, such as characters being moved around or overwritten seemingly at random.\n"
newline
printf "In order to prevent these issues, all ANSI escape codes need to be surrounded with escaped brackets, i.e. \`\\[\` and \`\\]\`.\n"
printf "For example, if you wanted an entirely cyan-colored prompt string:\n"
printf " - WRONG: \`PS1='\\\\e[36m\u@\h \\$\\\\e[0m'\`\n"
printf " - RIGHT: \`PS1='\[\\\\e[36m\]\u@\h \\$\[\\\\e[0m\]'\`\n"
} }
section_table_of_all_sgr_commands() { section_table_of_all_sgr_commands() {
@ -452,33 +460,6 @@ main() {
section_credits section_credits
newline newline
#printf 'When using these sequences in a Bash prompt (e.g. $PS1), be sure to surround the whole escape sequence with escaped brackets to prevent issues with Bash miscounting the number of characters in a line. For example: `export PS1=''\[\\e[36m\]\u@\h \$\[\\e[0m\]''` would create a cyan-colored prompt string.\n'
#printf '\n'
#
#printf '\e[4;37m\e[1;37mRegular Colors\e[0m\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[30m[30m Black\e[0m \e[40m[40m Black\e[0m\n'
#printf '\e[31m[31m Red\e[0m \e[41m[41m Red\e[0m\n'
#printf '\e[32m[32m Green\e[0m \e[42m[42m Green\e[0m\n'
#printf '\e[33m[33m Brown\e[0m \e[43m[43m Brown\e[0m\n'
#printf '\e[34m[34m Blue\e[0m \e[44m[44m Blue\e[0m\n'
#printf '\e[35m[35m Purple\e[0m \e[45m[45m Purple\e[0m\n'
#printf '\e[36m[36m Cyan\e[0m \e[46m[46m Cyan\e[0m\n'
#printf '\e[37m[37m Light grey\e[0m \e[47m[47m Light grey\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37mBold Colors\e[0m\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[1;30m[1;30m Dark grey\e[0m \e[1;40m[1;40m Dark grey\e[0m\n'
#printf '\e[1;31m[1;31m Light red\e[0m \e[1;41m[1;41m Light red\e[0m\n'
#printf '\e[1;32m[1;32m Light green\e[0m \e[1;42m[1;42m Light green\e[0m\n'
#printf '\e[1;33m[1;33m Yellow\e[0m \e[1;43m[1;43m Yellow\e[0m\n'
#printf '\e[1;34m[1;34m Light blue\e[0m \e[1;44m[1;44m Light blue\e[0m\n'
#printf '\e[1;35m[1;35m Light purple\e[0m \e[1;45m[1;45m Light purple\e[0m\n'
#printf '\e[1;36m[1;36m Light cyan\e[0m \e[1;46m[1;46m Light cyan\e[0m\n'
#printf '\e[1;37m[1;37m White\e[0m \e[1;47m[1;47m White\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m2; (Test)\e[0m\n' #printf '\e[4;37m\e[1;37m2; (Test)\e[0m\n'
#printf '\e[2;34m[2;34m Light blue\e[0m \e[2;44m[2;44m Light blue\e[0m\n' #printf '\e[2;34m[2;34m Light blue\e[0m \e[2;44m[2;44m Light blue\e[0m\n'
#printf '\n' #printf '\n'
@ -486,51 +467,6 @@ main() {
#printf '\e[4;37m\e[1;37m3; (Test)\e[0m\n' #printf '\e[4;37m\e[1;37m3; (Test)\e[0m\n'
#printf '\e[3;34m[3;34m Light blue\e[0m \e[3;44m[3;44m Light blue\e[0m\n' #printf '\e[3;34m[3;34m Light blue\e[0m \e[3;44m[3;44m Light blue\e[0m\n'
#printf '\n' #printf '\n'
#printf '\e[4;37m\e[1;37m4; (Underscore)\e[0m\n'
#printf 'This attribute displays text with an underline.\n'
#printf 'If the underline is always displayed in the foreground color. See the table below for more detail.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[4;30m[4;30m Black\e[0m \e[4;40m[4;40m Black\e[0m\n'
#printf '\e[4;31m[4;31m Red\e[0m \e[4;41m[4;41m Red\e[0m\n'
#printf '\e[4;32m[4;32m Green\e[0m \e[4;42m[4;42m Green\e[0m\n'
#printf '\e[4;33m[4;33m Brown\e[0m \e[4;43m[4;43m Brown\e[0m\n'
#printf '\e[4;34m[4;34m Blue\e[0m \e[4;44m[4;44m Blue\e[0m\n'
#printf '\e[4;35m[4;35m Purple\e[0m \e[4;45m[4;45m Purple\e[0m\n'
#printf '\e[4;36m[4;36m Cyan\e[0m \e[4;46m[4;46m Cyan\e[0m\n'
#printf '\e[4;37m[4;37m Light grey\e[0m \e[4;47m[4;47m Light grey\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m5; (Blinkentext)\e[0m\n'
#printf 'Also known as the dreaded blinking text of doom.\n'
#printf 'Causes text to blink. Some terminal emulators refuse to honor this attribute as a matter of good taste, although there are some semi-legitimate uses for it -- the `ls` program, for example, can be configured to cause listings of broken symlinks to blink.\n'
#printf 'Note that even if the blinking attribute is set on a background color, it''s always the text that blinks, not the background.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[5;30m[5;30m Black\e[0m \e[5;40m[5;40m Black\e[0m\n'
#printf '\e[5;31m[5;31m Red\e[0m \e[5;41m[5;41m Red\e[0m\n'
#printf '\e[5;32m[5;32m Green\e[0m \e[5;42m[5;42m Green\e[0m\n'
#printf '\e[5;33m[5;33m Brown\e[0m \e[5;43m[5;43m Brown\e[0m\n'
#printf '\e[5;34m[5;34m Blue\e[0m \e[5;44m[5;44m Blue\e[0m\n'
#printf '\e[5;35m[5;35m Purple\e[0m \e[5;45m[5;45m Purple\e[0m\n'
#printf '\e[5;36m[5;36m Cyan\e[0m \e[5;46m[5;46m Cyan\e[0m\n'
#printf '\e[5;37m[5;37m Light grey\e[0m \e[5;47m[5;47m Light grey\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m7; (Inverse)\e[0m\n'
#printf 'Causes the foreground and background text to be flipped.\n'
#printf 'This is mostly a convenient shorthand for avoiding setting the foreground and background text simultaneously when you want one to be the default of the other.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[7;30m[7;30m Black\e[0m \e[7;40m[7;40m Black\e[0m\n'
#printf '\e[7;31m[7;31m Red\e[0m \e[7;41m[7;41m Red\e[0m\n'
#printf '\e[7;32m[7;32m Green\e[0m \e[7;42m[7;42m Green\e[0m\n'
#printf '\e[7;33m[7;33m Brown\e[0m \e[7;43m[7;43m Brown\e[0m\n'
#printf '\e[7;34m[7;34m Blue\e[0m \e[7;44m[7;44m Blue\e[0m\n'
#printf '\e[7;35m[7;35m Purple\e[0m \e[7;45m[7;45m Purple\e[0m\n'
#printf '\e[7;36m[7;36m Cyan\e[0m \e[7;46m[7;46m Cyan\e[0m\n'
#printf '\e[7;37m[7;37m Light grey\e[0m \e[7;47m[7;47m Light grey\e[0m\n'
} }
name="$(basename $0)" name="$(basename $0)"