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.

249 lines
7.1 KiB

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