Joel Dare

Status Updates on my Blog

I want to post social media like short status updates but I don’t want to lose those updates at the whim of some social media platform.

I keep these web pages in Markdown. Today I added a status update to the top of my home page and I added a status page to keep track of my running status updates.

Next, I wanted to create a tool to make writing status updates stupid simple.

I use the rc file (specifically ~/.zshrc) for a bunch of little aliases and shortcut scripts/functions. That seems like a natural way to update my status as well.

I decided to ask AI to write the majority of the function for me rather than figure out all the details on my own. I then went back and forth with the AI as well as personal tweak, for the better part of an hour (maybe two, I was in a state of flow). Here’s the final function I ended up with.

function status() {
  if [[ $# -eq 0 ]]; then
    echo "Usage: status <your status update>"
    return 1
  fi

  local status_update="$*"
  local date_time=$(date +"**%B %d, %Y %l:%M%P**")
  local status_line="${date_time}\n${status_update} [More Status Updates](/status.html)"
  
  # File paths
  local index_file="$HOME/Dropbox/Joel/sandbox/joeldare.com/index.md"
  local status_file="$HOME/Dropbox/Joel/sandbox/joeldare.com/status.md"
  
  # Temporary files
  local temp_index_file=$(mktemp)
  local temp_status_file=$(mktemp)

  # Update index.md: Replace lines 3 and 4
  awk -v status_line="$status_line" 'NR==3 {print status_line} NR==4 {next} NR!=3' "$index_file" > "$temp_index_file" && mv "$temp_index_file" "$index_file"

  # Update status.md: Insert at line 3
  awk -v new_status="${date_time}\n${status_update}\n" 'NR==3 {print new_status} {print}' "$status_file" > "$temp_status_file" && mv "$temp_status_file" "$status_file"
}

I also commit the files by adding the following lines to the bottom of the function. This is a little dangerous because it will commit and push those changes plus any others that you’ve made in the meantime.

  # Add the files ane commit those changes (other updates will come along for the ride!)
  cd "$HOME/Dropbox/Joel/sandbox/joeldare.com/"
  git add index.md
  git add status.md
  git commit -m "Add a new status update"
  git push