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.

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