diff --git a/scripts/mdold b/scripts/mdold new file mode 100755 index 0000000..4b3a19b --- /dev/null +++ b/scripts/mdold @@ -0,0 +1,47 @@ +#!/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 +