pure bash bible
This commit is contained in:
commit
f35db645a2
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
message="Valid entries are: <num>-<num>, <num>-,-<num>, <num>, ''"
|
||||||
|
path=$( readlink -f $0 )
|
||||||
|
path=${path%/*}
|
||||||
|
printf '%s\n' "Chapters:"
|
||||||
|
for num in {0..19}; do
|
||||||
|
file="$path/chapter$num.txt"
|
||||||
|
(( ${#num} == 1 )) && num="0$num"
|
||||||
|
h=$( grep -m1 . $file )
|
||||||
|
h=${h:2} # rm first 2 chars ('# ')
|
||||||
|
# h="${h#"${h%%[![:space:]]*}"}" # rm leading white spaces
|
||||||
|
h=${h,,} # all to lowercase
|
||||||
|
h=${h^} # first to uppercase
|
||||||
|
printf '%s\n' "$num: $h"
|
||||||
|
done
|
||||||
|
|
||||||
|
re_num='^[0-9]+$'
|
||||||
|
while true; do
|
||||||
|
read -p "Input range: " range
|
||||||
|
# echo "you chose $range"
|
||||||
|
start=${range%%-*}
|
||||||
|
: ${start:=0}
|
||||||
|
end=${range##*-}
|
||||||
|
: ${end:=19}
|
||||||
|
# echo "start is $start and end is $end"
|
||||||
|
[[ $start =~ $re_num ]] && [[ $end =~ $re_num ]] && break || echo "Not a valid range. $message"
|
||||||
|
done
|
||||||
|
|
||||||
|
for num in {0..19}; do
|
||||||
|
file="$path/chapter$num.txt"
|
||||||
|
(( $num >= $start )) && (( $num <= $end )) && pandoc -s --from=markdown --to=pdf $file | zathura -
|
||||||
|
# (( $num >= $start )) && (( $num <= $end )) && printf '%s\n' "$file"
|
||||||
|
done
|
Loading…
Reference in New Issue