rethinking aliases
I had an earlier note about using fzf for searching my notes. I keep forgetting the aliases, so I’m going to bundle them with a justfile and create just one alias with a bunch of arguments.
Background
I have my notes in a very shallow hierarchy in a git repository. There is a notes sub directory that contains all of my notes. Everything that is a note is in that notes directory and the file names are based on the time when the file was created.
At the same depth as the notes level, I have a directory that gets generated by a python script when I save a note. That directory contains a bunch of directories full of symbolic links that point into my notes directory. This gives me a tags view, a titles view, and a couple of views of backlinks.
So my notes repository looks like this:
notes (everything)
meta
├── backlinks-files
│ └── …
├── backlinks-titles
│ └── …
├── tags
│ ├── 3ds
│ │ ├── Bought a new 3DS LL (JPN).md -> notes/2023-08-19-09-14-21.md
│ │ └── …
│ ├── asahi
│ │ ├── graphics fail on asahi.md -> notes/2022-03-23-16-58-41.md
│ │ └── NixOS Asahi on MBP.md -> notes/2024-03-21-07-16-54.md
│ ├── atoms
│ │ ├── 1959 to 2008 linoleic acid levels in human subjects.md -> notes/2024-01-12-07-39-17.md
│ │ └── …
│ └── …
└── titles
├── 1959 to 2008 linoleic acid levels in human subjects.md -> notes/2024-01-12-07-39-17.md
├── abook is broken.md -> notes/2022-12-20-20-56-44.md
├── about my notes.md -> notes/2022-12-06-06-18-01.md
├── …
├── 生词:适合.md -> notes/2023-09-09-20-38-40.md
└── 这样.md -> notes/2023-08-24-09-13-10.md
I use a combination of bat and rg whenever I want to search my notes, unless I happen to be in (neo)vim and then I use Telescope – which is backed by rg. I also make use of Neo-Tree and can toggle the preview pane. It makes for a somewhat busy UI, but it’s colorful and I can toggle zen mode to dismiss the frilly bits.
Not that long ago, I was reading the man page for fzf and saw it had all kinds of cool preview features and multi select, and what-not, so I created some aliases for searching my notes. In addition to the previously mentioned utilities, I also made use of bemenu to pop up fuzzy finding menus for searching in my notes by tags or titles. It had some fragile bits because it parsed the tags and titles out of the notes directly, but not in a very standard way. The symbolic links were a first step in replacing elements of that script.
When I saw that fzf could make a very Telescope-like interface, I created aliases to search by tags and titles in there, too. But apparently the aliases are too hard for me to remember.
Also not that long ago, someone pointed me to an article about using a justfile to handle command-line argument parsing to simplify creating command-line helpers. I’ve had trouble finding the link, if I made a note about it, I didn’t tag it. But essentially you create a justfile, stick it somewhere convenient, and create an alias to invoke. Then add targets to that just file that do whatever, and you can use the alias.
First Iteration
So I have created a justfile. I put it in ~/notes-cli/justfile and I have an alias defined:
alias notes='just --justfile /home/stephen/notes-cli/justfile'
Some of the content of that justfile:
##
# Some fun escape sequences for style:
export RED:="\\e[0;31m"
export RST:="\\e[0m"
export BOLD_WHITE:="\\e[1;37m"
export WORKDIR:=invocation_directory()
##
# FZF flags for colors
export FZF_PBG:="#333333"
export FZF_BG:="#222222"
##
# FZF args for great justice!
# of note, -m for multi-select, preview via the bat command, and make the enter
# key call the editor and pass it every selected file.
export FZFARGS:="-m --border --preview \"bat --color=always {}\" --color bg:${FZF_BG},preview-bg:${FZF_PBG} --bind \"enter:become(${EDITOR} {+})\""
##
# Note, if you disable multi-select (-m) in the above, also remove the + in the
# {+} of the ${EDITOR} {+}.
#
# New notes get a name using the date format.
export DATE_FMT:="+%Y-%m-%d-%H-%M-%S"
# Show's (this) help info
help:
#!/usr/bin/env bash
echo -e "${BOLD_WHITE}Notes Helper${RST}"
echo -e "${BOLD_WHITE}============${RST}"
echo "This is a convenience script for making note management fun and easy. Or at least easier."
echo
echo "As long as there is a notes directory in the current directory this script can help with searching and creating new notes."
just --list
##
# Prints error: msg when called with a message and terminates.
[private]
@error msg:
echo -e "${RED}error${RST}: ${BOLD_WHITE}{{msg}}${RST}">&2
exit 1
##
# Checks for a notes directory in the current directory,
# displays a message and exits if one isn't found.
# Anything that needs a notes directory can depend on this.
[private]
check:
#!/usr/bin/env bash
if [ ! -d "${WORKDIR}"/notes ] ; then
just error "This doesn't look like a notes repository."
fi
# List the last few notes that were edited
[no-cd]
@ls: check
ls -lart notes
# List the last few notes that were edited (with fzf!)
[no-cd]
@fls: check
fzf {{FZFARGS}} --walker-root notes
# Search titles with fzf
[no-cd]
@ts: check
fzf {{FZFARGS}} --walker-root meta/titles
# Search tags with fzf
[no-cd]
@tags: check
fzf {{FZFARGS}} --walker-root meta/tags
# Search backlinks with fzf
[no-cd]
@links: check
fzf {{FZFARGS}} --walker-root meta/backlinks-titles
# Creates a new note in a notes directory
@new: check
"${EDITOR}" notes/"$(date "${DATE_FMT}".md)"
Then if I call notes I see the following:
[?2004l
[1;37mNotes Helper[0m
[1;37m============[0m
This is a convenience script for making note management fun and easy. Or at least easier.
As long as there is a notes directory in the current directory this script can help with searching and creating new notes.
Available recipes:
fls [34m#[0m [34mList the last few notes that were edited (with fzf!)[0m
help [34m#[0m [34mShow's (this) help info[0m
links [34m#[0m [34mSearch backlinks with fzf[0m
ls [34m#[0m [34mList the last few notes that were edited[0m
new [34m#[0m [34mCreates a new note in a notes directory[0m
tags [34m#[0m [34mSearch tags with fzf[0m
ts [34m#[0m [34mSearch titles with fzf[0m
If I use the notes ts command I can search for a title. Here’s an image showing a search for the term Enthymeme.
So…
While it seems trivial that I have replaced some aliases with another alias, now I can easily get a reminder for what each alias does. I think it’s a more convenient package. But I guess I’ll find out if I end up using/remembering it. I can also hang scripts off it and use it for other note related stuff. Like common pandoc reformatting or whatever else comes to mind that might be useful when I’m doing other things.
Tags: index, cli
Tags
Navigation
created: 2025-08-08
(re)generated: 2025-11-27