dotfiles/.config/zsh/plugins.zsh

89 lines
3.3 KiB
Bash
Raw Normal View History

# Generate plugin lists and update or install them
function()
{
setopt LOCAL_OPTIONS EXTENDED_GLOB
local -a _my_plugins=(
mafredri/zsh-async
zsh-users/zsh-completions
# Must come before autosuggestions and syntax-highlighting
Aloxaf/fzf-tab
zsh-users/zsh-autosuggestions
zsh-users/zsh-syntax-highlighting
# Must come after zsh-syntax-highlighting
zsh-users/zsh-history-substring-search
)
if ! command -v fzf > /dev/null; then
# Don't load these plugins if fzf was not found
_my_plugins=(${_my_plugins:#Aloxaf/fzf-tab})
fi
if [[ "$HOST" == "steuerbeamter" ]]; then
# Don't load these plugins on slow computers
_my_plugins=(${_my_plugins:#zsh-users/zsh-autosuggestions})
fi
local -a _my_plugins_dist
# Don't load plugins that are installed by the package manager
if [[ -f /etc/gentoo-release ]]; then
local _gentoo_plugin_dir="/usr/share/zsh/site-functions"
if [[ -d /var/db/pkg/app-shells/zsh-async-*(#qN) ]]; then
_my_plugins=(${_my_plugins:#mafredri/zsh-async})
_my_plugins_dist+=(${_gentoo_plugin_dir}/async.zsh)
fi
if [[ -d /var/db/pkg/app-shells/zsh-completions-*(#qN) ]]; then
_my_plugins=(${_my_plugins:#zsh-users/zsh-completions})
fi
if [[ -d /var/db/pkg/app-shells/fzf-tab-*(#qN) ]]; then
_my_plugins=(${_my_plugins:#Aloxaf/fzf-tab})
_my_plugins_dist+=(${_gentoo_plugin_dir}/fzf-tab.zsh)
fi
if [[ -d /var/db/pkg/app-shells/zsh-autosuggestions-*(#qN) ]]; then
_my_plugins=(${_my_plugins:#zsh-users/zsh-autosuggestions})
_my_plugins_dist+=(${_gentoo_plugin_dir}/zsh-autosuggestions.zsh)
fi
if [[ -d /var/db/pkg/app-shells/zsh-syntax-highlighting-*(#qN) ]]; then
_my_plugins=(${_my_plugins:#zsh-users/zsh-syntax-highlighting})
_my_plugins_dist+=(${_gentoo_plugin_dir}/zsh-syntax-highlighting.zsh)
fi
if [[ -d /var/db/pkg/app-shells/zsh-history-substring-search-*(#qN) ]]; then
_my_plugins=(${_my_plugins:#zsh-users/zsh-history-substring-search})
_my_plugins_dist+=(${_gentoo_plugin_dir}/zsh-history-substring-search.zsh)
fi
fi
export ZSH_PLUGIN_DIST="${_my_plugins_dist}" # Arrays can not be exported
[[ -z ${_my_plugins} ]] && return
# If there are plugins not handled by the package manager, use antibody
if command -v antibody > /dev/null; then
zmodload zsh/stat
zmodload zsh/datetime
local plugin_cache_dir="$(antibody home)"
export ZSH_PLUGIN_SOURCE="${plugin_cache_dir}/antibody-plugins.zsh"
if [[ -f "${ZSH_PLUGIN_SOURCE}" ]] \
&& [[ $(zstat +size "${ZSH_PLUGIN_SOURCE}") -ne 0 ]]; then
local _plugins_modified=$(zstat +mtime "${ZSH_PLUGIN_SOURCE}")
local _now=$(strftime '%s')
# Update plugins every 10 days
if [[ $(( ${_now} - ${_plugins_modified} - 60 * 60 * 24 * 10)) -gt 0 ]]; then
print "\e[3;95mUpdating plugins…\e[0m"
antibody update --parallelism=$(nproc --ignore=1) \
&& touch "${ZSH_PLUGIN_SOURCE}"
fi
else
print "\e[3;95mInstalling plugins…\e[0m"
mkdir -p "${plugin_cache_dir}"
antibody bundle --parallelism=$(nproc --ignore=1) \
<<<$(print -l ${_my_plugins}) > "${ZSH_PLUGIN_SOURCE}"
fi
else
print -u 2 "\e[7;95mantibody not found.\e[0m"
fi
}