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.

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