skywind3000 / skywind3000/z.lua
希望添加当执行 `z foo bar` 其中 `foo` 被记录过,其子目录 `bar` 没有被记录过时也能 `cd` 的功能
Open
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 3.1k
- Forks
- 148
- PR merge metrics
- No merged PRs in 30d
Description
我设想的做法是当 z one two three four 失败后,使用去掉了最后一个 pattern 的 one two three 来匹配,当在数据中匹配到了 one two three ,就在这个路径中找有没有子目录 four ,如果就直接 cd 进入。
效果类似于:
$ grep 'linux/drivers' ~/.zlua # 记录中无 linux/driver
$ grep 'linux' ~/.zlua # 记录中有 linux
/home/xxx/linux|2|1676041029
$ z linux drivers
$ pwd
/home/xxx/linux/drivers
我认为可以添加如下几行实现这个功能:
--- a/z.lua
+++ b/z.lua
@@ -1954,6 +1954,12 @@ function main(argv)
path = os.path.norm(path)
end
end
+ if path == nil then
+ local prefix = table.pack(table.unpack(args, 1, #args - 1))
+ local last = args[#args]
+ path = z_cd(prefix)..os.path.sep..last
+ path = os.path.isdir(path) and path or nil
+ end
end
if path ~= nil then
io.write(path .. (options['-e'] and "\n" or ""))
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in z.lua at main(argv), around the path lookup logic near the mentioned fallback. Reproduce the case where ~/.zlua contains linux but not linux/drivers, then run z linux drivers and verify that it enters the existing child directory when the full pattern lookup fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100