-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwow
More file actions
executable file
·82 lines (72 loc) · 1.93 KB
/
wow
File metadata and controls
executable file
·82 lines (72 loc) · 1.93 KB
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
#!/bin/bash
#Words Of Wisdom
# output some random text from my journal
#TODO
# - add option to specify max depth of directory recursion (or no recursion)
# - define a more detailed config file
r=5 #range of text sample (how many lines to grab)
V=false #verbose
files=()
while getopts "f:l:r:v" opt; do
case $opt in
v)
V=true
;;
f)
files+=("$OPTARG")
if $V ; then echo $OPTARG; fi
;;
r)
r=$OPTARG
echo "using range="$r
;;
l)
if $V ; then echo "using files listed in "$OPTARG; fi
for l in `cat $OPTARG`; do
l=`echo $l | sed 's,\~,/home/'$USER'/,g'`
echo $l
for f in `find $l`; do #expand any wildcards
if $V ; then echo "adding "$f; fi
files+=("$f")
done
done
;;
esac
done
if [[ ${#files[@]} == 0 ]]; then
files=(~/doc/j/_journal-toaug2022 ~/_poetry ~/doc/_journal_2019 )
fi
if [ $V ]; then echo "Grabbing text sample from files: "${files[*]}; fi
n=${#files[@]}
n=$(($n-1))
f=${files[`shuf -i 0-${n} -n 1`]}
if [[ ${f} == *".odt" ]]; then
if $V ; then echo "odt file"; fi
txt=`odt2txt ${f} | tr '.' '\n'`# | sed 's/\./\.\n/g'` #split by sentence because most of these are 1 line
l=`echo ${txt} | wc -l | cut -f1 -d' '`
echo $txt
echo $l
exit 0
else
l=`wc -l ${f} | cut -f1 -d' '`
txt=`cat ${f}`
fi
if $V; then echo "l="$l; fi
if [[ -z $l ]]; then
echo "line get failed. perhaps ${f} doesn't exist?"
exit 1
fi
t=''
while [[ ! "$t" =~ ^[a-zA-Z0-9] || "$t" =~ ^[0-9] ]]; do
if $V ; then echo "sampling from "${f}; fi
i=`shuf -i ${r}-${l} -n 1`
s=$(($i-$r))
e=$(($i+$r))
if [[ ${e} -gt ${l} ]]; then
e=$((l-1))
fi
if $V ; then echo "lines "$s"-"$e; fi
t=`echo ${txt} | sed -n ${s},${e}p`
# sleep 2
done
echo ${t}