init.zsh 2.6 KB

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