1
0
Fork 0
mirror of synced 2024-11-22 23:35:35 -05:00

Refactor: extract _zimfw_print function

This commit is contained in:
Eric Nielsen 2020-01-09 07:13:31 -05:00
parent 2cc69d5d6f
commit 424526ebee
No known key found for this signature in database
GPG key ID: 47D1DBFA0765A1FB
9 changed files with 28 additions and 53 deletions

View file

@ -0,0 +1,5 @@
_zimfw_print() {
if (( ! _zquiet )); then
print "${@}"
fi
}

View file

@ -1,15 +1,11 @@
_zimfw_mv() {
if command cmp -s ${2} ${1}; then
if (( ! _zquiet )); then
print -PR "<%= okay %>%B${2}:%b Already up to date"
fi
_zimfw_print -PR "<%= okay %>%B${2}:%b Already up to date"
else
if [[ -e ${2} ]]; then
command mv -f ${2}{,.old} || return 1
fi
command mv -f ${1} ${2} && \
if (( ! _zquiet )); then
print -PR "<%= okay %>%B${2}:%b Updated. Restart your terminal for changes to take effect."
fi
_zimfw_print -PR "<%= okay %>%B${2}:%b Updated. Restart your terminal for changes to take effect."
fi
}

View file

@ -1,6 +1,3 @@
_zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && \
if (( ! _zquiet )); then
print -P '<%= done %>Done with build.'
fi
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P '<%= done %>Done with build.'
}

View file

@ -3,7 +3,5 @@ _zimfw_clean_compiled() {
(( ! _zquiet )) && zopt='-v'
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
if (( ! _zquiet )); then
print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
fi
_zimfw_print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
}

View file

@ -3,7 +3,5 @@ _zimfw_clean_dumpfile() {
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
(( ! _zquiet )) && zopt='-v'
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1
if (( ! _zquiet )); then
print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
fi
_zimfw_print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
}

View file

@ -8,7 +8,5 @@ _zimfw_uninstall() {
command rm -rf ${zopt} ${zdir} || return 1
fi
done
if (( ! _zquiet )); then
print -P '<%= done %>Done with uninstall.'
fi
_zimfw_print -P '<%= done %>Done with uninstall.'
}

View file

@ -7,10 +7,7 @@ _zimfw_upgrade() {
else
command curl -fsSL -o ${ztarget}.new ${zurl} || return 1
fi
_zimfw_mv ${ztarget}{.new,} && \
if (( ! _zquiet )); then
print -P '<%= done %>Done with upgrade.'
fi
_zimfw_mv ${ztarget}{.new,} && _zimfw_print -P '<%= done %>Done with upgrade.'
} always {
command rm -f ${ztarget}.new
}

View file

@ -53,9 +53,7 @@ Options:
install|update)
_zimfw_source_zimrc 1 || return 1
print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \
if (( ! _zquiet )); then
print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect."
fi && \
_zimfw_print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." && \
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2}
;;
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;

View file

@ -32,19 +32,21 @@ fi
# Define Zim location
: ${ZIM_HOME=${0:A:h}}
_zimfw_print() {
if (( ! _zquiet )); then
print "${@}"
fi
}
_zimfw_mv() {
if command cmp -s ${2} ${1}; then
if (( ! _zquiet )); then
print -PR "%F{green})%f %B${2}:%b Already up to date"
fi
_zimfw_print -PR "%F{green})%f %B${2}:%b Already up to date"
else
if [[ -e ${2} ]]; then
command mv -f ${2}{,.old} || return 1
fi
command mv -f ${1} ${2} && \
if (( ! _zquiet )); then
print -PR "%F{green})%f %B${2}:%b Updated. Restart your terminal for changes to take effect."
fi
_zimfw_print -PR "%F{green})%f %B${2}:%b Updated. Restart your terminal for changes to take effect."
fi
}
@ -95,10 +97,7 @@ _zimfw_build_login_init() {
}
_zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && \
if (( ! _zquiet )); then
print -P 'Done with build.'
fi
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P 'Done with build.'
}
zmodule() {
@ -243,9 +242,7 @@ _zimfw_clean_compiled() {
(( ! _zquiet )) && zopt='-v'
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
if (( ! _zquiet )); then
print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
fi
_zimfw_print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.'
}
_zimfw_clean_dumpfile() {
@ -253,9 +250,7 @@ _zimfw_clean_dumpfile() {
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
(( ! _zquiet )) && zopt='-v'
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1
if (( ! _zquiet )); then
print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
fi
_zimfw_print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
}
_zimfw_compile() {
@ -263,7 +258,7 @@ _zimfw_compile() {
}
_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 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a)
@ -279,9 +274,7 @@ _zimfw_uninstall() {
command rm -rf ${zopt} ${zdir} || return 1
fi
done
if (( ! _zquiet )); then
print -P 'Done with uninstall.'
fi
_zimfw_print -P 'Done with uninstall.'
}
_zimfw_upgrade() {
@ -293,10 +286,7 @@ _zimfw_upgrade() {
else
command curl -fsSL -o ${ztarget}.new ${zurl} || return 1
fi
_zimfw_mv ${ztarget}{.new,} && \
if (( ! _zquiet )); then
print -P 'Done with upgrade.'
fi
_zimfw_mv ${ztarget}{.new,} && _zimfw_print -P 'Done with upgrade.'
} always {
command rm -f ${ztarget}.new
}
@ -437,9 +427,7 @@ fi
install|update)
_zimfw_source_zimrc 1 || return 1
print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \
if (( ! _zquiet )); then
print -PR "Done with ${1}. Restart your terminal for any changes to take effect."
fi && \
_zimfw_print -PR "Done with ${1}. Restart your terminal for any changes to take effect." && \
_zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2}
;;
uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;;