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

6 Commits

Author SHA1 Message Date
skywind3000
23aeabedd9 update version number 2025-05-18 00:18:33 +08:00
Linwei
27dceb9899 Merge pull request #219 from chrisant996/allow_interactive_with_no_args
Fix when _ZL_MATCH_MODE=1.
2025-05-18 00:16:39 +08:00
Chris Antos
19b2d1747e Fix when _ZL_MATCH_MODE=1. 2025-05-17 04:29:40 -07:00
skywind3000
7c1c73af33 1. upgrade internal batch script
2. made _ZL_FZF_HEIGHT available on windows.
2025-05-17 13:57:37 +08:00
Linwei
b63a38b11a Merge pull request #218 from chrisant996/allow_interactive_with_no_args
Make `z -i` and `z -I` with no arguments be interactive.
2025-05-16 15:12:21 +08:00
Chris Antos
c524e28851 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.
2025-05-15 09:47:19 -07:00
2 changed files with 30 additions and 24 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"

50
z.lua
View File

@@ -4,7 +4,7 @@
-- z.lua - a cd command that learns, by skywind 2018-2022
-- Licensed under MIT license.
--
-- Version 1.8.18, Last Modified: 2024/04/30 17:11
-- Version 1.8.23, Last Modified: 2025/05/18 00:18:20
--
-- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -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)
@@ -1668,12 +1670,12 @@ function z_cd(patterns)
local flag = os.environ('_ZL_FZF_FLAG', '')
flag = (flag == '' or flag == nil) and '+s -e' or flag
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
if height ~= nil and height ~= '' and height ~= '0' then
cmd = cmd .. ' --height ' .. height
end
if not windows then
tmpname = os.tmpname()
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
if height ~= nil and height ~= '' and height ~= '0' then
cmd = cmd .. ' --height ' .. height
end
cmd = cmd .. ' < "' .. tmpname .. '"'
else
tmpname = os.tmpname():gsub('[\\:]', ''):gsub('%.', '')
@@ -1971,13 +1973,13 @@ 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)
if path == nil and Z_MATCHMODE ~= 0 then
local last = args[#args]
if os.path.isdir(last) then
if last and os.path.isdir(last) then
path = os.path.abspath(last)
path = os.path.norm(path)
end
@@ -2653,7 +2655,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"
if /i "%RunMode%"=="-n" (