-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_user.sh
executable file
·40 lines (35 loc) · 918 Bytes
/
git_user.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
#!/bin/bash
# Function to display usage
usage() {
echo "Usage: source $0 -u username -e email"
echo " -u username Specify the Git user name"
echo " -e email Specify the Git user email"
exit 1
}
# Parse options
while getopts ":u:e:" opt; do
case ${opt} in
u )
USER="$OPTARG"
;;
e )
EMAIL="$OPTARG"
;;
\? )
usage
;;
esac
done
shift $((OPTIND -1))
# Check if both username and email are provided
if [ -z "$USER" ] || [ -z "$EMAIL" ]; then
usage
fi
# Set the temporary Git environment variables
export GIT_AUTHOR_NAME="$USER"
export GIT_AUTHOR_EMAIL="$EMAIL"
export GIT_COMMITTER_NAME="$USER"
export GIT_COMMITTER_EMAIL="$EMAIL"
echo "Temporarily set Git user name to: $USER"
echo "Temporarily set Git email to: $EMAIL"
echo "These settings will only last for this terminal session."