Refactor: extract _zimfw_print function
This commit is contained in:
parent
2cc69d5d6f
commit
424526ebee
9 changed files with 28 additions and 53 deletions
5
src/stage2/22_zimfw_print.zsh.erb
Normal file
5
src/stage2/22_zimfw_print.zsh.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
_zimfw_print() {
|
||||||
|
if (( ! _zquiet )); then
|
||||||
|
print "${@}"
|
||||||
|
fi
|
||||||
|
}
|
|
@ -1,15 +1,11 @@
|
||||||
_zimfw_mv() {
|
_zimfw_mv() {
|
||||||
if command cmp -s ${2} ${1}; then
|
if command cmp -s ${2} ${1}; then
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -PR "<%= okay %>%B${2}:%b Already up to date"
|
||||||
print -PR "<%= okay %>%B${2}:%b Already up to date"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
if [[ -e ${2} ]]; then
|
if [[ -e ${2} ]]; then
|
||||||
command mv -f ${2}{,.old} || return 1
|
command mv -f ${2}{,.old} || return 1
|
||||||
fi
|
fi
|
||||||
command mv -f ${1} ${2} && \
|
command mv -f ${1} ${2} && \
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -PR "<%= okay %>%B${2}:%b Updated. Restart your terminal for changes to take effect."
|
||||||
print -PR "<%= okay %>%B${2}:%b Updated. Restart your terminal for changes to take effect."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
_zimfw_build() {
|
_zimfw_build() {
|
||||||
_zimfw_build_init && _zimfw_build_login_init && \
|
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P '<%= done %>Done with build.'
|
||||||
if (( ! _zquiet )); then
|
|
||||||
print -P '<%= done %>Done with build.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,5 @@ _zimfw_clean_compiled() {
|
||||||
(( ! _zquiet )) && zopt='-v'
|
(( ! _zquiet )) && zopt='-v'
|
||||||
command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1
|
command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1
|
||||||
command rm -f ${zopt} <%= home %>/<%= startup_files_glob %>.zwc(|.old)(N) || return 1
|
command rm -f ${zopt} <%= home %>/<%= startup_files_glob %>.zwc(|.old)(N) || return 1
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
|
||||||
print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,5 @@ _zimfw_clean_dumpfile() {
|
||||||
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
|
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
|
||||||
(( ! _zquiet )) && zopt='-v'
|
(( ! _zquiet )) && zopt='-v'
|
||||||
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1
|
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
|
||||||
print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,5 @@ _zimfw_uninstall() {
|
||||||
command rm -rf ${zopt} ${zdir} || return 1
|
command rm -rf ${zopt} ${zdir} || return 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -P '<%= done %>Done with uninstall.'
|
||||||
print -P '<%= done %>Done with uninstall.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,7 @@ _zimfw_upgrade() {
|
||||||
else
|
else
|
||||||
command curl -fsSL -o ${ztarget}.new ${zurl} || return 1
|
command curl -fsSL -o ${ztarget}.new ${zurl} || return 1
|
||||||
fi
|
fi
|
||||||
_zimfw_mv ${ztarget}{.new,} && \
|
_zimfw_mv ${ztarget}{.new,} && _zimfw_print -P '<%= done %>Done with upgrade.'
|
||||||
if (( ! _zquiet )); then
|
|
||||||
print -P '<%= done %>Done with upgrade.'
|
|
||||||
fi
|
|
||||||
} always {
|
} always {
|
||||||
command rm -f ${ztarget}.new
|
command rm -f ${ztarget}.new
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,7 @@ Options:
|
||||||
install|update)
|
install|update)
|
||||||
_zimfw_source_zimrc 1 || return 1
|
_zimfw_source_zimrc 1 || return 1
|
||||||
print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \
|
print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." && \
|
||||||
print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect."
|
|
||||||
fi && \
|
|
||||||
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2}
|
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2}
|
||||||
;;
|
;;
|
||||||
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;
|
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;
|
||||||
|
|
42
zimfw.zsh
42
zimfw.zsh
|
@ -32,19 +32,21 @@ fi
|
||||||
# Define Zim location
|
# Define Zim location
|
||||||
: ${ZIM_HOME=${0:A:h}}
|
: ${ZIM_HOME=${0:A:h}}
|
||||||
|
|
||||||
|
_zimfw_print() {
|
||||||
|
if (( ! _zquiet )); then
|
||||||
|
print "${@}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
_zimfw_mv() {
|
_zimfw_mv() {
|
||||||
if command cmp -s ${2} ${1}; then
|
if command cmp -s ${2} ${1}; then
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -PR "%F{green})%f %B${2}:%b Already up to date"
|
||||||
print -PR "%F{green})%f %B${2}:%b Already up to date"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
if [[ -e ${2} ]]; then
|
if [[ -e ${2} ]]; then
|
||||||
command mv -f ${2}{,.old} || return 1
|
command mv -f ${2}{,.old} || return 1
|
||||||
fi
|
fi
|
||||||
command mv -f ${1} ${2} && \
|
command mv -f ${1} ${2} && \
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -PR "%F{green})%f %B${2}:%b Updated. Restart your terminal for changes to take effect."
|
||||||
print -PR "%F{green})%f %B${2}:%b Updated. Restart your terminal for changes to take effect."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,10 +97,7 @@ _zimfw_build_login_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_build() {
|
_zimfw_build() {
|
||||||
_zimfw_build_init && _zimfw_build_login_init && \
|
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P 'Done with build.'
|
||||||
if (( ! _zquiet )); then
|
|
||||||
print -P 'Done with build.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zmodule() {
|
zmodule() {
|
||||||
|
@ -243,9 +242,7 @@ _zimfw_clean_compiled() {
|
||||||
(( ! _zquiet )) && zopt='-v'
|
(( ! _zquiet )) && zopt='-v'
|
||||||
command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1
|
command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1
|
||||||
command rm -f ${zopt} ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout).zwc(|.old)(N) || return 1
|
command rm -f ${zopt} ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout).zwc(|.old)(N) || return 1
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
|
||||||
print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_clean_dumpfile() {
|
_zimfw_clean_dumpfile() {
|
||||||
|
@ -253,9 +250,7 @@ _zimfw_clean_dumpfile() {
|
||||||
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
|
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
|
||||||
(( ! _zquiet )) && zopt='-v'
|
(( ! _zquiet )) && zopt='-v'
|
||||||
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1
|
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
|
||||||
print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_compile() {
|
_zimfw_compile() {
|
||||||
|
@ -263,7 +258,7 @@ _zimfw_compile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_info() {
|
_zimfw_info() {
|
||||||
print 'Zim version: 1.0.1-SNAPSHOT (previous commit is 7374770)'
|
print 'Zim version: 1.0.1-SNAPSHOT (previous commit is 2cc69d5)'
|
||||||
print -R 'ZIM_HOME: '${ZIM_HOME}
|
print -R 'ZIM_HOME: '${ZIM_HOME}
|
||||||
print -R 'Zsh version: '${ZSH_VERSION}
|
print -R 'Zsh version: '${ZSH_VERSION}
|
||||||
print -R 'System info: '$(command uname -a)
|
print -R 'System info: '$(command uname -a)
|
||||||
|
@ -279,9 +274,7 @@ _zimfw_uninstall() {
|
||||||
command rm -rf ${zopt} ${zdir} || return 1
|
command rm -rf ${zopt} ${zdir} || return 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -P 'Done with uninstall.'
|
||||||
print -P 'Done with uninstall.'
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_upgrade() {
|
_zimfw_upgrade() {
|
||||||
|
@ -293,10 +286,7 @@ _zimfw_upgrade() {
|
||||||
else
|
else
|
||||||
command curl -fsSL -o ${ztarget}.new ${zurl} || return 1
|
command curl -fsSL -o ${ztarget}.new ${zurl} || return 1
|
||||||
fi
|
fi
|
||||||
_zimfw_mv ${ztarget}{.new,} && \
|
_zimfw_mv ${ztarget}{.new,} && _zimfw_print -P 'Done with upgrade.'
|
||||||
if (( ! _zquiet )); then
|
|
||||||
print -P 'Done with upgrade.'
|
|
||||||
fi
|
|
||||||
} always {
|
} always {
|
||||||
command rm -f ${ztarget}.new
|
command rm -f ${ztarget}.new
|
||||||
}
|
}
|
||||||
|
@ -437,9 +427,7 @@ fi
|
||||||
install|update)
|
install|update)
|
||||||
_zimfw_source_zimrc 1 || return 1
|
_zimfw_source_zimrc 1 || return 1
|
||||||
print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \
|
print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \
|
||||||
if (( ! _zquiet )); then
|
_zimfw_print -PR "Done with ${1}. Restart your terminal for any changes to take effect." && \
|
||||||
print -PR "Done with ${1}. Restart your terminal for any changes to take effect."
|
|
||||||
fi && \
|
|
||||||
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2}
|
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2}
|
||||||
;;
|
;;
|
||||||
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;
|
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;
|
||||||
|
|
Loading…
Reference in a new issue