diff --git a/scripts/milk-commands b/scripts/milk-commands new file mode 100755 index 00000000..236ec1d3 --- /dev/null +++ b/scripts/milk-commands @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +MSdescr="list milk- scripts" + +MSextdescr="List milk scripts + +Scan system for milk- commands + +" + +source milk-script-std-config + +PRINTPATH="0" +MSopt+=( "p:path:set_printpath::Print command path" ) +function set_printpath() +{ + PRINTPATH="1" +} + +PRINTDATE="0" +MSopt+=( "d:date:set_printdate::Print command date" ) +function set_printdate() +{ + PRINTDATE="1" +} + +source milk-argparse + + +CMDLIST=$(compgen -c "milk-" | sort -u ) + +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +echo "LIST OF MILK COMMANDS :" + +for cmd in $CMDLIST; do + if [ "${PRINTPATH}" = "1" ]; then + pathstring="$(which ${cmd})" + printf " ${GREEN}%-32s${NC} %s\n" "$cmd" "${pathstring}" + elif [ "${PRINTDATE}" = "1" ]; then + filename="$(which ${cmd})" + datestring="$(date -r $filename '+%Y-%m-%dT%H:%M:%SZ')" + CMDLISTOUT+="$(printf "%s %s;" "${datestring}" "$cmd")" + else + helpline=$( $cmd -hs | head -n 1 ) + printf " ${GREEN}%-32s${NC} %s\n" "$cmd" "$helpline" + fi + +done + + +if [ "${PRINTDATE}" = "1" ]; then + IFS=';' read -r -a array <<< "${CMDLISTOUT//[$'\t\r\n']}"; unset IFS + IFS=$'\n' sortedarray=($(sort <<<"${array[*]}")); unset IFS + for element in "${sortedarray[@]//[$'\t\r\n']}" + do + cmdstr=$(echo $element | awk '{ print $2}') + datestr=$(echo $element | awk '{ print $1}') + helpline=$( $cmdstr -hs | head -n 1 ) + printf " %s ${GREEN}%-32s${NC} %s\n" "$datestr" "$cmdstr" "$helpline" + done +fi