diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index ec964ad..71cd29a 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -40,49 +40,8 @@ export EDITOR="${VISUAL}" ############################# Plugins ########################################## -zmodload zsh/stat -zmodload zsh/datetime - -local -a _my_plugins=( - mafredri/zsh-async - 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 - -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 +# Generate plugin lists and update or install them +source "${ZDOTDIR}"/plugins.zsh ############################# Variables ######################################## diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 3571631..0d27c2b 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -52,7 +52,10 @@ add-zsh-hook zshaddhistory _my_import_history_zshaddhistory ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=236" -# Set up in .zprofile. +for plugin in "${(@s/ /)ZSH_PLUGIN_DIST}"; do + [[ -n "${plugin}" ]] && source "${plugin}" +done +unset plugin source "${ZSH_PLUGIN_SOURCE}" # Fuzzy finder, . diff --git a/.config/zsh/plugins.zsh b/.config/zsh/plugins.zsh new file mode 100644 index 0000000..8fcee0b --- /dev/null +++ b/.config/zsh/plugins.zsh @@ -0,0 +1,70 @@ +# 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 + +}