Skip to content

Commit efc3f10

Browse files
committed
[scripts] ,markdown-to-html: add -l flag for live preview and file picker
-l flag delegates to ,markdown-preview for live reload. When no file is given in an interactive terminal, offers fd+fzf file selection.
1 parent a9ed760 commit efc3f10

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

scripts/.local/bin/utils/,markdown-to-html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
#!/bin/sh
22

3-
# Convert markdown to html once. Use ,markdown-preview for continues updates.
3+
# Convert markdown to html once. Use -l for live preview via ,markdown-preview.
44

55
set -e
66

7+
live=0
8+
if [ "$1" = "-l" ]; then
9+
live=1
10+
shift
11+
fi
12+
713
input="$1"
14+
# if no file provided and interactive terminal, pick one with fzf
15+
if [ -z "$input" ] && [ -t 0 ]; then
16+
input=$(fd -e md --max-depth 3 | fzf --preview 'head -50 {}') || exit 1
17+
fi
18+
819
# read from stdin if available
920
if [ -z "$input" ]; then
1021
if [ -t 0 ]; then
11-
echo "Usage: $0 <input.md> [output.html]"
22+
echo "Usage: $0 [-l] <input.md> [output.html]"
1223
exit 1
1324
else
1425
input="/dev/stdin"
1526
fi
1627
fi
1728

29+
if [ "$live" = 1 ]; then
30+
exec ,markdown-preview "$input"
31+
fi
32+
1833
basename_noext=$(basename "$input" .md)
1934
filename="/tmp/$(xxd -l2 -ps /dev/urandom)-${basename_noext}.html"
2035
outfile=${2:-$filename}

0 commit comments

Comments
 (0)