Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
7.8 KiB

  1. install_prelude () {
  2. printf " Cloning the Prelude's GitHub repository...\n$RESET"
  3. if [ x$PRELUDE_VERBOSE != x ]
  4. then
  5. /usr/bin/env git clone $PRELUDE_URL "$PRELUDE_INSTALL_DIR"
  6. else
  7. /usr/bin/env git clone $PRELUDE_URL "$PRELUDE_INSTALL_DIR" > /dev/null
  8. fi
  9. if ! [ $? -eq 0 ]
  10. then
  11. printf "$RED A fatal error occurred during Prelude's installation. Aborting..."
  12. exit 1
  13. fi
  14. }
  15. make_prelude_dirs () {
  16. printf " Making the required directories.\n$RESET"
  17. mkdir -p "$PRELUDE_INSTALL_DIR/vendor" "$PRELUDE_INSTALL_DIR/personal"
  18. mkdir -p "$PRELUDE_INSTALL_DIR/themes"
  19. mkdir -p "$PRELUDE_INSTALL_DIR/savefile"
  20. }
  21. colors_ () {
  22. case "$SHELL" in
  23. *zsh)
  24. autoload colors && colors
  25. eval RESET='$reset_color'
  26. for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE
  27. do
  28. eval $COLOR='$fg_no_bold[${(L)COLOR}]'
  29. eval B$COLOR='$fg_bold[${(L)COLOR}]'
  30. done
  31. ;;
  32. *)
  33. RESET='\e[0m' # Reset
  34. RED='\e[0;31m' # Red
  35. GREEN='\e[0;32m' # Green
  36. YELLOW='\e[0;33m' # Yellow
  37. BLUE='\e[0;34m' # Blue
  38. PURPLE='\e[0;35m' # Magenta
  39. CYAN='\e[0;36m' # Cyan
  40. WHITE='\e[0;37m' # White
  41. BRED='\e[1;31m' # Bold Red
  42. BGREEN='\e[1;32m' # Bold Green
  43. BYELLOW='\e[1;33m' # Bold Yellow
  44. BBLUE='\e[1;34m' # Bold Blue
  45. BPURPLE='\e[1;35m' # Bold Magenta
  46. BCYAN='\e[1;36m' # Bold Cyan
  47. BWHITE='\e[1;37m' # Bold White
  48. ;;
  49. esac
  50. }
  51. # Commandline args:
  52. # -d/--directory [dir]
  53. # Install prelude into the specified directory. If 'dir' is a relative path prefix it with $HOME.
  54. # Defaults to '$HOME/.emacs.d'
  55. # -c/--colors
  56. # Enable colors
  57. # -s/--source [url]
  58. # Clone prelude from 'url'.
  59. # Defaults to 'https://github.com/bbatsov/prelude.git'
  60. # -i/--into
  61. # If one exists, install into the existing config
  62. # -n/--no-bytecompile
  63. # Skip the compilation of the prelude files.
  64. # -h/--help
  65. # Print help
  66. # -v/--verbose
  67. # Verbose output, for debugging
  68. usage() {
  69. printf "Usage: $0 [OPTION]\n"
  70. printf " -c, --colors \t \t \t Enable colors.\n"
  71. printf " -d, --directory [dir] \t Install prelude into the specified directory.\n"
  72. printf " \t \t \t \t If 'dir' is a relative path prefix with $HOME.\n"
  73. printf " \t \t \t \t Defaults to $HOME/.emacs.d\n"
  74. printf " -s, --source [url] \t \t Clone prelude from 'url'.\n"
  75. printf " \t \t \t \t Defaults to 'https://github.com/bbatsov/prelude.git'.\n"
  76. printf " -n, --no-bytecompile \t \t Skip the bytecompilation step of prelude.\n"
  77. printf " -i, --into \t \t \t Install Prelude into a subdirectory in the existing configuration\n"
  78. printf " \t \t \t \t The default behavious is to install prelude into the existing\n"
  79. printf " \t \t \t \t emacs configuration.\n"
  80. printf " -h, --help \t \t \t Display this help and exit\n"
  81. printf " -v, --verbose \t \t Display verbose information\n"
  82. printf "\n"
  83. }
  84. ### Parse cli
  85. while [ $# -gt 0 ]
  86. do
  87. case $1 in
  88. -d | --directory)
  89. PRELUDE_INSTALL_DIR=$2
  90. shift 2
  91. ;;
  92. -c | --colors)
  93. colors_
  94. shift 1
  95. ;;
  96. -s | --source)
  97. PRELUDE_URL=$2
  98. shift 2
  99. ;;
  100. -i | --into)
  101. PRELUDE_INTO='true'
  102. shift 1
  103. ;;
  104. -n | --no-bytecompile)
  105. PRELUDE_SKIP_BC='true'
  106. shift 1
  107. ;;
  108. -h | --help)
  109. usage
  110. exit 0
  111. ;;
  112. -v | --verbose)
  113. PRELUDE_VERBOSE='true';
  114. shift 1
  115. ;;
  116. *)
  117. printf "Unkown option: $1\n"
  118. shift 1
  119. ;;
  120. esac
  121. done
  122. VERBOSE_COLOR=$BBLUE
  123. [ -z "$PRELUDE_URL" ] && PRELUDE_URL="https://github.com/bbatsov/prelude.git"
  124. [ -z "$PRELUDE_INSTALL_DIR" ] && PRELUDE_INSTALL_DIR="$HOME/.emacs.d"
  125. if [ x$PRELUDE_VERBOSE != x ]
  126. then
  127. printf "$VERBOSE_COLOR"
  128. printf "PRELUDE_VERBOSE = $PRELUDE_VERBOSE\n"
  129. printf "INSTALL_DIR = $PRELUDE_INSTALL_DIR\n"
  130. printf "SOURCE_URL = $PRELUDE_URL\n"
  131. printf "$RESET"
  132. if [ -n "$PRELUDE_SKIP_BC" ]
  133. then
  134. printf "Skipping bytecompilation.\n"
  135. fi
  136. if [ -n "$PRELUDE_INTO" ]
  137. then
  138. printf "Replacing existing config (if one exists).\n"
  139. fi
  140. printf "$RESET"
  141. fi
  142. # If prelude is already installed
  143. if [ -d "$PRELUDE_INSTALL_DIR/core/prelude-core.el" ]
  144. then
  145. printf "\n\n$BRED"
  146. printf "You already have Prelude installed.$RESET\nYou'll need to remove $PRELUDE_INSTALL_DIR/prelude if you want to install Prelude again.\n"
  147. printf "If you want to update your copy of prelude, run 'git pull origin master' from your prelude directory\n\n"
  148. exit 1;
  149. fi
  150. ### Check dependencies
  151. printf "$CYAN Checking to see if git is installed... $RESET"
  152. if hash git 2>&-
  153. then
  154. printf "$GREEN found.$RESET\n"
  155. else
  156. printf "$RED not found. Aborting installation!$RESET\n"
  157. exit 1
  158. fi;
  159. printf "$CYAN Checking to see if aspell is installed... "
  160. if hash aspell 2>&-
  161. then
  162. printf "$GREEN found.$RESET\n"
  163. else
  164. printf "$RED not found. Install aspell to benefit from flyspell-mode!$RESET\n"
  165. fi
  166. ### Check emacs version
  167. if [ $(emacs --version 2>/dev/null | sed -n 's/.*[^0-9.]\([0-9]*\.[0-9.]*\).*/\1/p;q' | sed 's/\..*//g') -lt 24 ]
  168. then
  169. printf "$YELLOW WARNING:$RESET Prelude depends on emacs $RED 24$RESET !\n"
  170. fi
  171. if [ -d "$PRELUDE_INSTALL_DIR" ] || [ -f "$PRELUDE_INSTALL_DIR" ]
  172. then
  173. # Existing file/directory found -> backup
  174. printf " Backing up the existing config to $PRELUDE_INSTALL_DIR.pre-prelude.tar.\n"
  175. tar -cf "$PRELUDE_INSTALL_DIR.pre-prelude.tar" "$PRELUDE_INSTALL_DIR" > /dev/null 2>&1
  176. PRELUDE_INSTALL_DIR_ORIG="$PRELUDE_INSTALL_DIR"
  177. # Overwrite existing?
  178. [ -n "$PRELUDE_INTO" ] && PRELUDE_INSTALL_DIR="$PRELUDE_INSTALL_DIR/prelude"
  179. # Clear destination directory for git clone to work
  180. rm -fr "$PRELUDE_INSTALL_DIR"
  181. mkdir "$PRELUDE_INSTALL_DIR"
  182. # Replace existing config
  183. install_prelude
  184. make_prelude_dirs
  185. # Reinstate files that weren't replaced
  186. tar --skip-old-files -xf "$PRELUDE_INSTALL_DIR_ORIG.pre-prelude.tar" "$PRELUDE_INSTALL_DIR" > /dev/null 2>&1
  187. [ -n "$PRELUDE_INTO" ] && cp "$PRELUDE_INSTALL_DIR/sample/prelude-modules.el" "$PRELUDE_INSTALL_DIR"
  188. elif [ -e "$PRELUDE_INSTALL_DIR" ]
  189. then
  190. # File exist but not a regular file or directory
  191. # WTF NOW?
  192. printf "$BRED $PRELUDE_INSTALL_DIR exist but isn't a file or directory.\n"
  193. printf "$BRED please remove this file or install prelude in a different directory"
  194. printf "$BRED (-d flag)\n$RESET"
  195. exit 1
  196. else
  197. # Nothing yet so just install prelude
  198. install_prelude
  199. make_prelude_dirs
  200. cp "$PRELUDE_INSTALL_DIR/sample/prelude-modules.el" "$PRELUDE_INSTALL_DIR"
  201. fi
  202. if [ -z "$PRELUDE_SKIP_BC" ];
  203. then
  204. if which emacs > /dev/null 2>&1
  205. then
  206. printf " Bytecompiling Prelude.\n"
  207. if [ x$PRELUDE_VERBOSE != x ]
  208. then
  209. emacs -batch -f batch-byte-compile "$PRELUDE_INSTALL_DIR/core"/*.el
  210. else
  211. emacs -batch -f batch-byte-compile "$PRELUDE_INSTALL_DIR/core"/*.el > /dev/null 2>&1
  212. fi
  213. else
  214. printf "$YELLOW Emacs not found.$RESET Skipping bytecompilation.\n"
  215. fi
  216. else
  217. printf "Skipping bytecompilation.\n"
  218. fi
  219. printf "\n"
  220. printf "$BBLUE ____ _ _ \n"
  221. printf "$BBLUE | _ \ _ __ ___| |_ _ __| | ___ \n"
  222. printf "$BBLUE | |_) | __/ _ \ | | | |/ _ |/ _ \ \n"
  223. printf "$BBLUE | __/| | | __/ | |_| | (_| | __/ \n"
  224. printf "$BBLUE |_| |_| \___|_|\__,_|\__,_|\___| \n\n"
  225. printf "$GREEN ... is now installed and ready to do thy bidding, Master $USER!$RESET\n"
  226. printf "$GREEN Don't forget to adjust the modules you want to use in $PRELUDE_INSTALL_DIR/prelude-modules.el!$RESET\n"