This gist describes simply/minimally how to extend the ad editor to use zettelkasten/Denote type notes using just four short bash scripts.
Below is a short description of ad, a couple of demos and the bash scripts needed to:
- create "Denote" notes
- create links to notes
- open notes in ad from the links using ad's loading/plumbing mechanism
- list notes in ad that link back (backlink) to the current one
The bash scripts are included in this README and also as files in the gist for cloning/downloading.
The ad editor is a really interesting new text editor created my @sminez which combines elements of.
- Plan9's Acme editor (https://acme.cat-v.org/)
- modal editing from vi/vim
- noun/verb actions from kakoune
- fuzzy finding ideas from suckless's dmenu
- tree-sitter for code highlighting
- language server protocol integration
It's at an early stage but is already very useable. Indeed this gist was written using ad.
One of the most interesting aspects of ad, taken from Acme, is the use of the 9p protocol to expose the editor as a filesystem. This in effect means that any programming/scripting language or indeed any application can interact with ad using their normal file reading/writing mechanisms. In Rob Cox's excellent screencast on Acme he describes Acme as an "Integrating Development Environment (IDE)" as opposed to the usual "Integrated Development Environment (IDE)" because preexisting applications/tools can be used to extend/adapt Acme through the file system interface. @sminez has adopted this "Integrating" description also for ad and it is this characteristic that is exploited in this short gist.
This short demo shows:
- creating a new Denote note with crnote and opening it
- creating a Denote link "denote:" to a pre-exisitng note using crlink
- opening a Denote note file from a "denote:" link
This demo shows show to create a list of notes that backlink to the current one using adGrep.
In the two demos crnote, crlink and adGrep have been typed into ad to show explicitly how the scripts link to the actions in ad. This can be made much more efficient by binding keys in ad to the script commands. For example in my ad config file located in .ad/bin/config.toml I have
"<space> n" = { run = "crnote" }
"<space> l" = { run = "crlink" }
"<space> g" = { run = "adGrep" }
Executing this script in ad creates a note in the current directory using the Denote file naming scheme incorporating date and time. It should be put in the $HOME/.ad/bin directory and made executable. To use: execute crnote and answer the questions about what the note title should be and what the keywords should be. The note filename will be printed to the screen and right clicking on the name will open the new note in ad - see "Demo 1" above.
#!/usr/bin/env bash
. "$HOME/.ad/lib/ad.sh"
requireAd
tname="$(minibufferPrompt 'What is the note title?: ')"
kname="$(minibufferPrompt 'Which keywords/filetags?: ')"
# title in filename
ftname=$(echo $tname | sed 's/ /-/g')
# keywords/filetags
fkname=$(echo $kname | sed 's/ /_/g')
tags=$(echo $kname | sed 's/ /", "/g;s/^/["/;s/$/"]/')
# get dates:
# to create the identifier (dtid)
# for the note header (dt)
dtid=$(date '+%Y%m%dT%H%M%S')
dthd=$(date '+%Y-%m-%d %a %H:%M')
# create the full note filename and print out to screen
fname=$dtid"--"$ftname"__"$fkname".md"
echo $fname
# create the note header as per denote and write
# out to note filename
echo '---
title: "'$tname'"
date: ['$dthd']
tags: ' $tags '
identifier: "'$dtid'"
---' > $fname
Cut and paste the date/time ID of the note that you want to link to and execute the crlink script in ad - see "Demo 1" above. crlink should be put in the $HOME/.ad/bin directory and made executable.
#!/usr/bin/env bash
. "$HOME/.ad/lib/ad.sh"
requireAd
nid=$(bufRead "$bufid" dot)
ntitle=$(echo $(ls $nid*) | sed 's/.*--//;s/__.*//;s/-/ /g')
link=$(echo '['$ntitle'](denote:'$nid')')
echo $link | bufWrite "$bufid" dot
This uses ad's Loading mechanism (right mouse click) which is based on Plan9's plumber. Highlight the link that you want to open and right mouse click which will open the note in ad - see "Demo 1" above.
A couple of lines need to be added to ad's plumbing rules script. Which should be located in $HOME/.ad/plumbing.rules
# open denote file
data matches ^[0-9]{8}[T][0-9]{6}.+
plumb to edit
# denote links
data matches ^[d][e][n][o][t][e][:][0-9]{8}[T][0-9]{6}
plumb start plink $0
In addition the "plink" bash script below should be put somewhere in the execution PATH ($PATH) and made executable so that the ad-plumber can run it from ad.
#!/usr/bin/env bash
filename=$(ls $(echo -n $1 | sed 's/.*://')*)
echo -n open-in-new-window "$filename" | ad -9p write ad/ctl
In Zettelkasten it is important to be able to see which notes link (backlink) to the current one as well as which notes this current note links to.
Highlight the date/time ID of the current note in the file header and execute the adGrep script - see "Demo 2" above. The adGrep script should be put in the $HOME/.ad/bin directory and made executable.
#!/usr/bin/env bash
. "$HOME/.ad/lib/ad.sh"
requireAd
id=$(bufRead "$bufid" dot)
grep $id *