Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: visually show if plugins need to be updated #131

Merged
merged 9 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions install.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ main() {
local ZAP_DIR="$HOME/.local/share/zap"
local ZSHRC="${ZDOTDIR:-$HOME}/.zshrc"

# check if ZAP_DIR already exists
[[ -d "$ZAP_DIR" ]] && {
echo "Zap is already installed in '$ZAP_DIR'!"
read -q "res?Reinstall Zap? [y/N] "
echo ""
[[ $res == "n" ]] && {
echo "❕ skipped!"
return
}
echo "Reinstalling Zap..."
rm -rf "$ZAP_DIR"
}

# Check if the current .zshrc file exists
if [ -f "$ZSHRC" ]; then
# Move the current .zshrc file to the new filename
Expand All @@ -31,19 +44,6 @@ main() {

[[ $1 == "--branch" || $1 == "-b" && -n $2 ]] && local BRANCH="$2"

# check if ZAP_DIR already exists
[[ -d "$ZAP_DIR" ]] && {
echo "Zap is already installed in '$ZAP_DIR'!"
read -q "res?Reinstall Zap? [y/N] "
echo ""
[[ $res == "n" ]] && {
echo "❕ skipped!"
return
}
echo "Reinstalling Zap..."
rm -rf "$ZAP_DIR"
}

git clone --depth 1 -b "${BRANCH:-master}" https://github.com/zap-zsh/zap.git "$ZAP_DIR" > /dev/null 2>&1 || { echo "❌ Failed to install Zap" && return 2 }

echo " Zapped"
Expand All @@ -54,6 +54,6 @@ main() {

main $@

[[ $? -eq 0 ]] && exec zsh || return
[[ $? -eq 0 ]] && source "$ZSHRC" || return

# vim: ft=zsh ts=4 et
28 changes: 24 additions & 4 deletions zap.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,39 @@ function _zap_list() {
}

function _zap_update() {
local _plugin _plug
echo "⚡ Zap - Update\n\n 0 ⚡ Zap"

local _plugin _plug _status

function _check() {
git -C "$1" remote update &> /dev/null
case $(LANG=en_US git -C "$1" status -uno | grep -Eo '(ahead|behind|up to date)') in
ahead)
_status='\033[1;34mLocal ahead remote\033[0m' ;;
behind)
_status='\033[1;33mOut of date\033[0m' ;;
'up to date')
_status='\033[1;32mUp to date\033[0m' ;;
*)
_status='\033[1;31mDiverged state\033[0m' ;;
esac
}

echo "⚡ Zap - Update\n"
_check "$ZAP_DIR"
printf ' 0 ⚡ Zap (%b)\n' "$_status"
for _plugin in ${ZAP_INSTALLED_PLUGINS[@]}; do
printf '%4s 🔌 %s\n' $ZAP_INSTALLED_PLUGINS[(Ie)$_plugin] $_plugin
_check "$ZAP_PLUGIN_DIR/$_plugin"
printf '%4s 🔌 %s (%b)\n' $ZAP_INSTALLED_PLUGINS[(Ie)$_plugin] $_plugin $_status
done
echo -n "\n🔌 Plugin Number | (a) All Plugins | (0) ⚡ Zap Itself: " && read _plugin
echo -n "\n 🔌 Plugin Number | (0) ⚡ Zap Itself | (a) All Plugins | (⏎) Abort: " && read _plugin
case $_plugin in
[[:digit:]]*)
[[ $_plugin -gt ${#ZAP_INSTALLED_PLUGINS[@]} ]] && { echo "❌ Invalid option" && return 1 }
[[ $_plugin -eq 0 ]] && {
git -C "$ZAP_DIR" pull &> /dev/null && { echo -e "\e[1A\e[K⚡ Zap updated!"; return 0 } || { echo -e "\e[1A\e[K❌ Failed to pull"; return 14 }
} || { _pull "$ZAP_PLUGIN_DIR/$ZAP_INSTALLED_PLUGINS[$_plugin]" } ;;
'a'|'A')
echo "\nUpdating All Plugins\n"
for _plug in ${ZAP_INSTALLED_PLUGINS[@]}; do
_pull "$ZAP_PLUGIN_DIR/$_plug"
done ;;
Expand Down