Skip to content

Instantly share code, notes, and snippets.

@flamewing
Created July 19, 2021 10:36
Show Gist options
  • Save flamewing/0e1f2b15a57b891e7170629db6ee01f6 to your computer and use it in GitHub Desktop.
Save flamewing/0e1f2b15a57b891e7170629db6ee01f6 to your computer and use it in GitHub Desktop.
Some stuff for bashrc dealing with colors/styles and man page colorization
#-------------------------------------------------------------------------------
# ANSI escape sequences
stySetBold=$(echo -en "\e[1m")
stySetDim=$(echo -en "\e[2m")
stySetUnderline=$(echo -en "\e[4m")
stySetBlink=$(echo -en "\e[5m")
stySetReverse=$(echo -en "\e[7m")
stySetHidden=$(echo -en "\e[8m")
stySetCrossed=$(echo -en "\e[9m")
styClearBold=$(echo -en "\e[22m")
styClearDim=$(echo -en "\e[22m")
styClearUnderline=$(echo -en "\e[24m")
styClearBlink=$(echo -en "\e[25m")
styClearReverse=$(echo -en "\e[27m")
styClearHidden=$(echo -en "\e[28m")
styClearCrossed=$(echo -en "\e[29m")
styClearAll=$(echo -en "\e[0m")
styReset=$(echo -en "\e[m")
eraseLine=$(echo -en "\e[0K")
fgBlack=$(echo -en "\e[30m")
fgDkRed=$(echo -en "\e[31m")
fgDkGreen=$(echo -en "\e[32m")
fgDkYellow=$(echo -en "\e[33m")
fgDkBlue=$(echo -en "\e[34m")
fgDkMagenta=$(echo -en "\e[35m")
fgDkCyan=$(echo -en "\e[36m")
fgLtGray=$(echo -en "\e[37m")
fgDkGray=$(echo -en "\e[90m")
fgLtRed=$(echo -en "\e[91m")
fgLtGreen=$(echo -en "\e[92m")
fgLtYellow=$(echo -en "\e[93m")
fgLtBlue=$(echo -en "\e[94m")
fgLtMagenta=$(echo -en "\e[95m")
fgLtCyan=$(echo -en "\e[96m")
fgWhite=$(echo -en "\e[97m")
fgDefault=$(echo -en "\e[39m")
bgBlack=$(echo -en "\e[40m")
bgDkRed=$(echo -en "\e[41m")
bgDkGreen=$(echo -en "\e[42m")
bgDkYellow=$(echo -en "\e[43m")
bgDkBlue=$(echo -en "\e[44m")
bgDkMagenta=$(echo -en "\e[45m")
bgDkCyan=$(echo -en "\e[46m")
bgLtGray=$(echo -en "\e[47m")
bgDkGray=$(echo -en "\e[100m")
bgLtRed=$(echo -en "\e[101m")
bgLtGreen=$(echo -en "\e[102m")
bgLtYellow=$(echo -en "\e[103m")
bgLtBlue=$(echo -en "\e[104m")
bgLtMagenta=$(echo -en "\e[105m")
bgLtCyan=$(echo -en "\e[106m")
bgWhite=$(echo -en "\e[107m")
bgDefault=$(echo -en "\e[49m")
export stySetBold stySetDim stySetUnderline stySetBlink stySetReverse stySetHidden stySetCrossed
export styClearBold styClearDim styClearUnderline styClearBlink styClearReverse styClearHidden styClearCrossed styClearAll styReset
export eraseLine
export fgBlack fgDkRed fgDkGreen fgDkYellow fgDkBlue fgDkMagenta fgDkCyan fgLtGray fgDkGray fgLtRed fgLtGreen fgLtYellow fgLtBlue fgLtMagenta fgLtCyan fgWhite fgDefault
export bgBlack bgDkRed bgDkGreen bgDkYellow bgDkBlue bgDkMagenta bgDkCyan bgLtGray bgDkGray bgLtRed bgLtGreen bgLtYellow bgLtBlue bgLtMagenta bgLtCyan bgWhite bgDefault
_info() {
>&2 echo "${stySetBold}[${fgDkGreen}INFO ${fgDefault}]${styClearBold} $*"
}
_warn() {
>&2 echo "${stySetBold}[${fgDkYellow}WARN ${fgDefault}]${styClearBold} $*"
}
_error() {
>&2 echo "${stySetBold}[${fgDkRed}ERROR${fgDefault}]${styClearBold} $*"
}
_fatal() {
>&2 echo "${stySetBold}[${stySetUnderline}${fgDkMagenta}FATAL${fgDefault}${styClearUnderline}]${styClearBold} $*"
}
_stringify() {
echo "${fgLtCyan}\"$*\"${fgDefault}"
}
man() {
# LESS_TERMCAP_mb = enter blinking mode
# LESS_TERMCAP_md = enter double-bright mode
# LESS_TERMCAP_me = turn off all appearance modes (mb, md, so, us)
# LESS_TERMCAP_ue = leave underline mode
# LESS_TERMCAP_us = enter underline mode
# LESS_TERMCAP_so = enter standout mode
# LESS_TERMCAP_se = leave standout mode
LESS_TERMCAP_mb="${stySetBlink}${fgDkRed}" \
LESS_TERMCAP_md="${stySetBold}${fgDkBlue}" \
LESS_TERMCAP_me="${styClearAll}" \
LESS_TERMCAP_ue="${styClearUnderline}${fgDefault}" \
LESS_TERMCAP_us="${stySetUnderline}${fgDkMagenta}" \
LESS_TERMCAP_so="${stySetReverse}${fgDkYellow}" \
LESS_TERMCAP_se="${styClearReverse}${fgDefault}" \
command man "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment