spectrum.zsh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. dim "%{%}" no-dim "%{%}"
  9. italic "%{%}" no-italic "%{%}"
  10. underline "%{%}" no-underline "%{%}"
  11. blink "%{%}" no-blink "%{%}"
  12. reverse "%{%}" no-reverse "%{%}"
  13. )
  14. for color in {000..255}; do
  15. FG[$color]="%{[38;5;${color}m%}"
  16. BG[$color]="%{[48;5;${color}m%}"
  17. done
  18. # Show all 256 colors with color number
  19. function spectrum_ls() {
  20. setopt localoptions nopromptsubst
  21. local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
  22. for code in {000..255}; do
  23. print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
  24. done
  25. }
  26. # Show all 256 colors where the background is set to specific color
  27. function spectrum_bls() {
  28. setopt localoptions nopromptsubst
  29. local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
  30. for code in {000..255}; do
  31. print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
  32. done
  33. }