nb
nb copied to clipboard
Feature request: integration with fzf?
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 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
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 That's very cool.
@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;
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
}
how about scan the dir using rg and fzf ? only call nb to edit while file choosed.