theme_chooser.sh 3.5 KB

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