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

Make FzF options configurable #154

Merged
merged 10 commits into from
Apr 24, 2022
7 changes: 7 additions & 0 deletions internal/adapter/fzf/fzf.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var (
type Opts struct {
// Preview command executed by fzf when hovering a line.
PreviewCmd opt.String
// Optionally preovide additional arguments, taken from the config `fzf-additional-args` property.
AdditionalArgs opt.String
// Amount of space between two non-empty fields.
Padding int
// Delimiter used by fzf between fields.
Expand Down Expand Up @@ -72,6 +74,8 @@ func New(opts Opts) (*Fzf, error) {
opts.Delimiter = "\x01"
}

defaultFzfArgs := strings.Split(os.Getenv("FZF_DEFAULT_OPTS"), " ")

args := []string{
"--delimiter", opts.Delimiter,
"--tiebreak", "begin",
Expand All @@ -88,6 +92,9 @@ func New(opts Opts) (*Fzf, error) {
"--preview-window", "wrap",
}

args = append(defaultFzfArgs, args...)
args = append(args, strings.Split(opts.AdditionalArgs.String(), " ")...)

header := ""
binds := []string{}
for _, binding := range opts.Bindings {
Expand Down
3 changes: 3 additions & 0 deletions internal/adapter/fzf/note_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type NoteFilterOpts struct {
AlwaysFilter bool
// Format for a single line, taken from the config `fzf-line` property.
LineTemplate opt.String
// Optionally preovide additional arguments, taken from the config `fzf-additional-args` property.
AdditionalArgs opt.String
// Preview command to run when selecting a note.
PreviewCmd opt.String
// When non null, a "create new note from query" binding will be added to
Expand Down Expand Up @@ -98,6 +100,7 @@ func (f *NoteFilter) Apply(notes []core.ContextualNote) ([]core.ContextualNote,
previewCmd := f.opts.PreviewCmd.OrString("cat {-1}").Unwrap()

fzf, err := New(Opts{
AdditionalArgs: f.opts.AdditionalArgs,
PreviewCmd: opt.NewNotEmptyString(previewCmd),
Padding: 2,
Bindings: bindings,
Expand Down
1 change: 1 addition & 0 deletions internal/cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (c *Container) CurrentNotebook() (*core.Notebook, error) {
func (c *Container) NewNoteFilter(opts fzf.NoteFilterOpts) *fzf.NoteFilter {
opts.PreviewCmd = c.Config.Tool.FzfPreview
opts.LineTemplate = c.Config.Tool.FzfLine
opts.AdditionalArgs = c.Config.Tool.FzfAdditionalArgs
return fzf.NewNoteFilter(opts, c.FS, c.Terminal, c.TemplateLoader)
}

Expand Down
21 changes: 13 additions & 8 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ type MarkdownConfig struct {

// ToolConfig holds the external tooling configuration.
type ToolConfig struct {
Editor opt.String
Pager opt.String
FzfPreview opt.String
FzfLine opt.String
Editor opt.String
Pager opt.String
FzfPreview opt.String
FzfLine opt.String
FzfAdditionalArgs opt.String
}

// LSPConfig holds the Language Server Protocol configuration.
Expand Down Expand Up @@ -361,6 +362,9 @@ func ParseConfig(content []byte, path string, parentConfig Config) (Config, erro
if tool.FzfLine != nil {
config.Tool.FzfLine = opt.NewNotEmptyString(*tool.FzfLine)
}
if tool.FzfAdditionalArgs != nil {
config.Tool.FzfAdditionalArgs = opt.NewNotEmptyString(*tool.FzfAdditionalArgs)
}

// LSP completion
lspCompl := tomlConf.LSP.Completion
Expand Down Expand Up @@ -500,10 +504,11 @@ type tomlMarkdownConfig struct {
}

type tomlToolConfig struct {
Editor *string
Pager *string
FzfPreview *string `toml:"fzf-preview"`
FzfLine *string `toml:"fzf-line"`
Editor *string
Pager *string
FzfPreview *string `toml:"fzf-preview"`
FzfLine *string `toml:"fzf-line"`
FzfAdditionalArgs *string `toml:"fzf-additional-args"`
}

type tomlLSPConfig struct {
Expand Down