Skip to content

Commit c524e28

Browse files
committed
Make z -i and z -I with no arguments be interactive.
In #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.
1 parent c3a182c commit c524e28

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

z.cmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ if /i "%1"=="--purge" (
8989
:check
9090

9191
if /i "%1"=="" (
92-
set "RunMode=-l"
92+
if /i "%InterMode%"=="" (
93+
set "RunMode=-l"
94+
)
9395
)
9496

9597
for /f "delims=" %%i in ('cd') do set "PWD=%%i"

z.lua

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,21 +1612,23 @@ function z_cd(patterns)
16121612
if patterns == nil then
16131613
return nil
16141614
end
1615-
if #patterns == 0 then
1616-
return nil
1617-
end
1618-
local last = patterns[#patterns]
1619-
if last == '~' or last == '~/' then
1620-
return os.path.expand('~')
1621-
elseif windows and last == '~\\' then
1622-
return os.path.expand('~')
1623-
end
1624-
if os.path.isabs(last) and os.path.isdir(last) then
1625-
local size = #patterns
1626-
if size <= 1 then
1627-
return os.path.norm(last)
1628-
elseif last ~= '/' and last ~= '\\' then
1629-
return os.path.norm(last)
1615+
if Z_INTERACTIVE == 0 then
1616+
if #patterns == 0 then
1617+
return nil
1618+
end
1619+
local last = patterns[#patterns]
1620+
if last == '~' or last == '~/' then
1621+
return os.path.expand('~')
1622+
elseif windows and last == '~\\' then
1623+
return os.path.expand('~')
1624+
end
1625+
if os.path.isabs(last) and os.path.isdir(last) then
1626+
local size = #patterns
1627+
if size <= 1 then
1628+
return os.path.norm(last)
1629+
elseif last ~= '/' and last ~= '\\' then
1630+
return os.path.norm(last)
1631+
end
16301632
end
16311633
end
16321634
local M = z_match(patterns, Z_METHOD, Z_SUBDIR)
@@ -1971,7 +1973,7 @@ function main(argv)
19711973
end
19721974
elseif options['-'] then
19731975
path = cd_minus(args, options)
1974-
elseif #args == 0 then
1976+
elseif #args == 0 and Z_INTERACTIVE == 0 then
19751977
path = nil
19761978
else
19771979
path = z_cd(args)

0 commit comments

Comments
 (0)