spectrum.zsh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /bin/zsh
  2. # A script to make using 256 colors in zsh less painful.
  3. # P.C. Shyamshankar <sykora@lucentbeing.com>
  4. # Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
  5. typeset -Ag FX FG BG
  6. FX=(
  7. reset "%{%}"
  8. bold "%{%}" no-bold "%{%}"
  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. ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
  19. # Show all 256 colors with color number
  20. function spectrum_ls() {
  21. for code in {000..255}; do
  22. print -P -- "$code: %F{$code}$ZSH_SPECTRUM_TEXT%f"
  23. done
  24. }
  25. # Show all 256 colors where the background is set to specific color
  26. function spectrum_bls() {
  27. for code in {000..255}; do
  28. print -P -- "$BG[$code]$code: $ZSH_SPECTRUM_TEXT %{$reset_color%}"
  29. done
  30. }