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.

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