1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-12 02:39:48 +00:00

Make z -i and z -I with no arguments be interactive.

In skywind3000/z.lua#122 there's a note that z.lua intentionally doesn't
support `z -i` being interactive to maintain consistency with how z.sh
behaves with `z -i`.  But z.sh doesn't have a `-i` option, so I'm not
sure what is the intent.

This commit makes `z -i` and `z -I` go interactive even with no args.
This commit is contained in:
Chris Antos
2025-05-15 09:47:19 -07:00
parent c3a182c6c9
commit c524e28851
2 changed files with 21 additions and 17 deletions

4
z.cmd
View File

@@ -89,7 +89,9 @@ if /i "%1"=="--purge" (
:check
if /i "%1"=="" (
set "RunMode=-l"
if /i "%InterMode%"=="" (
set "RunMode=-l"
)
)
for /f "delims=" %%i in ('cd') do set "PWD=%%i"

34
z.lua
View File

@@ -1612,21 +1612,23 @@ function z_cd(patterns)
if patterns == nil then
return nil
end
if #patterns == 0 then
return nil
end
local last = patterns[#patterns]
if last == '~' or last == '~/' then
return os.path.expand('~')
elseif windows and last == '~\\' then
return os.path.expand('~')
end
if os.path.isabs(last) and os.path.isdir(last) then
local size = #patterns
if size <= 1 then
return os.path.norm(last)
elseif last ~= '/' and last ~= '\\' then
return os.path.norm(last)
if Z_INTERACTIVE == 0 then
if #patterns == 0 then
return nil
end
local last = patterns[#patterns]
if last == '~' or last == '~/' then
return os.path.expand('~')
elseif windows and last == '~\\' then
return os.path.expand('~')
end
if os.path.isabs(last) and os.path.isdir(last) then
local size = #patterns
if size <= 1 then
return os.path.norm(last)
elseif last ~= '/' and last ~= '\\' then
return os.path.norm(last)
end
end
end
local M = z_match(patterns, Z_METHOD, Z_SUBDIR)
@@ -1971,7 +1973,7 @@ function main(argv)
end
elseif options['-'] then
path = cd_minus(args, options)
elseif #args == 0 then
elseif #args == 0 and Z_INTERACTIVE == 0 then
path = nil
else
path = z_cd(args)