f to choose bakefile
This commit is contained in:
2
Bakefile
2
Bakefile
@@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
install() { # Install bake: required prefix as argument
|
install() { # Install bake: required prefix as argument
|
||||||
# Prefix is ~/.local/ or /usr/local/
|
# Prefix is ~/.local/ or /usr/local/
|
||||||
# The executable is put under PREFIX/bin/ and should be in PATH
|
# The executable is put under PREFIX/bin/ and should be in PATH
|
||||||
|
|||||||
74
bake
74
bake
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## VERSION 22.4.1
|
## VERSION 22.4.2
|
||||||
## BASH-MAKE ==========================================================
|
## BASH-MAKE ==========================================================
|
||||||
## Utility to mimick some of GNU Make behavior, but run in a single
|
## Utility to mimick some of GNU Make behavior, but run in a single
|
||||||
## bash shell. This executable can be used as the Bakefile, too,
|
## bash shell. This executable can be used as the Bakefile, too,
|
||||||
@@ -43,6 +43,32 @@ _menu() { _flines | while read line; do
|
|||||||
"${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
|
"${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
|
||||||
fi
|
fi
|
||||||
done; }
|
done; }
|
||||||
|
_help() {
|
||||||
|
cat <<EOF
|
||||||
|
Bash-Make: bake
|
||||||
|
Runs bash functions from Bakefile, like make would from Makefile.
|
||||||
|
Reserved arguments:
|
||||||
|
-h This help. Add function name to get help for the target.
|
||||||
|
-f [Bakefile] Choose a different Bakefile than the default.
|
||||||
|
-l List targets
|
||||||
|
-m Menu of targets with 'smenu' command
|
||||||
|
__autocomplete__ get autocomplete function for bash
|
||||||
|
|
||||||
|
Example Bakefile
|
||||||
|
# help() { # This help. Note the exact function declaration + docs format.
|
||||||
|
# # function names may contain characters: a-zA-Z0-9._-
|
||||||
|
# # functions starting with _ are not listed
|
||||||
|
# _menu
|
||||||
|
# }
|
||||||
|
# echo foo # NOTE: Bakefile gets sourced when read!
|
||||||
|
# default() { # Default function will be run if present, and no target passed
|
||||||
|
# # Extra help to be read with -h
|
||||||
|
# echo "I'm running!"
|
||||||
|
# _smenu # interactive menu with 'smenu' command
|
||||||
|
# }
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
_itemhelp() { funfound=0; cat "$BAKEFILE" | while read line; do
|
_itemhelp() { funfound=0; cat "$BAKEFILE" | while read line; do
|
||||||
if [[ "$line" =~ ^("$1")\(\).\{[\ #]*(.*) ]]; then
|
if [[ "$line" =~ ^("$1")\(\).\{[\ #]*(.*) ]]; then
|
||||||
printf "\e[33m%s \e[36m %s\e[0m\n" \
|
printf "\e[33m%s \e[36m %s\e[0m\n" \
|
||||||
@@ -76,35 +102,23 @@ _source_bakefile() {
|
|||||||
. "$BAKEFILE"
|
. "$BAKEFILE"
|
||||||
fi; }
|
fi; }
|
||||||
|
|
||||||
case $1 in
|
for (( i=1; i<=$#; i++ )); do
|
||||||
"__list__") _flines | sed 's/().*//'; exit ;;
|
if [[ $i -eq 1 ]]; then
|
||||||
"-m") _smenu; exit ;;
|
if [[ "${!i}" = "__list__" ]]; then _flines | sed 's/().*//'; exit; fi
|
||||||
"-l") _menu; exit ;;
|
fi
|
||||||
"-h") if [[ -n "$2" ]]; then _itemhelp "$2"; else cat <<EOF
|
j=$(( i + 1 ))
|
||||||
Bash-Make: bake
|
if [[ "${!i}" = "-m" ]]; then _smenu; exit; fi
|
||||||
Runs bash functions from Bakefile, like make would from Makefile.
|
if [[ "${!i}" = "-l" ]]; then _menu; exit; fi
|
||||||
Reserved arguments:
|
if [[ "${!i}" = "-f" ]]; then BAKEFILE="${!j}"; REMOVEARG="${i}"; fi
|
||||||
-h This help. Add function name to get help for the target.
|
if [[ "${!i}" = "-h" ]]; then
|
||||||
-l List targets
|
if [[ -n "${!j}" ]]; then _itemhelp "${!j}"; else _help; fi
|
||||||
-m Menu of targets with 'smenu' command
|
exit
|
||||||
__autocomplete__ get autocomplete function for bash
|
fi
|
||||||
|
done
|
||||||
Example Bakefile
|
if [[ -n "$REMOVEARG" ]]; then
|
||||||
# help() { # This help. Note the exact function declaration + docs format.
|
# remove args if Bakefile was modified
|
||||||
# # function names may contain characters: a-zA-Z0-9._-
|
set -- "${@:1:REMOVEARG-1}" "${@:REMOVEARG+2}"
|
||||||
# # functions starting with _ are not listed
|
fi
|
||||||
# _menu
|
|
||||||
# }
|
|
||||||
# echo foo # NOTE: Bakefile gets sourced when read!
|
|
||||||
# default() { # Default function will be run if present, and no target passed
|
|
||||||
# # Extra help to be read with -h
|
|
||||||
# echo "I'm running!"
|
|
||||||
# _smenu # interactive menu with 'smenu' command
|
|
||||||
# }
|
|
||||||
|
|
||||||
EOF
|
|
||||||
fi; exit ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Run commands
|
# Run commands
|
||||||
_source_bakefile
|
_source_bakefile
|
||||||
|
|||||||
Reference in New Issue
Block a user