xwmx / nb

CLI and local web plain text note‑taking, bookmarking, and archiving with linking, tagging, filtering, search, Git versioning & syncing, Pandoc conversion, + more, in a single portable script.
https://xwmx.github.io/nb
GNU Affero General Public License v3.0
6.45k stars 182 forks source link

Feature request: integration with fzf? #102

Open xingheng opened 3 years ago

xingheng commented 3 years ago

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?

xwmx commented 3 years ago

@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 
asyncanup commented 3 years ago

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!

xwmx commented 3 years ago

@asyncanup That's very cool.

annata83 commented 3 years ago

@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;

Woodham commented 2 years ago

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
}
superiums commented 6 months ago

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

0ion9 commented 3 days ago

Everyone here using nb ls --no-color.. Just use fzf --ansi instead and keep the color. Unless you don't like it, I guess? (fzf output is the same regardless -- stripped of color.)

fzf also recently got support for multi-line items (NUL-separated, use --read0 option) so anyone that would like to have searchable excerpts in the item entries themselves instead of / as well as a preview in the preview pane, that should now be possible.