Skip to content

Commit

Permalink
added script
Browse files Browse the repository at this point in the history
  • Loading branch information
oguyon committed Aug 15, 2024
1 parent e040a6d commit 55eb6bf
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions scripts/milk-commands
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 55eb6bf

Please sign in to comment.