-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathinstaller.zsh
145 lines (125 loc) · 3.23 KB
/
installer.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/zsh
# Release some autoloads
autoload -Uz colors; colors
autoload -Uz is-at-least; is-at-least
typeset TMPFILE="/tmp/.zplug-$$$RANDOM"
if [[ -z $ZSH_VERSION ]]; then
printf "zplug requires zsh 4.1.9 or newer\n"
exit 1
fi
if [[ -z $ZPLUG_HOME ]]; then
export ZPLUG_HOME=~/.zplug
fi
spin()
{
local \
before_msg="$1" \
after_msg="$2"
local spinner
local -a spinners
spinners=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
# hide cursor
tput civis
while true
do
for spinner in "${spinners[@]}"
do
if [[ -f $TMPFILE ]]; then
rm -f $TMPFILE
tput cnorm
return 1
fi
sleep 0.05
printf " $fg[white]$spinner$reset_color $before_msg\r" 2>/dev/null
done
echo "$jobstates" \
| awk '
/[0-9]+=/ {
jobs[++job_count] = $0
}
END {
for (i = 1; i <= job_count; i++) {
print(jobs[i])
}
exit job_count == 0
}' \
| xargs test -z && break
done
if [[ -n $after_msg ]]; then
printf "\033[2K"
printf " $fg_bold[blue]\U2714$reset_color $after_msg\n"
fi 2>/dev/null
# show cursor
tput cnorm || true
}
execute()
{
local arg title error
local -a args errors
while (( $# > 0 ))
do
case "$1" in
--title)
title="$2"
shift
;;
--error)
errors+=( "$2" )
shift
;;
-*|--*)
return 1
;;
*)
args+=( "$1" )
;;
esac
shift
done
{
for arg in "${args[@]}"
do
${~${=arg}} &>/dev/null
# When an error causes
if [[ $status -ne 0 ]]; then
# error mssages
printf "\033[2K" 2>/dev/null
printf \
" $fg[yellow]\U26A0$reset_color $title [$fg[red]FAILED$reset_color]\n" \
2>/dev/null
printf "$status\n" >"$TMPFILE"
# additional error messages
if (( $#errors > 0 )); then
for error in "${errors[@]}"
do
printf " -> $error\n" 2>/dev/null
done
fi
fi
done
} &
spin \
"$title" \
"$title [$fg[green]SUCCEEDED$reset_color]"
if [[ $status -ne 0 ]]; then
printf "\033[2K" 2>/dev/null
printf "Oops \U2620 ... Try again!\n" 2>/dev/null
exit 1
fi
}
execute \
--title \
"Checking if your zsh version is newer than 4.1.9" \
"sleep 1" \
"is-at-least 4.1.9"
execute \
--title \
"Installing zplug to $ZPLUG_HOME" \
--error \
"Is git installed?" \
--error \
"Does '$ZPLUG_HOME' already exist?" \
"git clone https://github.com/zplug/zplug.git $ZPLUG_HOME"
printf " All processes are successfully completed \U1F389\n"
printf " For more information, see ${(%):-%U}http://zplug.sh${(%):-%u} \U1F33A\n"
printf " Enjoy zplug!\n"