-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·89 lines (67 loc) · 2.22 KB
/
install.sh
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
#!/usr/bin/env bash
if [ "$EUID" -ne 0 ]; then
echo -e "\033[0;31mError\033[0m: You don't have permission. Please run with sudo."
exit 1
fi
spinner() {
local task_name="$1"
local task_function="$2"
local pid
local spin=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
local temp_file=$(mktemp)
local GREEN='\033[0;32m'
local RED='\033[0;31m'
local NC='\033[0m'
tput civis
$task_function > "$temp_file" 2>&1 &
pid=$!
local term_width=$(tput cols)
local max_task_width=$((term_width - 10))
if [ ${#task_name} -gt $max_task_width ]; then
task_name="${task_name:0:$((max_task_width-3))}..."
fi
printf "%-*s" "$max_task_width" "$task_name"
local i=0
while kill -0 $pid 2>/dev/null; do
printf "\r%-*s[%s]" "$max_task_width" "$task_name" "${spin[i]}"
i=$(( (i+1) % ${#spin[@]} ))
sleep 0.2
done
wait $pid
local status=$?
if [ $status -eq 0 ]; then
printf "\r%-*s[${GREEN}✓${NC}]\n" "$max_task_width" "$task_name"
else
printf "\r%-*s[${RED}✗${NC}]\n" "$max_task_width" "$task_name"
local error_message=$(cat "$temp_file")
if [ -n "$error_message" ]; then
echo -e "${RED}Error:${NC} $error_message"
else
echo -e "${RED}Error:${NC} An unknown error occurred."
fi
fi
rm "$temp_file"
return $status
}
trap 'tput cnorm' EXIT
installing() {
local completion_content
local output_dir
if command -v curl &>/dev/null; then
completion_content=$(curl -s https://raw.githubusercontent.com/Watchdog0x/goComplete/main/go-completion.sh)
else
completion_content=$(wget -qO- https://raw.githubusercontent.com/Watchdog0x/goComplete/main/go-completion.sh)
fi
if [ -d "/usr/share/bash-completion/completions" ]; then
output_dir="/usr/share/bash-completion/completions"
else
output_dir="/etc/bash_completion.d"
fi
echo "$completion_content" > "$output_dir/go"
chmod +x "$output_dir/go"
}
main() {
spinner "Installing Go Bash Completion" installing
printf "\nInstallation completed successfully!\nOpen a new terminal\n"
}
main