#!/usr/bin/env bash
set -euo pipefail
###############################################################################
# KRIS WRITE — Content browser for krisyotam.com
#
# Maintainer: Kris Yotam <krisyotam@pm.me>
# License: MIT
# Created: 2025-01-01
# Updated: 2026-02-15
# Description: Browse content repos with nnn, open files in Typora.
# Select a content type, then browse ~/content/{type}/ with nnn.
# Enter on any .mdx file opens it in Typora.
###############################################################################
###############################################################################
# config
###############################################################################
CONTENT_DIR="$HOME/content"
CONTENT_TYPES=(
blog diary essays fiction news notes ocs
papers progymnasmata reviews verse
)
###############################################################################
# helpers
###############################################################################
have_cmd() { command -v "$1" >/dev/null 2>&1; }
die() { echo "ERROR: $1" >&2; exit 1; }
have_cmd fzf || die "fzf not found"
have_cmd nnn || die "nnn not found"
have_cmd typora || die "typora not found"
###############################################################################
# ui
###############################################################################
print_banner() {
local cols
cols="$(tput cols 2>/dev/null || echo 80)"
if have_cmd figlet; then
figlet -w "$cols" -f big "KRISYOTAM.COM" 2>/dev/null \
|| figlet -w "$cols" "KRISYOTAM.COM"
else
echo "KRISYOTAM.COM"
fi
echo
echo " est. 2025"
echo " author: Kris Yotam"
echo " script: write"
echo
echo " \"Do I contradict myself? Very well then I contradict myself,"
echo " (I am large, I contain multitudes.)\""
echo " — Walt Whitman"
echo
}
###############################################################################
# main
###############################################################################
main() {
clear
print_banner
while true; do
# Select content type via fzf
local type
type="$(
printf "%s\n" "${CONTENT_TYPES[@]}" "quit" |
fzf --prompt="type> " --height=15 --reverse
)" || exit 0
[[ "$type" == "quit" ]] && exit 0
local content_path="$CONTENT_DIR/$type"
if [[ ! -d "$content_path" ]]; then
echo "Directory not found: $content_path"
read -rp "Press Enter..." _
continue
fi
# Launch nnn in the content directory with Typora as opener
NNN_OPENER="$HOME/.local/bin/nnn-typora" \
NNN_FALLBACK_OPENER="${NNN_OPENER:-xdg-open}" \
nnn "$content_path"
# After nnn exits, loop back to type selection
clear
print_banner
done
}
main