👴 jdcard

Simple Tools

Throughout the years I encouraged my staff to always write the date on anything they wrote at work, even if they were writing out their grocery list of things to pick up on their way home. Later I worked with an engineer who always kept a notebook on her desk and throughout the day would make brief entries about the files she worked on, the changes she made to code, which project she was working on, and how much time was billable to the client. Those dated entries proved valuable so many times that I wanted to find a simple way to keep a journal or daybook for myself. Since I'm allergic to writing things by hand, and almost all my work was done in the computer, it made sense to do my journaling in that environment.

When I worked primarily in Microsoft Windows computing environments, I collected a series of small tools to help with day to day tasks. One of these was a simple text editor called [SavageEd]*, which I selected because it offered these features: it was lightning-fast to start, even on a slow machine; it would automatically reopen the last file you had edited, it offered a "log mode" in which it would automatically insert a new line at the top or bottom of a file and insert a date and timestamp with the current time; and it could be configured to save my edits and exit the program with a single keystroke ([ESC]). This allowed me to emulate one of the features of [Borland Sidekick]: a quick note-taking app available at any time from a keyboard shortcut. I configured a global Windows shortcut to open SavageEd any time I pressed [CTRL]+[ALT]+[j], and then I had a simple, quick editor that didn't require multiple mouse actions to open the program, select the file to edit, click to insert a datestamp, save my edits, and then close the program. Instead, to make a quick note was simply [CTRL]+[ALT]+[j], type my text, hit [ESC] and I was done -- all without needing a mouse, and no matter what other programs I had open or which window currently had focus.

[SavageEd] [Borland Sidekick]

When I moved from working on Windows machines all the time to a Linux environment I looked for a similar utility. While Linux has tons of little utilities available for nearly any task you can imagine, I never found anything that would work quite the same way. I even tried running SavageEd, but the Wine environment is just too slow to start for it to be used the same way as I did in Windows. I tried lots of editors but none would do just what I wanted. The problem was that I was trying to do things the Windows way in Linux -- once I learned to think differently I came up with a similar solution using the built-in Linux utilities. Here it is as a one-liner entered in my .bashrc file:

      alias j='echo "JOURNAL: enter text.";
      IFS= read -r textline;
      echo $textline | ts "%Y-%m-%d %H:%M:%S " >> ~/Documents/journal.txt;
      tail -n5 ~/Documents/journal.txt;'
    

Yeah, I said one line but showed you four – that's just for readability here, but it is all actually just a single line. Let's see what's going on here: the "alias" creates a shortcut that substitutes all the stuff enclosed between the ' ' marks for the single letter "j" entered as a command on the command line. Next the "echo" statement prints a prompt reminding me that I'm making an entry into my journal. The "IFS=" sets the internal field separator to be empty for the "read" command that then accepts the line of text that I want to enter into the journal. The second "echo" statement sends it to the "ts" timestamp utility which prepends the date and time to the text I've entered, and then redirects the output to be appended to the end of my journal file. Finally the "tail" command displays the last five lines of my journal, both to confirm that the entry was made and to show me a bit of context.

Now, to make an entry in my journal it is [ALT]+[TAB] to get to my terminal window (if I'm not already there), [j] [ENTER] to start capturing text, and [ENTER] again to exit. It's not quite as quick and simple as my Windows setup, unless I happen to already be working in a terminal window – which is actually pretty often. Similarly, I set up an alias for an "ej" (edit journal) shortcut to open my journal file in my favorite editor when a single-line quick entry is not enough.

Eventually I replaced the "j" alias with a script in $HOME/bin"

      #!/bin/bash
      # Add an entry to my daily journal ($JRNL)
      
      # Requires:
      #   bash;
      #   moreutils; for ts timestamp utility
      
      # Location of my daily journal file; use $JRNL environment variable if set.
      "${JRNL:=/home/$USER/Documents/Journal/journal.txt}"
      
      if [ "${1}" ]; then
        echo "$@" | ts "%Y-%m-%d %H:%M:%S " >> $JRNL;
      else
        echo "JOURNAL: enter text.";
        IFS= read -r textline;
        echo $textline | ts "%Y-%m-%d %H:%M:%S " >> $JRNL;
      fi
      tail -n5 $JRNL;
    

This works better for me because the line editor for "read" doesn't allow any editing other than destructive backspace, so if I noticed a typo at the beginning of the line I could either keep typing my entry and edit it later, or backspace back to the beginning of the line, correct the error, and then retype all the text I just deleted. I do have to be mindful of characters in my input that BASH intercepts (like ";"), it is simple to compensate for this by just enclosing my entire text in quotes: j "This works just fine; BASH ignores the semicolon."

* Since the author of SavageEd, Sevag Krikorian, authorized its redistribution ("This program may or may not be distributed with documents and source. ... It may be re-distributed in whole or in part, with or without sources bundled or stand alone.") I have linked both the original SavageEd.zip and the later SavageEd2.zip here. The source files are included as well as the Windows executables.

SavageEd.zip SavageEd2.zip

©2022 🅭🅯🄏🄎 Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

🗡️ spartan://jdcard.com:3300/ 🛰️ gemini://jdcard.com/ 🌐 http://jdcard.com/