/ Analogpixel / blog

My Alfred Workflows

May 21, 2020

Snippets

Every editor has one or more way to handle code snippets. Every OS has a handfull of programs to handle code snippets, so in the vein of this, I decided to make my own universal snippet manager that would work across whatever editor I was using that day.

Snippets are just files in a directory structure, and then I use FZF to find the snippet i’m looking for.

alfred

The script takes what you are typing in alfred, and uses fzf to find all the files matching that:

echo '{"items": ['

for x in `(cd ~/pcloud/reference/cli/snippets  && find * ! -path snip -type f | /usr/local/bin/fzf -f "{query}")`
do

echo "
{
		\"uid\": \"$x\",
		\"arg\": \"$x\",
		\"title\": \"$x\",
		\"autocomplete\": \"$x\",
},
"
done

echo ']}'

I then pass it to a script that cats it out, and then send that to the clipboard. So for example, if I was editing an ansible playbook, and wanted to paste in a file segment, I could open alfred type sn ansfi and that’s enough to file the ansible/file entry , and it is copied to the clipboard.

I was thinking of writing a converter, that converts my snippets to other snippet managers to make a sort of universal snippet, but currently this alfred workflow is doing a good enough job that I don’t need to use any of the IDE built in systems.

Work Journal

Me and my brain are in a constant conflict of: “Don’t worry I can remember THAT”, and “I forgot.” To combat this, I’ve been keeping a daily work journal of things that happen that day; things like servers crashing, config changes that were made, how to do some task or another..etc. It has come in very handy for when something happens in the middle of the night and you are oncall and you are able to quickly search for the last time something like this happened and a simple explanation on how you fixed it last time.

I was using a custom containerized webapp that connected to a s3 database to hold all this information, but decided that It might be easier to just store this information in a large text file to make it easier to search and edit.

The workflow I’ve come up with for this looks something like this:

alfred

In Alfred, you type just jrnl if you just want the journal to open, or you can type jrnl topic and it will create a template for a new journal entry and then open the file. I wanted the newest entry on top, so that took a little tom foolery to get that to happen (thus me running a shell script instead of using Alfred’s built in write to file):

echo "## {query}
$(date +"%Y-%m-%d:%H:%M")

----
$(cat workjrnl.jrnl)
" > workjrnl.jrnl