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.

246 lines
8.0 KiB

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