nb icon indicating copy to clipboard operation
nb copied to clipboard

Feature request: integration with fzf?

Open xingheng opened this issue 3 years ago • 6 comments

It would be grateful if fzf integrated when searching, just like rga-fzf.

Or is there any way that could pipe the file result to fzf?

xingheng avatar Mar 10 '21 09:03 xingheng

@xingheng Thanks for the heads up. I'll take a closer look to see what options there are for integration. The following seems to work for filenames:

nb list --no-color --filenames | fzf 

xwmx avatar Mar 19 '21 22:03 xwmx

Here's what I came up with:

nb-list() {
  nb list -t note --no-color | grep '\[\d*\]' |  sed -r 's/\[//' | sed -r 's/\]//' |
  fzf --height 50% \
    --preview "nb show -p {1} | head -n 200 | bat -l md" \
    --bind "alt-j:preview-down,alt-k:preview-up,alt-d:preview-page-down,alt-u:preview-page-up" \
    --preview-window=right:70% |
  cut -d$' ' -f1
}

Now $(nb-list) will open fzf, and return the selected note's id.

I also have a keyboard shortcut for it:

bind '"\C-f\C-f": "$(nb-list)\e\C-e\er"'

Now, I type: nb edit , and then hit ctrl-f twice to pull up the note list with fzf.

Hope it helps!

asyncanup avatar Mar 20 '21 10:03 asyncanup

@asyncanup That's very cool.

xwmx avatar Mar 21 '21 16:03 xwmx

@asyncanup How are you; I try ur method:

nb❯ $(nb-list)

/home/niko/.nbrc: line 37: bind: warning: line editing not enabled

fzf with preview setting opens up but no notes are grab;

annata83 avatar Apr 13 '21 02:04 annata83

I was also looking for an integration like this, for now I've whipped up a small plugin that suites my usage - may be helpful for others.

To use I just so nb fzf which opens a fzf search for titles in the current notebook.

#!/usr/bin/env bash
###############################################################################
# fzf.nb-plugin
#
# FZF Plugin for nb
#
###############################################################################

# Add the new subcommand name with `_subcommands add <name>`.
_subcommands add "fzf"

# Define help and usage text with `_subcommands describe <subcommand> <usage>`.
_subcommands describe "fzf" <<HEREDOC
Usage:
  nb fzf
  Description:
    Search through current notebook using fzf and then edit sepected item.
HEREDOC

_fzf() {
    local note=$(_list -t note --no-color --no-indicator --no-id | fzf-tmux $(echo $FZF_TMUX_OPTS) --header "$(_notebook current --name)" --preview "nb show -p {} | bat -l md" )

    if ! [[ -z "$note" ]]; then
        command nb edit "$note"
    fi
}

Woodham avatar Sep 20 '21 10:09 Woodham

how about scan the dir using rg and fzf ? only call nb to edit while file choosed.

superiums avatar Dec 11 '23 03:12 superiums