shift
done
-printf "$fg[white]$fx[bold]$(hostname)$fx[no-bold] "
-printf "$fg[yellow]$(tty)$fx[reset], "
-printf "$fg[green]$fx[underline]${TERM:-?}$fx[reset] "
-printf "(${COLUMNS:-?}x${LINES:-?}); "
-printf "$fg[white]LANG=${LANG:-?}$fx[reset]"
+print -Pn -- "$fg[white]$FX[bold]$(hostname)$FX[no-bold] "
+print -Pn -- "$fg[yellow]$(tty)$FX[reset], "
+print -Pn -- "$fg[green]$FX[underline]${TERM:-?}$FX[reset] "
+print -Pn -- "(${COLUMNS:-?}x${LINES:-?}); "
+print -Pn -- "$fg[white]LANG=${LANG:-?}$FX[reset]"
echo
[[ -z "$VERBOSE" ]] && return 0
check_function_result() {
"$1"; r=$?
- printf " - $fg[white]$1$fx[reset]() = "
+ print -Pn -- " - $fg[white]$1$FX[reset]() = "
if [[ $r -eq 0 ]]; then
- echo "$fg[green]yes$fx[reset]"
+ print -P -- "$fg[green]yes$FX[reset]"
else
- echo "$fg[red]NO$fx[reset]"
+ print -P -- "$fg[red]NO$FX[reset]"
fi
return $r
}
autoload -Uz colors
colors
+# Foreground (FG) and background (BG) colors.
+typeset -Ag FG BG
+for color in {000..255}; do
+ FG[$color]="%{\e[38;5;${color}m%}"
+ BG[$color]="%{\e[48;5;${color}m%}"
+done
+
# Text effects (FX)
-typeset -Ag fx
-fx=(
- reset "\e[00m"
- bold "\e[01m"
- no-bold "\e[22m"
- italic "\e[03m"
- no-italic "\e[23m"
- underline "\e[04m"
- no-underline "\e[24m"
- blink "\e[05m"
- no-blink "\e[25m"
- reverse "\e[07m"
- no-reverse "\e[27m"
+typeset -Ag FX
+FX=(
+ reset "%{\e[00m%}"
+ bold "%{\e[01m%}" no-bold "%{\e[22m%}"
+ italic "%{\e[03m%}" no-italic "%{\e[23m%}"
+ underline "%{\e[04m%}" no-underline "%{\e[24m%}"
+ blink "%{\e[05m%}" no-blink "%{\e[25m%}"
+ reverse "%{\e[07m%}" no-reverse "%{\e[27m%}"
)
+
+ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-The quick brown fox jumps over the lazy dog}
+
+# Show all 256 foreground colors with color number
+function spectrum_ls() {
+ for code in {000..255}; do
+ print -P -- "$code: %{$FG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"
+ done
+}
+
+# Show all 256 background colors with color number
+function spectrum_bls() {
+ for code in {000..255}; do
+ print -P -- "$code: %{$BG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"
+ done
+}
+
+# NOTE for FG, BG and FX arrays, and spectrum_ls() and spectrum_bls() functions:
+# Based on a script to make using 256 colors in zsh less painful, written by
+# P.C. Shyamshankar <sykora@lucentbeing.com>.
+# Copied from OhMyZsh https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/spectrum.zsh
+# which was copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ :-)