Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望添加当执行 z foo bar 其中 foo 被记录过,其子目录 bar 没有被记录过时也能 cd 的功能 #175

Open
vaaandark opened this issue Feb 10, 2023 · 2 comments

Comments

@vaaandark
Copy link

我设想的做法是当 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 ""))
@vaaandark
Copy link
Author

更正一下自己的实现,应该用 if path == nil and #args > 1 then

@skywind3000
Copy link
Owner

OK 回头我看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants