theme_chooser.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. print -P $PROMPT
  24. }
  25. function banner() {
  26. echo
  27. echo "╺━┓┏━┓╻ ╻ ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╻ ╻┏━┓┏━┓┏━┓┏━╸┏━┓"
  28. echo "┏━┛┗━┓┣━┫ ┃ ┣━┫┣╸ ┃┃┃┣╸ ┃ ┣━┫┃ ┃┃ ┃┗━┓┣╸ ┣┳┛"
  29. echo "┗━╸┗━┛╹ ╹ ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╹ ╹┗━┛┗━┛┗━┛┗━╸╹┗╸"
  30. echo
  31. }
  32. function usage() {
  33. echo "Usage: $0 [options] [theme]"
  34. echo
  35. echo "Options"
  36. echo " -l List available themes"
  37. echo " -s Show all themes"
  38. echo " -h Get this help message"
  39. exit 1
  40. }
  41. function list_themes() {
  42. for THEME in $(ls $THEMES_DIR); do
  43. THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
  44. echo $THEME_NAME
  45. done
  46. }
  47. function insert_favlist() {
  48. if grep -q "$THEME_NAME" $FAVLIST 2> /dev/null ; then
  49. echo "Already in favlist"
  50. else
  51. echo $THEME_NAME >> $FAVLIST
  52. echo "Saved to favlist"
  53. fi
  54. }
  55. function theme_chooser() {
  56. for THEME in $(ls $THEMES_DIR); do
  57. echo
  58. theme_preview $THEME
  59. echo
  60. if [[ -z $1 ]]; then
  61. noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
  62. insert_favlist $THEME_NAME
  63. echo
  64. fi
  65. done
  66. }
  67. while getopts ":lhs" Option
  68. do
  69. case $Option in
  70. l ) list_themes ;;
  71. s ) theme_chooser 0 ;;
  72. h ) usage ;;
  73. * ) usage ;; # Default.
  74. esac
  75. done
  76. if [[ -z $Option ]]; then
  77. if [[ -z $1 ]]; then
  78. banner
  79. echo
  80. theme_chooser
  81. else
  82. theme_preview $1".zsh-theme"
  83. fi
  84. fi