module-custom.zsh (1889B)
1 zmodule-custom() { 2 local zcommand zname ztarget 3 local -a zargs 4 zcommand=${1} 5 zname=custom/${zcommand} 6 shift 7 while (( # > 0 )); do 8 case ${1} in 9 --name) 10 shift 11 zname=${1} 12 ;; 13 --if) 14 shift 15 zargs+=(--if "(( \${+commands[${zcommand}]} )) && ${1}") 16 ;; 17 --if-command) 18 shift 19 zargs+=(--if "(( \${+commands[${zcommand}]} && \${+commands[${1}]} ))") 20 ;; 21 --if-ostype) 22 shift 23 zargs+=(--if "(( \${+commands[${zcommand}]} )) && [[ \${OSTYPE} == ${1} ]]") 24 ;; 25 --on-pull) 26 shift 27 zargs+=(--on-pull ${1}) 28 ;; 29 -d|--disabled) 30 zargs+=(--disabled) 31 ;; 32 -f|--fpath) 33 shift 34 zargs+=(--fpath ${1}) 35 ;; 36 -a|--autoload) 37 shift 38 zargs+=(--autoload ${1}) 39 ;; 40 -s|--source) 41 shift 42 zargs+=(--source ${1}) 43 ;; 44 -c|--cmd) 45 shift 46 zargs+=(--cmd ${1}) 47 ;; 48 --comp) 49 shift 50 ztarget=functions/_${1//[^[:IDENT:]]/-} 51 zargs+=(--on-pull "mkdir -p functions") 52 zargs+=(--fpath functions) 53 zargs+=(--cmd "if [[ ! {}/${ztarget} -nt \${commands[${zcommand}]} ]]; then ${1} >! {}/${ztarget}; fi") 54 zargs+=(--cmd "if (( \${+_comps} && ! \${+_comps[${zcommand}]} )); then autoload -Uz ${ztarget:t}; _comps[${zcommand}]=${ztarget:t}; fi") 55 ;; 56 --eval) 57 shift 58 ztarget=${1//[^[:IDENT:]]/-}.zsh 59 zargs+=(--cmd "if [[ ! {}/${ztarget} -nt \${commands[${zcommand}]} ]]; then ${1} >! {}/${ztarget}; zcompile -UR {}/${ztarget}; fi") 60 zargs+=(--source ${ztarget}) 61 ;; 62 *) 63 print "Unknown zmodule option ${1}" 64 return 2 65 ;; 66 esac 67 shift 68 done 69 70 zmodule custom-${zcommand} --name ${zname} --use mkdir --if-command ${zcommand} ${zargs} 71 }