add type target

This commit is contained in:
q
2025-11-28 18:17:16 +02:00
parent ec540a0cbc
commit 0d7977dad8

24
bake
View File

@@ -1,5 +1,5 @@
#!/bin/bash
## VERSION 23.8.23
## VERSION 25.11.28
## BASH-MAKE ==========================================================
## Utility to mimick some of GNU Make behavior, but run in a single
## bash shell. This executable can be used as the Bakefile, too,
@@ -51,6 +51,26 @@ _menu() { _flines | while read line; do
"${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
fi
done; }
_type() { if [ -z "$1" ]; then echo Give target name; exit 1; fi;
OLDIFS="$IFS"
IFS=''
while read line; do
if [[ "$line" =~ ([a-zA-Z0-9_\.\-]+)\(\).\{[\ #]*(.*) ]]; then
if [ "${BASH_REMATCH[1]}" = "$1" ]; then
infunction=true
printf "\e[33m%s\e[0m() {\e[36m # %-50s ]\e[0m\n" \
"${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
continue
else
infunction=false
fi
fi
if [ "$infunction" = "true" ]; then
if [ -z "$line" ]; then continue; fi
echo "$line"
fi
done < "$BAKEFILE"
IFS="$OLDIFS"; }
_help() {
cat <<EOF
Bash-Make: bake
@@ -59,6 +79,7 @@ Bash-Make: bake
-h This help. Add function name to get help for the target.
-f [Bakefile] Choose a different Bakefile than the default.
-l List targets
-t [target] Type target
-m Menu of targets with 'smenu' command
__autocomplete__ get autocomplete function for bash
@@ -136,6 +157,7 @@ for (( i=1; i<=$#; i++ )); do
j=$(( i + 1 ))
if [[ "${!i}" = "-m" ]]; then _smenu; exit; fi
if [[ "${!i}" = "-l" ]]; then _menu; exit; fi
if [[ "${!i}" = "-t" ]]; then _type "${!j}"; exit; fi
if [[ "${!i}" = "-f" ]]; then BAKEFILE="${!j}"; REMOVEARG="${i}"; fi
if [[ "${!i}" = "-h" ]]; then
if [[ -n "${!j}" ]]; then _itemhelp "${!j}"; else _help; fi; exit