-
Notifications
You must be signed in to change notification settings - Fork 141
/
z.cmd
130 lines (106 loc) · 1.93 KB
/
z.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
@echo off
setlocal EnableDelayedExpansion
set "LuaExe=lua"
set "LuaScript=%~dp0z.lua"
set "MatchType=-n"
set "StrictSub=-n"
set "RunMode=-n"
set "StripMode="
set "InterMode="
if /i not "%_ZL_LUA_EXE%"=="" (
set "LuaExe=%_ZL_LUA_EXE%"
)
:parse
if /i "%1"=="-r" (
set "MatchType=-r"
shift /1
goto parse
)
if /i "%1"=="-t" (
set "MatchType=-t"
shift /1
goto parse
)
if /i "%1"=="-c" (
set "StrictSub=-c"
shift /1
goto parse
)
if /i "%1"=="-l" (
set "RunMode=-l"
shift /1
goto parse
)
if /i "%1"=="-e" (
set "RunMode=-e"
shift /1
goto parse
)
if /i "%1"=="-x" (
set "RunMode=-x"
shift /1
goto parse
)
if /i "%1"=="--add" (
set "RunMode=--add"
shift /1
goto parse
)
if "%1"=="-i" (
set "InterMode=-i"
shift /1
goto parse
)
if "%1"=="-I" (
set "InterMode=-I"
shift /1
goto parse
)
if /i "%1"=="-s" (
set "StripMode=-s"
shift /1
goto parse
)
if /i "%1"=="-h" (
call "%LuaExe%" "%LuaScript%" -h
goto end
)
if /i "%1"=="--purge" (
call "%LuaExe%" "%LuaScript%" --purge
goto end
)
:check
if /i "%1"=="" (
set "RunMode=-l"
)
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
if /i "%RunMode%"=="-n" (
for /f "delims=" %%i in ('call "%LuaExe%" "%LuaScript%" --cd %MatchType% %StrictSub% %InterMode% %*') do set "NewPath=%%i"
if not "!NewPath!"=="" (
if exist !NewPath!\nul (
if /i not "%_ZL_ECHO%"=="" (
echo !NewPath!
)
pushd !NewPath!
pushd !NewPath!
endlocal
goto popdir
)
)
) else (
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
)
goto end
:popdir
rem -- Exploits variable expansion and the pushd stack to set the current
rem -- directory without leaking a pushd.
popd
setlocal
set "NewPath=%CD%"
set "CDCmd=cd /d"
if /i not "%_ZL_CD%"=="" (
set "CDCmd=%_ZL_CD%"
)
endlocal & popd & %CDCmd% "%NewPath%"
:end
echo.