Thought from Terminal
Purpose
Section titled “Purpose”So I added a section of the webpage where I can add fleeting thoughts in tiny bubble. Just like a former blue website. Then I thought huh, wouldn’t it be swell to be able to do this from the terminal?
Then the thought became a tiny function in my .zshrc. And now I can shoot thoughts straight from the terminal right into my website. How cool is that?
I built up the string’s static parts and used cat to grab a multiline string for the thought. Then I added an empty <div> on the page to be able to determine where to add the new thought, then I used awk to find that anchor and add lines below it. Lastly I opened a subshell, cd into the directory, added the thought to the file and did the whole git add commit push thing. Then GitHub takes over, rebuilding the site and presto, a fresh thought!
The line is just a guide for the max width of a thought. I don’t want any weird stuff with phone screens, so I make it pretty short - 52 characters max.
The code is ugly, but whatever. Here it is:
function thought() { echo "End with Ctrl+D twice\n\n" echo "------------------------------------------" THOUGHT="$(cat)"
echo ""
FULL="\`\`\`sh> date +\"%Y-%m-%dT%H:%M:%S\"$(date +'%Y-%m-%dT%H:%M:%S')> cat thought\"$THOUGHT\"\`\`\`"
( cd ~/tedwall.se/src/content/docs git pull
awk -v insert="$FULL" ' /hidden-anchor-for-start-of-thoughts/ { print print insert next } 1 ' fleeting-thoughts.mdx > tmp && mv tmp fleeting-thoughts.mdx
git add . git commit -am $(date +'%Y-%m-%dT%H:%M:%S') git push )}