# 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 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 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/zsh-autosuggestions-*(#qN) ]]; then _my_plugins=(${_my_plugins:#zsh-users/zsh-autosuggestions}) _my_plugins_dist+=(/usr/share/zsh/site-functions/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+=(/usr/share/zsh/site-functions/zsh-syntax-highlighting.zsh) fi fi export ZSH_PLUGIN_DIST="${_my_plugins_dist}" # Arrays can not be exported zmodload zsh/stat zmodload zsh/datetime 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}" ]] \ && [[ $(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 }