forked from giggio/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure-user-env.sh
executable file
·83 lines (75 loc) · 1.55 KB
/
configure-user-env.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
#!/bin/bash
set -euo pipefail
if [ "$EUID" == "0" ]; then
echo "Please do not run this script as root"
exit 2
fi
ALL_ARGS=$@
SHOW_HELP=false
VERBOSE=false
NAME=''
EMAIL=''
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--help|-h)
SHOW_HELP=true
break
;;
--verbose)
VERBOSE=true
shift
;;
-n|--name)
NAME="$2"
shift
shift
;;
-e|--email)
EMAIL="$2"
shift
shift
;;
*)
shift
;;
esac
done
if $SHOW_HELP; then
cat <<EOF
Configures user environment.
Usage:
`readlink -f $0` [flags]
Flags:
-n, --name Name to use when configuring Git.
-e, --email Email to use when configuring Git.
--verbose Show verbose output
-h, --help help
EOF
exit 0
fi
if $VERBOSE; then
echo -e "\e[32mRunning `basename "$0"` $ALL_ARGS\e[0m"
echo Name is $NAME
echo Email is $EMAIL
fi
if [ "$NAME" != "" ]; then
git config --global user.name $NAME
elif [[ `git config --global user.name` == "" ]] || [[ `git config --global user.name` == "placeholder" ]]; then
>&2 echo Name is required.
exit 2
else
if $VERBOSE; then
echo Git name already configured as `git config --global user.name`
fi
fi
if [ "$EMAIL" != "" ]; then
git config --global user.email $EMAIL
elif [[ `git config --global user.email` == "" ]] || [[ `git config --global user.email` == "[email protected]" ]]; then
>&2 echo Email is required.
exit 2
else
if $VERBOSE; then
echo Git email already configured as `git config --global user.email`
fi
fi