-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.cmd
156 lines (130 loc) · 3.31 KB
/
init.cmd
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
@echo off
echo "%cmdcmdline%" | find /i " /c " >nul && exit /b
if defined PL_I (
call :clear_variables
) else if exist "%~dp0header.cmd" (
call "%~dp0header.cmd"
)
set PL_DIR=%~dp0
set PL_ARGS=%*
for %%i in (
cd cd. cd..
pushd pushd. pushd..
popd
git
) do (
%SystemRoot%\System32\doskey.exe %%i="%~dp0update.cmd" %%i $*
)
setlocal
for /f "tokens=2 delims=:" %%i in ('%SystemRoot%\System32\chcp.com') do set cp=%%i
%SystemRoot%\System32\mode.com con cp select=65001 >nul
if "%~1" == "" (
call "%~dp0styles.cmd" p default
) else (
call "%~dp0styles.cmd" p %*
)
( endlocal
call :build_prompt "%separator%" "%margin%" "%segments%"
%SystemRoot%\System32\mode.com con cp select=%cp:~1% >nul
)
call "%~dp0update.cmd"
exit /b
:clear_variables () -> PL_I, PL_P[], PL_V[], PL_C[]
for /l %%i in (0,1,%PL_I%) do (
set PL_P[%%i]=
set PL_V[%%i]=
set PL_C[%%i]=
)
set PL_I=
goto :eof
:build_prompt ("separator", "margin", "segments") -> PL_I, PL_P[], PL_V[], PL_C[]
set PL_I=0
set PL_P[0]=
set PL_V[0]=
set PL_C[0]=
for %%i in (%~3) do (
call :build_segment %1 %%i
)
setlocal EnableDelayedExpansion
set "p=!PL_P[%PL_I%]!49m%~1$E[39m%~2"
endlocal & set "PL_P[%PL_I%]=%p%"
goto :eof
:build_segment ("separator", segment) -> PL_I, PL_P[], PL_V[], PL_C[]
setlocal EnableDelayedExpansion
set fore=
set back=
set var=
set cmd=
set text=
for /f "tokens=1,* delims=:" %%i in ("%2") do (
if [%%i] == [%%~i] (
call "%~dp0styles.cmd" s %%i
) else (
set text=%%~i
)
call :color %%j
)
if defined var if defined cmd (
if defined PL_P[%PL_I%] (
set /a PL_I+=1
)
)
set i=%PL_I%
if not defined PL_P[0] (
if defined text (
set "p=$E[38;%fore%;48;%back%m%text%$E[38;%back%;"
) else (
set "p=$E[38;%back%;"
)
) else (
if defined text (
set "p=!PL_P[%i%]!48;%back%m%~1$E[38;%fore%m%text%$E[38;%back%;"
) else (
set "p=!PL_P[%i%]!48;%back%m%~1$E[38;%back%;"
)
)
if defined var if defined cmd (
set /a PL_I+=1
)
( endlocal
set "PL_P[%i%]=%p%"
set "PL_V[%i%]=%var%"
set "PL_C[%i%]=%cmd%"
set PL_I=%PL_I%
)
goto :eof
:color ([value]) -> fore, back
setlocal EnableDelayedExpansion
set value=#%1
if "%value:~3,1%" == "" (
set /a fore=0x0%value:~1,1%
set /a back=0x0%value:~2,1%
goto :color_8bit
)
if "%value:~5,1%" == "" (
set /a fore=232+0%value:~1,2%
set /a back=232+0%value:~3,2%
goto :color_8bit
)
if "%value:~7,1%" == "" (
set /a fore=16 + 36 * 0%value:~1,1% + 6 * 0%value:~2,1% + 0%value:~3,1%
set /a back=16 + 36 * 0%value:~4,1% + 6 * 0%value:~5,1% + 0%value:~6,1%
goto :color_8bit
)
set /a fr=0x0%value:~1,2%
set /a fg=0x0%value:~3,2%
set /a fb=0x0%value:~5,2%
set /a br=0x0%value:~7,2%
set /a bg=0x0%value:~9,2%
set /a bb=0x0%value:~11,2%
( endlocal
set fore=2;%fr%;%fg%;%fb%
set back=2;%br%;%bg%;%bb%
)
goto :eof
:color_8bit
( endlocal
set fore=5;%fore%
set back=5;%back%
)
goto :eof