You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB
Bash

#!/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