-
Notifications
You must be signed in to change notification settings - Fork 1
/
ohmyzsh-full-autoupdate.plugin.zsh
130 lines (118 loc) · 4.83 KB
/
ohmyzsh-full-autoupdate.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# File: ohmyzsh-full-autoupdate.plugin.zsh
#
# Name: Oh My Zsh full-autoupdate
# Description: Plugin for Oh My ZSH that automatically updates your custom plugins and themes.
#
# Author: Pilaton
# GitHub: https://github.com/Pilaton/MacSync
# Bugs: https://github.com/Pilaton/MacSync/issues
# License: MIT
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#######################################
# If our label exists in the file "${ZSH_CACHE_DIR}/.zsh-update", skip updating plugins and themes
#######################################
if [[ $(grep "LABEL_FULL_AUTOUPDATE" "${ZSH_CACHE_DIR}/.zsh-update") ]]; then
return
fi
#######################################
# Set colors if "tput" is present in the system
#######################################
if [[ -n $(command -v tput) ]]; then
bold=$(tput bold)
colorGreen=$(tput setaf 2)
colorYellow=$(tput setaf 3)
colorBlue=$(tput setaf 4)
reset=$(tput sgr0)
fi
#######################################
# Welcome screen
#######################################
rainbow=(
"$(printf '\033[38;5;196m')"
"$(printf '\033[38;5;202m')"
"$(printf '\033[38;5;226m')"
"$(printf '\033[38;5;082m')"
"$(printf '\033[38;5;021m')"
"$(printf '\033[38;5;093m')"
"$(printf '\033[38;5;163m')"
)
threeColours=(
"$(printf '\033[38;5;226m')"
"$(printf '\033[38;5;082m')"
"$(printf '\033[38;5;163m')"
)
resetPrintf=$(printf '\033[0m')
printf '%s %s__ %s %s %s %s %s__ %s \n' $rainbow $resetPrintf
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s \n' $rainbow $resetPrintf
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s \n' $rainbow $resetPrintf
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s \n' $rainbow $resetPrintf
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s \n' $rainbow $resetPrintf
printf '%s %s %s %s /____/ %s %s %s %s \n' $rainbow $resetPrintf
printf ''
printf '%s ____ ____ %s __ %s __ __ %s \n' $threeColours $resetPrintf
printf '%s / __/_ __/ / / %s____ ___ __/ /_____%s __ ______ ____/ /___ _/ /____%s \n' $threeColours $resetPrintf
printf '%s / /_/ / / / / /____%s/ __ `/ / / / __/ __ \%s/ / / / __ \/ __ / __ `/ __/ _ \%s \n' $threeColours $resetPrintf
printf '%s / __/ /_/ / / /____%s/ /_/ / /_/ / /_/ /_/ /%s /_/ / /_/ / /_/ / /_/ / /_/ __/%s \n' $threeColours $resetPrintf
printf '%s/_/ \__,_/_/_/ %s\__,_/\__,_/\__/\____/%s\__,_/ .___/\__,_/\__,_/\__/\___/%s \n' $threeColours $resetPrintf
printf '%s %s %s /_/ %s \n' $threeColours $resetPrintf
printf '\n'
printf "${bold}Updating plugins and themes Oh My ZSH${reset}\n"
printf "${colorYellow}--------------------------------------${reset}\n"
printf '\n'
#######################################
# Getting url for a package on the GitHub website.
# Arguments:
# [text...] Path to the .git folder in the local package directory
# Outputs:
# [text...] Url
#######################################
_getUrlGithub() {
local url=$(grep 'url =' "$1/config" | grep -o 'https://\S*' | sed 's/\.git//')
echo $url
}
#######################################
# Defining the plugin category and getting the category name.
# Arguments:
# [text...] Path to local package folder
# Outputs:
# [text...] Name category
#######################################
_getNameCustomCategory() {
local path=$1
case $path in
*"plugins"*) echo "Plugin" ;;
*"themes"*) echo "Theme" ;;
esac
}
#######################################
# Saving a label that determines if plugins need to be updated.
# Globals:
# ZSH_CACHE_DIR
#######################################
_savingLabel() {
echo "\nLABEL_FULL_AUTOUPDATE=true" >> "${ZSH_CACHE_DIR}/.zsh-update"
}
#######################################
# We get a list of available plugins and update them.
# Globals:
# ZSH_CUSTOM
#######################################
omzFullUpdate() {
local arrayPackages=($(find -L "${ZSH_CUSTOM}" -type d -name ".git"))
for package in ${arrayPackages[@]}; do
local urlGithub=$(_getUrlGithub "$package")
local nameCustomCategory=$(_getNameCustomCategory "$package")
local packageDir=$(dirname "$package")
local packageName=$(basename "$packageDir")
printf '%sUpdating %s — %s -> %s\n' "$colorYellow" "$nameCustomCategory" "$colorGreen$packageName$reset" "$colorBlue$urlGithub$reset"
if ! git -C "$packageDir" pull; then
printf '%sError updating %s%s\n' "$colorRed" "$packageName" "$reset"
fi
printf '\n'
done
_savingLabel
}
omzFullUpdate