kevins8
11/20/2021, 5:05 AMbenhsm | Jack of N trades
11/20/2021, 5:07 AMicedwater
11/20/2021, 5:43 AMmkdir $dirname && dendron workspace init --wsRoot $dirname
dendron note lookup --query $notename
works but it also spits a lot of json at you hahabenhsm | Jack of N trades
11/20/2021, 6:18 AMicedwater
11/20/2021, 6:25 AM--quiet
is, hehbenhsm | Jack of N trades
11/20/2021, 6:46 AMsh
#!/bin/sh
# Looks up a Dendron note and opens it in an editor
# Dependencies:
# fzf, fd, bat dendron-cli
# fd and bat could have just been find and cat
#
# Required env variables:
# DENDRON_DIR -> Set to workspace root directory
# DENDRON_VAULT -> Set this to the vault you want to use
# Usage: if a note exists, select it from the fzf prompt with 'enter' to view/edit it.
# if the note doesn't exist, use the binding 'ctrl-l' to create a new note with that name
cd "$DENDRON_VAULT" || exit
NOTE="${1:-$(fd --exclude assets --exclude ./*.yml | sed -E 's/\.[^.]*$//' | fzf --height 90% --margin 5% --layout=reverse --border --bind ctrl-l:print-query --preview='bat --terminal-width 70 --wrap=auto --style numbers,changes --color=always {}.md')}"
if test -z "$NOTE"; then
# printf "\nNo input. Doing nothing.\n"
exit;
fi;
if test -f "$NOTE.md"; then
exec $EDITOR "${NOTE}.md" || echo "There was a problem"
else
dendron note lookup --quiet --wsRoot "$DENDRON_DIR" --query "$NOTE" && exec "$EDITOR" + "${NOTE}.md" || echo "There was a problem"
fi
clear
zsh
lookup-note() {
lookup
zle reset-prompt
# see: https://stackoverflow.com/questions/9212508/how-to-redraw-the-zsh-prompt-after-widget-action
}
zle -N lookup-note
bindkey -v '^L' lookup-note
where '^L' is the literal for . So hitting that keybind brings up fzf in my terminal with the notes in my vault and a previewicedwater
11/20/2021, 6:52 AMbenhsm | Jack of N trades
11/20/2021, 6:53 AMicedwater
11/20/2021, 6:59 AMbenhsm | Jack of N trades
11/20/2021, 7:01 AMvim
" Dendron config
" see: https://damien.pobel.fr/post/configure-neovim-vim-gf-javascript-import/
augroup dendron
autocmd!
au BufReadPost $DENDRON_VAULT* setlocal path+=$DENDRON_VAULT
au BufReadPost $DENDRON_VAULT* setlocal suffixesadd=.md
au BufReadPost $DENDRON_VAULT* lcd $DENDRON_VAULT
augroup END
function! LookupHandler(note) abort
let fullpath = $DENDRON_VAULT . '/' . a:note . ".md"
if filereadable(fullpath)
execute "edit " . fullpath
else
execute '!dendron note lookup --quiet --wsRoot "$DENDRON_DIR" --query ' . a:note
execute "edit " . fullpath
endif
endfunction
function! FzfLookUp()
cd $DENDRON_VAULT
let options = ['--layout=reverse', '--info=inline', '--preview', 'bat --wrap=auto --style numbers,changes --color=always {}.md', '--bind', 'ctrl-l:print-query']
let window = {'width': 0.9, 'height': 0.9}
call fzf#run({'source': 'fd --exclude assets --exclude ./*.yml | sed -E "s/\.[^.]*$//"', 'sink': funcref('LookupHandler'), 'window': window, 'options': options})
cd -
endfunction
function! DendronSearch(term)
cd $DENDRON_VAULT
let options = ['--layout=reverse', '--info=inline', '--preview', 'bat --wrap=auto --style numbers,changes --color=always {}.md', '--bind', 'ctrl-l:print-query']
let window = {'width': 0.9, 'height': 0.9}
call fzf#run({'source': 'rg --files-with-matches --smart-case ' . a:term . ' | sed -E "s/\.[^.]*$//"', 'sink': funcref('LookupHandler'), 'window': window, 'options': options})
cd -
endfunction
command! -nargs=1 Search call DendronSearch("<args>")
gf
also filename omnicompletion, though I haven't yet figured out how to chop off the file extension in the completed text--output
option to get it to spit out markdownfd
command is swapped out with a ripgrep command:
zsh
rg --files-with-matches --smart-case "$@"
sh
#!/bin/sh
# Queries a Dendron journal note and opens it in an editor
# If called with an argument, makes a journal note in that domain
# If called with no argument, makes a journal note in the 'daily' domain
JOURNAL_ROOT="${1-daily}"
JOURNAL_NOTE="$JOURNAL_ROOT.journal.$(date +%Y.%m.%d)"
if test -f "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"; then
if test "$EDITOR" = "nvim" || test "$EDITOR" = "vim"; then
exec "$EDITOR" + "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"
else
exec "$EDITOR" "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"
fi
fi
dendron note lookup --wsRoot "$DENDRON_DIR" --query "$JOURNAL_NOTE" --quiet && exec $EDITOR "${DENDRON_VAULT}/${JOURNAL_NOTE}.md"
sh
#!/bin/sh
# Opens a random Dendron note
cd "$DENDRON_VAULT" || exit
nvim -c "call TogglePager()" "$(fd --exclude assets --exclude ./*.yml | shuf | head -n 1)"
icedwater
11/20/2021, 8:00 AMbenhsm | Jack of N trades
11/20/2021, 2:12 PMicedwater
11/20/2021, 2:52 PMbenhsm | Jack of N trades
11/20/2021, 3:28 PMicedwater
11/20/2021, 4:07 PMbenhsm | Jack of N trades
11/20/2021, 4:14 PM:! [...]
icedwater
11/25/2021, 5:31 PMbenhsm | Jack of N trades
11/25/2021, 5:35 PMicedwater
11/30/2021, 3:59 AMbenhsm | Jack of N trades
11/30/2021, 10:45 AMicedwater
11/30/2021, 12:58 PMkevins8
11/30/2021, 4:06 PMmandarvaze
12/11/2021, 5:17 AM.app
which is a directory, not a binary - so while macOS/finder understands them, terminal does not "execute" it - it can cd
into it.
Any suggestions ?
In the mean time, I'm OK w/ nvim binary, which is not a GUI. so it is OK.benhsm | Jack of N trades
12/11/2021, 12:30 PMfudo
02/27/2022, 4:33 PM.app
into a folder that loads your bin into your pathopen
command wich takes the {application}.app
name / path and executes as if you double clicked on it