Fix fzf preview command when setting --notebook-dir

pull/17/head
Mickaël Menu 3 years ago
parent 52434f8618
commit 695a3bc351
No known key found for this signature in database
GPG Key ID: 53D73664CD359895

@ -57,11 +57,12 @@ func (f *NoteFinder) Find(opts note.FinderOpts) ([]note.Match, error) {
}
for _, match := range matches {
path, err := filepath.Rel(f.opts.CurrentPath, filepath.Join(f.opts.BasePath, match.Path))
absPath := filepath.Join(f.opts.BasePath, match.Path)
relPath, err := filepath.Rel(f.opts.CurrentPath, absPath)
if err != nil {
return selectedMatches, err
}
relPaths = append(relPaths, path)
relPaths = append(relPaths, relPath)
}
zkBin, err := os.Executable()
@ -84,8 +85,15 @@ func (f *NoteFinder) Find(opts note.FinderOpts) ([]note.Match, error) {
})
}
previewCmd := f.opts.PreviewCmd.OrString("cat {-1}").Unwrap()
if previewCmd != "" {
// The note paths will be relative to the current path, so we need to
// move there otherwise the preview command will fail.
previewCmd = `cd "` + f.opts.CurrentPath + `" && ` + previewCmd
}
fzf, err := New(Opts{
PreviewCmd: f.opts.PreviewCmd.OrString("cat {-1}").NonEmpty(),
PreviewCmd: opt.NewNotEmptyString(previewCmd),
Padding: 2,
Bindings: bindings,
})

Loading…
Cancel
Save