alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

011.txt (1959B) [raw]


      1 Lowering Barriers to Writing
      2 ----------------------------
      3 Sun Nov 21 10:21:16 EST 2021
      4 
      5 ---
      6 Sipping coffee and listening to Psychedelic Swamp on the
      7 turntable while Jennie shops online for plants as presents.
      8 ---
      9 
     10 When I moved from mdoc(7) over HTTP to plaintext over Gopher,
     11 the barrier to writing became much smaller. No longer did I
     12 have to look up the mdoc man page while writing, nor did I
     13 have to check how it looked in multiple formats (HTML and
     14 ASCII). There were also psychological barriers too--a phlog
     15 has less traffic, and the traffic here is maybe less judgey.
     16 I feel I can be a bit more open in my writing and worry about
     17 the phrasing less.
     18 
     19 I wanted to make it even easier to "just start writing", so
     20 I wrote a small shell script "phlog(1)" that:
     21 
     22   1. Takes a title
     23   2. Starts a new entry at the next NNN.txt file available
     24   3. Prepopulates the entry with the title and date
     25   4. Updates the phlog index to include the entry
     26 
     27 It's in gopher://alexkarle.com/1/code, but I wanted to include
     28 it here too, just because I expect it'll morph over time and
     29 I want to document the MVP!
     30 
     31 Some things learned:
     32 
     33 - `$(())` for arithmetic returns the result, so to avoid
     34   executing a number, prefix it with the null operation `:`
     35 
     36 - ed(1) is awesome for programmatic edits to files
     37 
     38 --- phlog(1) ---
     39 
     40 #!/bin/sh
     41 # phlog -- lowering the barrier to phlogging
     42 # see gopher://alexkarle.com/phlog/011.txt
     43 die() {
     44     echo "$*"
     45     exit 1
     46 }
     47 
     48 [ -z "$1" ] && die "usage: phlog TITLE"
     49 
     50 PHLOG=$(dirname "$(dirname "$(readlink -f "$0")")")/phlog
     51 
     52 i=1
     53 nextfile() {
     54     file=$(printf "%03d.txt" $i)
     55     : $((i+=1))
     56 }
     57 
     58 title="$*"
     59 underline="$(echo "$title" | sed 's/./-/g')"
     60 
     61 nextfile
     62 while [ -e "$PHLOG/$file" ]; do
     63     nextfile
     64 done
     65 
     66 echo "$title" >"$PHLOG/$file"
     67 echo "$underline" >>"$PHLOG/$file"
     68 date >>"$PHLOG/$file"
     69 
     70 ed  "$PHLOG/index.gph" <<EOM
     71 /^\[0|Atom Feed/+a
     72 [0|[$(date +%F)] $title|/phlog/$file|server|port]
     73 .
     74 wq
     75 EOM
     76 
     77 exec "${EDITOR:-vi}" "$PHLOG/$file"