Commit Diff


commit - 678c47e7f9dcabf0bfaa3d3aa8ffd8f619b9e28e
commit + d294179de2c1ba95d8ecac7edb510c2ef8b659e2
blob - 9654e0bb66dcf0077b16444c595ea288a019d167
blob + 0db24b50ba05f1f927ea8f9517cf7abf4ef9f8ac
--- src/fzf.zig
+++ src/fzf.zig
@@ -34,18 +34,22 @@ fn gotoFile(allocator: std.mem.Allocator, db: ?*hist.D
         io.warn("failed to open /dev/tty: {}\n", .{err});
     }
 
+    const parent_dir = std.fs.path.dirname(file_path) orelse ".";
+    const base_name = std.fs.path.basename(file_path);
+    try std.process.setCurrentPath(io.rt(), parent_dir);
+
     if (command) |cmd| {
-        return std.process.replace(io.rt(), .{ .argv = &.{ cmd, file_path } });
+        return std.process.replace(io.rt(), .{ .argv = &.{ cmd, base_name } });
     }
 
     const editor = config.editor orelse (io.getenv("EDITOR") orelse return error.EditorNotSet);
 
     if (line) |l| {
         const line_arg = try std.fmt.allocPrint(allocator, "+{s}", .{l});
-        return std.process.replace(io.rt(), .{ .argv = &.{ editor, line_arg, file_path } });
+        return std.process.replace(io.rt(), .{ .argv = &.{ editor, line_arg, base_name } });
     }
 
-    return std.process.replace(io.rt(), .{ .argv = &.{ editor, file_path } });
+    return std.process.replace(io.rt(), .{ .argv = &.{ editor, base_name } });
 }
 
 const StdIo = std.process.SpawnOptions.StdIo;