-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathsetup.sh
More file actions
80 lines (71 loc) · 2.1 KB
/
Copy pathsetup.sh
File metadata and controls
80 lines (71 loc) · 2.1 KB
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
#!/usr/bin/env zsh
function Echo_Color(){
case $1 in
r* | R* )
COLOR='\033[0;31m'
;;
g* | G* )
COLOR='\033[0;32m'
;;
y* | Y* )
COLOR='\033[0;33m'
;;
b* | B* )
COLOR='\033[0;34m'
;;
*)
echo "$COLOR Wrong COLOR keyword!\033[0m"
;;
esac
echo -e "$COLOR$2\033[0m"
}
case $SHELL in
*zsh )
profile=~/.zshrc
logout_profile=~/.zlogout
;;
*bash )
profile=~/.bashrc
logout_profile=~/.bash_logout
;;
* )
Echo_Color r "Unknown shell, need to manually add config on your shell profile!!"
profile='unknown'
logout_profile='unknown'
;;
esac
gitacc_config='# git account switch
source $HOME/.git-acc'
cp ./git-acc.sh ~/.git-acc
if [ "$profile" = "unknown" ]; then
echo 'Paste the information down below to your profile:'
Echo_Color y "$gitacc_config\n"
echo 'Paste the information down below to your profile:'
Echo_Color y "$(cat ./logout.script)\n"
else
if [ "$(grep -xn "$gitacc_config" $profile)" != "" ]; then
Echo_Color g "You have already added git-acc config in $profile !!\nOnly update your git-acc!"
else
printf "\n$gitacc_config\n" >> $profile
echo "$(cat ./logout.script)" >> $logout_profile
fi
# Inject auto-load logic for default account
autoload_marker='# Auto-load default git account'
if [ "$(grep -n "$autoload_marker" $profile)" = "" ]; then
autoload_code='# Auto-load default git account (if set) - skip when agent already active
if [[ "$SSH_AUTH_SOCK" != *agent* ]]; then
if [[ -f $HOME/.gitacc ]] && grep -q '"'"'\[DEFAULT\]'"'"' $HOME/.gitacc 2>/dev/null; then
default_acc=$(grep -A1 '"'"'\[DEFAULT\]'"'"' $HOME/.gitacc | grep '"'"'account'"'"' | cut -d'"'"'='"'"' -f2 | xargs)
if [[ -n "$default_acc" ]]; then
git-acc "$default_acc" 2>/dev/null || true
fi
fi
fi'
printf "\n%s\n" "$autoload_code" >> $profile
fi
fi
if ! [ -f ~/.gitacc ]; then
printf "" >> ~/.gitacc
fi
source $profile
echo "Done!! Now can use! Enjoy~~~"