rwxrob-dot/scripts/md
Rob Muhlestein 2ea0289e9f Rebase
2022-02-09 02:29:05 -05:00

48 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
## See, now *this* is why using only hashtag headers in Markdown are so
## essential. Imagine doing this if level one and two headers could
## also be the stupid underline style.
toc () {
declare file=$(mktemp)
#TODO make it smarter, just need something quick for now
echo cat $file
while IFS= read -r line;do
if [[ $line =~ ^#+\ ]]; then
echo $line >> $file
fi
echo "$line"
done
}
imagelinks () {
declare dir="${1-.}"
find "$dir" -regextype posix-extended -regex '.+(png|jpg|gif)$' -printf "![](%p)\n"
}
########################## Command Delegation ##########################
declare subcommand="$1"; shift
declare -a commands=( toc imagelinks)
######################### Tab Completion Context ########################
if [ -n "$COMP_LINE" ]; then
pre=${COMP_LINE#* }
for cmd in ${commands[@]}; do
[[ $cmd =~ ^$pre ]] && echo $cmd
done
exit 0
fi
###################### Regular Context Delegation ######################
for i in ${commands[@]}; do
if [[ $i == "$subcommand" ]]; then
"$subcommand" $*
exit 0
fi
done