Skip to content

Instantly share code, notes, and snippets.

@knuton
Last active July 29, 2021 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knuton/364a2a73bc0e0319ae14fab389fcdbba to your computer and use it in GitHub Desktop.
Save knuton/364a2a73bc0e0319ae14fab389fcdbba to your computer and use it in GitHub Desktop.
Notational Velocity/nvALT approximation using fzf, ripgrep and awk
# Bash function to approximate Notational Velocity using fzf and ripgrep.
#
# Will search for and preview matching files based on name and content, then open with $EDITOR on enter.
# Assumes Markdown files.
#
# Based on
# - https://demu.red/blog/2021/04/a-notational-velocity-stopgap-solution-for-linux/
# - https://github.com/junegunn/fzf#3-interactive-ripgrep-integration
function note() {
pushd ~/notes 1>/dev/null && \
INITIAL_QUERY=""
RG_CMD="rg --no-column --no-line-number --no-heading --color=always --smart-case "
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
MATCH=$(fzf --bind "change:reload:rg --files | $RG_CMD {q}; $RG_CMD {q} || true" \
--ansi --disabled --query "$INITIAL_QUERY" \
--layout=reverse --cycle \
--preview-window=down --preview='cat $(echo {} | cut -d : -f 1)' \
--print-query)
if [ "$MATCH" != "" ]; then
NOTE_NAME=$(echo "$MATCH" \
| cut -d : -f 1 \
| gawk 'END{if($0 !~ /.md$/){$0=gensub(" ","_","g",$0) ".md"}; print $0}')
$EDITOR "$NOTE_NAME"
fi
popd 1>/dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment