2022-04-05 15:28:54 +02:00
|
|
|
# Generate plugin lists and update or install them
|
|
|
|
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
|
|
|
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
|
|
|
|
2022-05-01 08:38:56 +02:00
|
|
|
unset ZSH_PLUGIN_DIST ZSH_PLUGIN_SOURCE
|
|
|
|
|
2022-04-05 15:28:54 +02:00
|
|
|
local -a _my_plugins=(
|
|
|
|
zsh-users/zsh-completions
|
2022-04-06 19:52:58 +02:00
|
|
|
mafredri/zsh-async
|
2022-04-05 23:47:18 +02:00
|
|
|
# Must come before autosuggestions and syntax-highlighting
|
2022-04-05 15:28:54 +02:00
|
|
|
Aloxaf/fzf-tab
|
|
|
|
zsh-users/zsh-autosuggestions
|
|
|
|
zsh-users/zsh-syntax-highlighting
|
|
|
|
# Must come after zsh-syntax-highlighting
|
|
|
|
zsh-users/zsh-history-substring-search
|
|
|
|
)
|
2022-04-05 16:33:38 +02:00
|
|
|
|
2022-04-05 15:28:54 +02:00
|
|
|
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
|
2022-04-05 16:33:38 +02:00
|
|
|
|
2022-04-05 15:28:54 +02:00
|
|
|
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
|
2022-04-06 19:52:58 +02:00
|
|
|
# Don't fetch plugins that are installed by the package manager
|
2022-04-05 15:28:54 +02:00
|
|
|
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
|
2022-04-06 19:52:58 +02:00
|
|
|
|
|
|
|
function _plugin_installed()
|
|
|
|
{
|
|
|
|
local catpkg=${1}
|
|
|
|
local uri=${2}
|
|
|
|
local filename=${3}
|
|
|
|
|
|
|
|
if [[ -d /var/db/pkg/${catpkg}-*(#qN) ]]; then
|
|
|
|
_my_plugins=(${_my_plugins:#${uri}})
|
|
|
|
_my_plugins_dist+=(/usr/share/zsh/site-functions/${filename})
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
_plugin_installed app-shells/zsh-async \
|
|
|
|
mafredri/zsh-async \
|
|
|
|
async.zsh
|
|
|
|
_plugin_installed app-shells/fzf-tab \
|
|
|
|
Aloxaf/fzf-tab \
|
|
|
|
fzf-tab.zsh
|
|
|
|
_plugin_installed app-shells/zsh-autosuggestions \
|
|
|
|
zsh-users/zsh-autosuggestions \
|
|
|
|
zsh-autosuggestions.zsh
|
|
|
|
_plugin_installed app-shells/zsh-syntax-highlighting \
|
|
|
|
zsh-users/zsh-syntax-highlighting \
|
|
|
|
zsh-syntax-highlighting.zsh
|
|
|
|
_plugin_installed app-shells/zsh-history-substring-search \
|
|
|
|
zsh-users/zsh-history-substring-search \
|
|
|
|
zsh-history-substring-search.zsh
|
|
|
|
unfunction _plugin_installed
|
|
|
|
fi
|
|
|
|
if [[ -n ${_my_plugins_dist} ]]; then
|
|
|
|
export ZSH_PLUGIN_DIST="${_my_plugins_dist}" # Arrays can not be exported
|
2022-04-05 15:28:54 +02:00
|
|
|
fi
|
|
|
|
|
2022-04-06 04:07:06 +02:00
|
|
|
[[ -z ${_my_plugins} ]] && return
|
2022-04-05 16:33:38 +02:00
|
|
|
# If there are plugins not handled by the package manager, use antibody
|
2022-04-06 04:07:06 +02:00
|
|
|
if command -v antibody > /dev/null; then
|
2022-04-05 16:33:38 +02:00
|
|
|
zmodload zsh/stat
|
|
|
|
zmodload zsh/datetime
|
2022-04-05 15:28:54 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|