-
Notifications
You must be signed in to change notification settings - Fork 5
/
fortune.sh
executable file
·31 lines (24 loc) · 763 Bytes
/
fortune.sh
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
#!/usr/bin/env bash
set -e
# shellcheck source=./functions.sh
source ./functions.sh
if ! command_available fortune; then
echo "Missing fortune command"
exit 1
fi
if ! command_available strfile; then
echo "Missing strfile command"
exit 1
fi
fortunes_dir="$(brew --prefix fortune)/share/games/fortunes/"
echo "Processing fortunes/*.yaml"
for file in fortunes/*.yaml; do
fortune_basename=$(basename "$file" | sed -e 's/\.yaml$//')
echo "🔮 Scrying $fortune_basename"
fortune_file="$fortunes_dir/$fortune_basename"
# fortune files are \n%\n delimited
yq ea 'join("\n%\n")' "$file" > "$fortune_file"
# generate the .dat so fortune can access
strfile -s "$fortune_file"
paste <(echo "") <(fortune "$fortune_basename" | fold -w 80)
done