set-theme 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
  3. #THEME_FILE_NAME="$1"
  4. REQUEST="$1"
  5. SYMLINK_NAME=current
  6. cd $SCRIPT_DIR
  7. FISH_THEME_DIR="$SCRIPT_DIR/fish/theme"
  8. VIM_THEME_DIR="$SCRIPT_DIR/vim/theme"
  9. XRESOURCES_DIR="$SCRIPT_DIR/Xresources.d"
  10. XRESOURCES_FILE="$HOME/.Xresources"
  11. XRESOURCES_THEME_DIR="$XRESOURCES_DIR/theme"
  12. THEME_DIRS=("$FISH_THEME_DIR" "$VIM_THEME_DIR" "$XRESOURCES_THEME_DIR")
  13. switch_theme()
  14. {
  15. local theme_dir="$1"
  16. local theme_file_name="$2"
  17. local symlink_name="$SYMLINK_NAME"
  18. cd "$theme_dir"
  19. if test -f "$theme_file_name"
  20. then
  21. ln -sf "$theme_file_name" "$symlink_name"
  22. echo "Trace: $theme_dir: $theme_file_name linked to $symlink_name."
  23. else
  24. echo "Exit: $theme_file_name doesn't exist in $theme_dir, not linked."
  25. exit 1
  26. fi
  27. }
  28. xrdb_exists()
  29. {
  30. command -v xrdb > /dev/null
  31. }
  32. xresources_file_exists()
  33. {
  34. test -e "$XRESOURCES_FILE"
  35. }
  36. xresources_ready()
  37. {
  38. xrdb_exists && xresources_file_exists
  39. }
  40. switch_theme_xresources()
  41. {
  42. if xresources_ready
  43. then
  44. echo "Trace: Xresources ready, will switch Xresources theme."
  45. local theme_file_name="$1"
  46. switch_theme "$XRESOURCES_THEME_DIR" "$theme_file_name"
  47. xrdb -load "$XRESOURCES_FILE"
  48. else
  49. echo "Warning: Xresources not ready, will not switch Xresources theme."
  50. fi
  51. }
  52. switch_to_dark()
  53. {
  54. local primary_theme=tempus_future.dark
  55. switch_theme "$VIM_THEME_DIR" "$primary_theme"
  56. switch_theme_xresources "$primary_theme"
  57. local fallback_theme=tokyonight.night
  58. switch_theme "$FISH_THEME_DIR" "$fallback_theme"
  59. }
  60. switch_to_light()
  61. {
  62. local primary_theme=tempus_totus.light
  63. switch_theme "$VIM_THEME_DIR" "$primary_theme"
  64. switch_theme_xresources "$primary_theme"
  65. local fallback_theme=tokyonight.day
  66. switch_theme "$FISH_THEME_DIR" "$fallback_theme"
  67. }
  68. case "$REQUEST" in
  69. dark | night)
  70. switch_to_dark
  71. ;;
  72. light | day)
  73. switch_to_light
  74. ;;
  75. *)
  76. echo "Error: ${REQUEST:--no request-} is not a valid request."
  77. exit 1
  78. ;;
  79. esac
  80. #for theme_dir in "${THEME_DIRS[@]}"
  81. #do
  82. # switch_theme "$theme_dir" "$THEME_FILE_NAME" "$SYMLINK_NAME"
  83. #done