theme_chooser.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/zsh
  2. # Zsh Theme Chooser by fox (fox91 at anche dot no)
  3. # This program is free software. It comes without any warranty, to
  4. # the extent permitted by applicable law. You can redistribute it
  5. # and/or modify it under the terms of the Do What The Fuck You Want
  6. # To Public License, Version 2, as published by Sam Hocevar. See
  7. # http://sam.zoy.org/wtfpl/COPYING for more details.
  8. THEMES_DIR="$ZSH/themes"
  9. FAVLIST="${HOME}/.zsh_favlist"
  10. source $ZSH/oh-my-zsh.sh
  11. function noyes() {
  12. read "a?$1 [y/N] "
  13. if [[ $a == "N" || $a == "n" || $a = "" ]]; then
  14. return 0
  15. fi
  16. return 1
  17. }
  18. function theme_preview() {
  19. THEME=$1
  20. THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
  21. print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color"
  22. source "$THEMES_DIR/$THEME"
  23. cols=$(tput cols)
  24. print -P "$PROMPT $RPROMPT"
  25. }
  26. function banner() {
  27. echo
  28. echo "╺━┓┏━┓╻ ╻ ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╻ ╻┏━┓┏━┓┏━┓┏━╸┏━┓"
  29. echo "┏━┛┗━┓┣━┫ ┃ ┣━┫┣╸ ┃┃┃┣╸ ┃ ┣━┫┃ ┃┃ ┃┗━┓┣╸ ┣┳┛"
  30. echo "┗━╸┗━┛╹ ╹ ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╹ ╹┗━┛┗━┛┗━┛┗━╸╹┗╸"
  31. echo
  32. }
  33. function usage() {
  34. echo "Usage: $0 [options] [theme]"
  35. echo
  36. echo "Options"
  37. echo " -l List available themes"
  38. echo " -s Show all themes"
  39. echo " -h Get this help message"
  40. exit 1
  41. }
  42. function list_themes() {
  43. for THEME in $(ls $THEMES_DIR); do
  44. THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
  45. echo $THEME_NAME
  46. done
  47. }
  48. function insert_favlist() {
  49. if grep -q "$THEME_NAME" $FAVLIST 2> /dev/null ; then
  50. echo "Already in favlist"
  51. else
  52. echo $THEME_NAME >> $FAVLIST
  53. echo "Saved to favlist"
  54. fi
  55. }
  56. function theme_chooser() {
  57. for THEME in $(ls $THEMES_DIR); do
  58. echo
  59. theme_preview $THEME
  60. echo
  61. if [[ -z $1 ]]; then
  62. noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
  63. insert_favlist $THEME_NAME
  64. echo
  65. fi
  66. done
  67. }
  68. while getopts ":lhs" Option
  69. do
  70. case $Option in
  71. l ) list_themes ;;
  72. s ) theme_chooser 0 ;;
  73. h ) usage ;;
  74. * ) usage ;; # Default.
  75. esac
  76. done
  77. if [[ -z $Option ]]; then
  78. if [[ -z $1 ]]; then
  79. banner
  80. echo
  81. theme_chooser
  82. else
  83. theme_preview $1".zsh-theme"
  84. fi
  85. fi