init.zsh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #
  2. # Zim initializition
  3. #
  4. autoload -Uz is-at-least
  5. if ! is-at-least 5.2; then
  6. print "ERROR: Zim didn't start. You're using zsh version ${ZSH_VERSION}, and versions < 5.2 are not supported. Update your zsh." >&2
  7. return 1
  8. fi
  9. # Define zim location
  10. (( ! ${+ZIM_HOME} )) && export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
  11. # Source user configuration
  12. [[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc
  13. # Autoload module functions
  14. () {
  15. local mod_function
  16. setopt LOCAL_OPTIONS EXTENDED_GLOB
  17. # autoload searches fpath for function locations; add enabled module function paths
  18. fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath})
  19. for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc|*.zwc.old)(-.N:t); do
  20. autoload -Uz ${mod_function}
  21. done
  22. }
  23. # Initialize modules
  24. () {
  25. local zmodule zmodule_dir zmodule_file
  26. for zmodule (${zmodules}); do
  27. zmodule_dir=${ZIM_HOME}/modules/${zmodule}
  28. if [[ ! -d ${zmodule_dir} ]]; then
  29. print "No such module \"${zmodule}\"." >&2
  30. else
  31. for zmodule_file (${zmodule_dir}/{,zsh-}${zmodule}.zsh-theme \
  32. ${zmodule_dir}/init.zsh \
  33. ${zmodule_dir}/{,zsh-}${zmodule}.plugin.zsh \
  34. ${zmodule_dir}/{,zsh-}${zmodule}.{z,}sh); do
  35. if [[ -f ${zmodule_file} ]]; then
  36. source ${zmodule_file}
  37. break
  38. fi
  39. done
  40. fi
  41. done
  42. }
  43. zmanage() {
  44. local usage="zmanage [action]
  45. Actions:
  46. update Fetch and merge upstream zim commits if possible
  47. info Print zim and system info
  48. issue Create a template for reporting an issue
  49. clean-cache Clean the zim cache
  50. build-cache Rebuild the zim cache
  51. remove *experimental* Remove zim as best we can
  52. reset Reset zim to the latest commit
  53. debug Invoke the trace-zim script which produces logs
  54. help Print this usage message"
  55. if (( ${#} != 1 )); then
  56. print ${usage}
  57. return 1
  58. fi
  59. case ${1} in
  60. update) zsh ${ZIM_HOME}/tools/zim_update
  61. ;;
  62. info) zsh ${ZIM_HOME}/tools/zim_info
  63. ;;
  64. issue) zsh ${ZIM_HOME}/tools/zim_issue
  65. ;;
  66. clean-cache) source ${ZIM_HOME}/tools/zim_clean_cache && print 'Cache cleaned'
  67. ;;
  68. build-cache) source ${ZIM_HOME}/tools/zim_build_cache && print 'Cache rebuilt'
  69. ;;
  70. remove) zsh ${ZIM_HOME}/tools/zim_remove
  71. ;;
  72. reset) zsh ${ZIM_HOME}/tools/zim_reset
  73. ;;
  74. debug) zsh ${ZIM_HOME}/modules/debug/functions/trace-zim
  75. ;;
  76. *) print ${usage}; return 1
  77. ;;
  78. esac
  79. }