~kris/dots

srice

ref: c8d9c68937f2c331a6bac47481ed40147fe73cba srice/.local/bin/misc/write -rwxr-xr-x 2.9 KiB
c8d9c689 — Kris Yotam shell migration: fish -> mksh, reorganize bin/, wallpaper cleanup 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/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