spectrum.zsh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # A script to make using 256 colors in zsh less painful.
  2. # P.C. Shyamshankar <sykora@lucentbeing.com>
  3. # Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
  4. typeset -AHg FX FG BG
  5. FX=(
  6. reset "%{%}"
  7. bold "%{%}" no-bold "%{%}"
  8. italic "%{%}" no-italic "%{%}"
  9. underline "%{%}" no-underline "%{%}"
  10. blink "%{%}" no-blink "%{%}"
  11. reverse "%{%}" no-reverse "%{%}"
  12. )
  13. for color in {000..255}; do
  14. FG[$color]="%{[38;5;${color}m%}"
  15. BG[$color]="%{[48;5;${color}m%}"
  16. done
  17. # Show all 256 colors with color number
  18. function spectrum_ls() {
  19. setopt localoptions nopromptsubst
  20. local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
  21. for code in {000..255}; do
  22. print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
  23. done
  24. }
  25. # Show all 256 colors where the background is set to specific color
  26. function spectrum_bls() {
  27. setopt localoptions nopromptsubst
  28. local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
  29. for code in {000..255}; do
  30. print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
  31. done
  32. }