more structure, for autocompletion
This commit is contained in:
4
Bakefile
4
Bakefile
@@ -20,3 +20,7 @@ install() { # Install bake: required prefix as argument
|
|||||||
echo \"if [[ -x $bakepath ]]; then . <( $bakepath __autocomplete__ ); fi\" >> ~/.bashrc
|
echo \"if [[ -x $bakepath ]]; then . <( $bakepath __autocomplete__ ); fi\" >> ~/.bashrc
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_complete_install() {
|
||||||
|
echo "\~/.local /usr/local $( compgen -o plusdirs -f -- "$1" )"
|
||||||
|
}
|
||||||
|
|||||||
51
bake
51
bake
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## VERSION 22.4.3
|
## VERSION 22.4.4
|
||||||
## 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,
|
||||||
@@ -15,24 +15,33 @@ if [[ $STANDALONE = true ]]; then
|
|||||||
BAKEFILE=$0
|
BAKEFILE=$0
|
||||||
else
|
else
|
||||||
if [[ "$1" = "__autocomplete__" ]]; then
|
if [[ "$1" = "__autocomplete__" ]]; then
|
||||||
|
printf -v SELF "%s/%s" "$( cd "$(dirname "$0")" ; pwd -P )" "$( basename "$0" )"
|
||||||
echo '_bake_complete() {
|
echo '_bake_complete() {
|
||||||
|
local BAKE="'$SELF'"
|
||||||
local curr_arg
|
local curr_arg
|
||||||
curr_arg=${COMP_WORDS[COMP_CWORD]}
|
curr_arg=${COMP_WORDS[COMP_CWORD]}
|
||||||
if [[ $COMP_CWORD -eq 1 ]]; then
|
if [[ $COMP_CWORD -eq 1 ]]; then
|
||||||
COMPREPLY=( $(compgen -W "$( bake __list__ ) -h -l -m" -- $curr_arg ) );
|
COMPREPLY=( $(compgen -W "$( $BAKE __list__ ) -h -l -m -f" -- $curr_arg ) );
|
||||||
|
fi
|
||||||
|
if [[ $COMP_CWORD -gt 1 ]]; then
|
||||||
|
compopt -o nospace
|
||||||
|
COMPREPLY=($(compgen -W "$( $BAKE _complete_${COMP_WORDS[1]} $curr_arg )" -- "$curr_arg"))
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
complete -F _bake_complete bake
|
complete -F _bake_complete bake
|
||||||
# Run me as: source <( bake __autocomplete__ )
|
# Run me as: source <( $BAKE __autocomplete__ )
|
||||||
'
|
'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
for BAKEFILE in Bakefile bakefile /dev/null; do
|
if [[ -z "$BAKEFILE" ]]; then
|
||||||
if [[ -f ./$BAKEFILE ]]; then
|
# BAKEFILE not set externally
|
||||||
BAKEFILE=./$BAKEFILE
|
for BAKEDEFAULT in Bakefile bakefile /dev/null; do
|
||||||
|
if [[ -f ./$BAKEDEFAULT ]]; then
|
||||||
|
BAKEFILE=./$BAKEDEFAULT
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_flines() { cat "$BAKEFILE" | \
|
_flines() { cat "$BAKEFILE" | \
|
||||||
@@ -127,16 +136,32 @@ fi
|
|||||||
|
|
||||||
# Run commands
|
# Run commands
|
||||||
_source_bakefile
|
_source_bakefile
|
||||||
if [[ "$1" =~ $( _commands ) ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo "Running target: $1"
|
# No argument given
|
||||||
"$@"
|
|
||||||
elif [[ -n "$1" ]]; then
|
|
||||||
echo "Command '$1' not recognized"
|
|
||||||
_menu
|
|
||||||
elif [[ -z "$1" ]]; then
|
|
||||||
if [[ "$( type -t default )" = function ]]; then
|
if [[ "$( type -t default )" = function ]]; then
|
||||||
|
# Run 'default' if exists
|
||||||
default
|
default
|
||||||
else
|
else
|
||||||
|
# or show menu
|
||||||
|
_menu
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Argument given
|
||||||
|
if [[ "$1" =~ $( _commands ) ]]; then
|
||||||
|
# Argument is one of the targets:
|
||||||
|
echo "Running target: $1"
|
||||||
|
"$@"
|
||||||
|
elif [[ "$1" =~ "_complete_"* ]]; then
|
||||||
|
if [[ "$( type -t $1 )" = function ]]; then
|
||||||
|
# target is a command line completer
|
||||||
|
"$@"
|
||||||
|
else
|
||||||
|
# but there is no defined completion
|
||||||
|
compgen -o plusdirs -f -- "${@: -1}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# no such command
|
||||||
|
echo "Command '$1' not recognized"
|
||||||
_menu
|
_menu
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user