-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.bat
159 lines (130 loc) · 3.97 KB
/
main.bat
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
::-------------------------------------------------------------
:: Change the git user.name and user.email
:: Reset the user's git password from a ~/.gitcredential file
:: weaponsforge;20191026
::-------------------------------------------------------------
@echo off
GOTO Main
:: Display the main menu
:Main
:: Clear the input variables
set "gitusername="
set "email="
set "doreset="
set "findstring="
set /A choice=1
set /A gitrepository=4
:: Set git credentials file paths
set gitcredentials=C:\Users\%username%\.gitcredential
set newcredentials=C:\Users\%username%\.gitcredentialnew
:: Delete temporary file
if exist %newcredentials% (
del /f %newcredentials%
)
cls
echo ----------------------------------------------------------
echo VIEWING GIT SWITCHER OPTIONS
echo ----------------------------------------------------------
echo [1] View git user config
echo [2] Edit git user config
echo [3] Exit
set /p choice="Select option:"
(if %choice% EQU 1 (
GOTO ViewUserConfig
) else if %choice% EQU 2 (
GOTO SetUserConfig
) else if %choice% EQU 3 (
EXIT /B 0
))
EXIT /B 0
:: Prompt for git config username and email
:SetUserConfig
cls
echo ----------------------------------------------------------
echo EDIT GIT USER CONFIG DETAILS
echo ----------------------------------------------------------
set /p gitusername="Enter git user.name:"
git config --global user.name %gitusername%
set /p email="Enter git user.email:"
git config --global user.email %email%
echo Updated git user config...
set /p doreset=Would you like to reset the password? [Y/n]:
echo.%doreset% | findstr /C:"Y">nul && (
GOTO ResetPassword
) || (
GOTO Main
)
EXIT /B 0
:: Display the current git user config
:ViewUserConfig
cls
echo ----------------------------------------------------------
echo GIT USER CONFIG DETAILS (global)
echo ----------------------------------------------------------
echo|set /p=Username:
git config --get user.name
echo|set /p=Email:
git config --get user.email
set /p choice=Press Enter to continue...
GOTO Main
EXIT /B 0
:: Delete the password for the newly-set git user so it will be
:: prompted on the next git operation
:ResetPassword
echo Which Git account password would you like to reset?
echo [1] Github
echo [2] Gitlab
echo [3] BitBucket
echo [4] Exit
set /p gitrepository="Select option:"
(if %gitrepository% EQU 1 (
) else if %gitrepository% EQU 2 (
) else if %gitrepository% EQU 3 (
) else (
GOTO Main
))
if exist %gitcredentials% (
echo | findstr /C:%findstring% %gitcredentials% > nul && (
:: Copy all git credentials to temp file excluding the user to reset
type %gitcredentials% | findstr /v %findstring% >> %newcredentials%
:: Overwrite current git credentials to delete (reset) the new git config user's password
type %newcredentials% > %gitcredentials%
)
GOTO ExitResetPassword
) else (
echo %gitcredentials% was not found.
echo Make sure your windows User path is correct and the file exists, then try again.
echo Read on the Usage instructions for more information.
GOTO ProcessError
)
EXIT /B 0
:: Exit from the git reset password
:ExitResetPassword
:: Delete temporary git credentials file
if exist %newcredentials% (
del /f %newcredentials% && (
echo Git user's %findstring% password has been reset.
GOTO ProcessError
) || (
echo Failed deleting temporary file.
echo Close this program and run again.
GOTO ProcessExit
)
) else (
echo Password for user %gitusername% on %findstring% was not found.
echo Nothing to reset.
GOTO ProcessError
)
EXIT /B 0
:: Process warning messages
:ProcessError
set /p choice=Press Enter to continue...
GOTO Main
EXIT /B 0
:: Exit for critical errors
:ProcessExit
set /p choice=Press Enter to continue...
EXIT /B 0