Skip to content

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

Open
@vaaandark

Description

@vaaandark

我设想的做法是当 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 ""))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions