From c524e2885151c7dd6bec660f7b6126f3f8a53d30 Mon Sep 17 00:00:00 2001 From: Chris Antos Date: Thu, 15 May 2025 09:47:19 -0700 Subject: [PATCH] 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. --- z.cmd | 4 +++- z.lua | 34 ++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/z.cmd b/z.cmd index f821238..6b0a621 100644 --- a/z.cmd +++ b/z.cmd @@ -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" diff --git a/z.lua b/z.lua index 10afaff..941c66e 100755 --- a/z.lua +++ b/z.lua @@ -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)