Post

Notes in Shell

I spend a lot of time in the shell, or the “Terminal” program on MacOS. I also like taking stream of consciousness notes throughout the day. Basically, I like to just jot down how I am feeling and what I am doing. I am not sure that I use these notes, but I get some joy from taking the time to say what I am thinking.

One of the ways that I have used for notes is the DayOne journal. The journal has a command line interface (CLI). You can easily create a new journal entry using the CLI

# create an entry into journal "Test" with content "some text" and timestamp of now
dayone2 -j Test new "some text"    
# create an entry with tags Super and Monkey
dayone2 -j Test -t Super Monkey -- new "some text"
# create an entry with tags Super and Monkey and post it last week
dayone2 -d 'Last Monday' -j Test -t Super Monkey -- new "some text"

Unfortunately, the CLI only allows you to create new notes. For me, that makes it a poor fit for many notes during the day. I would rather just have one entry from each day with all of my nonsense. I contacted Day One, but they were not able to help because the CLI is not high on their priorities.

I grumbled about my issue in the DS|Cafe (The DS|Cafe is an awesome virtual coworking space hosted by Dave Seah). One of my coworker friends, Cindy, came up with a perfect solution that I could just add to my bash file. I use Oh My Zsh, so I made some minor changes, and it is awesome

I originally wrote about this in my [100 Days of Code Log]

shell image

:eyes: SEE! Just a few lines of code in my .zshrc (right), and I can just fire off whatever I want to into my daily log (left). It is fantastic.

Here’s the code that I’m using now. See how I can create notes, see what I have created, and send everything to Day One at the end of the day. I also added a task log that pulls from Task Warrior which is super awesome. I also wrote about how I set up Taskwarrior.

# Set up my cool note system per Cindy!
noted() {
        dirname=$HOME/notes
        if [ ! -d $dirname ]
        then
                mkdir $dirname
        fi
        filename=`date +%Y%m%d`.txt
        timestamp=`date +%H:%M`
        echo " + [$timestamp] $@" >> $dirname/$filename
}
# usage -> $ noted This is the first note
seenoted() {
    dirname=$HOME/notes
    filename=`date +%Y%m%d`.txt
    cat $dirname/$filename
}
notedtojournal() {
    NEWLINE=$'\n'
    dirname=$HOME/notes
    filename=`date +%Y%m%d`.txt
    mynotes=`cat $dirname/$filename`
    header="Daily log:"
    tasksumm=`task dailywork`
    tasklog='Task Log'
    dayone2 new --date=`date +%Y-%m-%dT%H:%M:%S%z` $header${NEWLINE}$mynotes${NEWLINE}${NEWLINE}$tasklog${NEWLINE}$tasksumm
}
This post is licensed under CC BY 4.0 by the author.