spectrum.zsh 1.12 KB
Newer Older
1
2
# A script to make using 256 colors in zsh less painful.
# P.C. Shyamshankar <sykora@lucentbeing.com>
Janosch Schwalm's avatar
Janosch Schwalm committed
3
# Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
4

5
typeset -AHg FX FG BG
6
7

FX=(
8
9
10
11
12
13
  reset     "%{%}"
  bold      "%{%}" no-bold      "%{%}"
  italic    "%{%}" no-italic    "%{%}"
  underline "%{%}" no-underline "%{%}"
  blink     "%{%}" no-blink     "%{%}"
  reverse   "%{%}" no-reverse   "%{%}"
14
15
16
)

for color in {000..255}; do
17
18
  FG[$color]="%{[38;5;${color}m%}"
  BG[$color]="%{[48;5;${color}m%}"
19
done
20
21
22

# Show all 256 colors with color number
function spectrum_ls() {
23
  local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
24
  for code in {000..255}; do
25
    print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
26
27
28
  done
}

29
30
# Show all 256 colors where the background is set to specific color
function spectrum_bls() {
31
  local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
32
  for code in {000..255}; do
33
    print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
34
35
  done
}