1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-14 19:59:48 +00:00

commit windows init

This commit is contained in:
skywind3000
2018-04-03 03:09:15 +08:00
parent 5a81900e08
commit 7b9486c872

93
z.lua
View File

@@ -945,7 +945,11 @@ function main(argv)
for _, key in ipairs(args) do
opts[key] = 1
end
z_shell_init(opts)
if windows then
z_windows_init(opts)
else
z_shell_init(opts)
end
elseif options['-l'] ~= nil then
local M = z_match(args ~= nil and args or {}, Z_METHOD, Z_SUBDIR)
z_print(M)
@@ -1138,6 +1142,93 @@ function z_shell_init(opts)
end
-----------------------------------------------------------------------
-- windows .cmd script
-----------------------------------------------------------------------
local script_init_cmd = [[
set "MatchType=-n"
set "StrictSub=-n"
set "ListOnly=-n"
set "HelpMode=-n"
set "EchoPath=-n"
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 "ListOnly=-l"
shift /1
goto parse
)
if /i "%1"=="-e" (
set "EchoPath=-e"
shift /1
goto parse
)
if /i "%1"=="-h" (
call "%LuaExe%" "%LuaScript%" -h
shift /1
goto end
)
:check
if /i "%1"=="" (
set "ListOnly=-l"
)
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
if /i "%ListOnly%"=="-n" (
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('call "%LuaExe%" "%LuaScript%" --cd %MatchType% %StrictSub% %*') do set "NewPath=%%i"
if not "!NewPath!"=="" (
if exist !NewPath!\nul (
if /i "%EchoPath%"=="-e" (
echo !NewPath!
)
pushd !NewPath!
pushd !NewPath!
endlocal
popd
)
)
) else (
call "%LuaExe%" "%LuaScript%" -l %MatchType% %StrictSub% %*
)
:end
set "LuaExe="
set "LuaScript="
set "MatchType="
set "StrictSub="
set "NewPath="
set "ListOnly="
set "PWD="
]]
-----------------------------------------------------------------------
-- initialize cmd
-----------------------------------------------------------------------
function z_windows_init(opts)
print('@echo off')
print('set "LuaExe=' .. os.interpreter() .. '"')
print('set "LuaScript=' .. os.scriptname() .. '"')
print(script_init_cmd)
end
-----------------------------------------------------------------------
-- testing case
-----------------------------------------------------------------------