Zsh: Rewrite plugin update mechanism

This commit is contained in:
tastytea 2022-03-28 06:51:55 +02:00
parent cf8b4b8d7e
commit 2cc6086cbb
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -42,29 +42,28 @@ export ALTERNATE_EDITOR="$(command -v nano)"
if command -v fzf > /dev/null; then
# Only load these plugins if fzf was found.
local depends_on_fzf="Aloxaf/fzf-tab"
local _depends_on_fzf="Aloxaf/fzf-tab"
fi
if command -v antibody > /dev/null; then
local plugin_cache_dir="$(antibody home)"
export ZSH_PLUGIN_SOURCE="${plugin_cache_dir}/antibody-plugins.zsh"
if [[ -f ${ZSH_PLUGIN_SOURCE} ]] \
&& [[ $(stat --format="%s" ${ZSH_PLUGIN_SOURCE}) -ne 0 ]]; then
local mod_month="$(stat --format="%y" ${ZSH_PLUGIN_SOURCE} 2> /dev/null | cut -d\- -f2)"
# Update plugins every month.
if [[ ${mod_month} -ne $(date +'%m') ]]; then
if [[ -f "${ZSH_PLUGIN_SOURCE}" ]] \
&& [[ $(stat --format="%s" "${ZSH_PLUGIN_SOURCE}") -ne 0 ]]; then
local _plugins_modified=$(stat --format="%Y" "${ZSH_PLUGIN_SOURCE}")
local _now=$(date '+%s')
# Update plugins every 10 days
if [[ $(( (${_now} - ${_plugins_modified} - 60 * 60 * 24 * 10) > 0 )) ]]; then
print "\e[3;95mUpdating plugins…\e[0m"
antibody update --parallelism=$(nproc --ignore=1) \
&& touch ${ZSH_PLUGIN_SOURCE}
&& touch "${ZSH_PLUGIN_SOURCE}"
fi
else
print "\e[3;95mInstalling plugins…\e[0m"
mkdir -p ${plugin_cache_dir}
antibody bundle --parallelism=$(nproc --ignore=1) <<EOF > ${ZSH_PLUGIN_SOURCE}
# robbyrussell/oh-my-zsh path:lib
# robbyrussell/oh-my-zsh path:plugins/history-substring-search
${depends_on_fzf}
mkdir -p "${plugin_cache_dir}"
antibody bundle --parallelism=$(nproc --ignore=1) <<EOF > "${ZSH_PLUGIN_SOURCE}"
${_depends_on_fzf}
zsh-users/zsh-autosuggestions
mafredri/zsh-async
zsh-users/zsh-syntax-highlighting
@ -73,7 +72,7 @@ zsh-users/zsh-history-substring-search
EOF
fi
else
echo "antibody not found." >&2
print -u 2 "\e[7;95mantibody not found.\e[0m"
fi
############################# Variables ########################################