Reading and writing notes with yazi and helix
Originally I thought it was just a few weeks ago, but way back in April the first Linkdump on 82mhz.net, written by the fantastic Andreas, mentioned a bash note-taking, bookmarking, and archiving tool called nb. If you have read any posts on this blog you know I love command line tools and applications.
nb has a lot of features and I was excited to test it out. However, I ran into two issues I couldn’t overcome to fully switch to it.
One, something about how nb works and my brain just didn’t click. I couldn’t get my head wrapped around all of the options for creating notes, tagging, linking, and then syncing with git. There’s nothing wrong with nb, it just doesn’t feel right for me. Two, my phone is also my everyday carry laptop. It is critical I can easily view and access notes from my phone from the devices screen or when connected to my lapdock. Using a terminal application for notes just won’t work on a mobile device.
While testing nb it got me thinking more about my notes workflow and my desire to work as much as I can in the terminal. Since I use Obsidian for my notes, all of the files are markdown files I can open with any application. This means I could come up with a terminal workflow when I’m at my desk and still use the Obsidian app on my phone.
Combining existing tools
At the beginning of the year I started using yazi as my primary file manager in the terminal. Then, I was introduced to helix editor on Mastodon by codemonkeymike. I love these tools and the work awesome together. My thought was I should just use my existing tools to read, write, and edit notes on the command line rather than learning a new tool.
Setting up yazi and helix is simple, just follow the guides in their documentation. First and foremost, I want to use helix as my default editor when browsing files. To do this, I am going to set a variable in the yazi.toml file. If it doesn’t exist, place yazi.toml in /$HOME/.config/yazi. Then add this line:
[opener]
edit = [
{ run = 'hx "$@"', block = true }]
This sets the default editor to use as helix and then will be an option when using shift-o.
In addition to creating and editing notes, at times I just want to view them. I could simply view the raw markdown file, but there’s plenty of tools available for rendering markdown. For this I am using glow. In my yazi config I have set two openers for markdown files, one for editing and one for viewing. I added an open option for Glow and then set a rule to first open markdown files with it. So, when using yazi to browse directories I can hit o and will open with Glow and the shift-o for a list of options, which is when I can select helix. Now the config file looks like this:
[opener]
edit = [
{ run = 'hx "$@"', block = true },
]
open = [
{ run = 'glow "$@"', block = true, desc = "Glow" },
]
[open]
prepend_rules = [
{ name = "*.md", use = ["open", "edit"] },
]
The last little edit here is for glow. When displaying a single file, glow will just print the file in the console. yazi won’t display this (unless I can figure out how to open a new pane). To fix, go edit the pager option in the glow config using glow config and then changing pager to true.
Below is a short video of how it looks.
- - - - -
Did you like this post? Give it an upvote by clicking on the arrows below! Sending me an upvote is like you and I giving each other a high five.
🙏 😎
Thank you for reading! If you would like to comment on this post you can start a conversation on the Fediverse. Message me on Mastodon at @cinimodev@masto.ctms.me. Or, you may email me at blog.discourse904@8alias.com. This is an intentionally masked email address that will be forwarded to the correct inbox.If you enjoy the random stuff I write here, post to Mastodon, or watch on YouTube, and are feeling generous, I am open to tips of Ko-fi.