Better shake, but not perfect shake
This commit is contained in:
parent
c91e88e94d
commit
944fcdc02e
42
shake
42
shake
@ -1,28 +1,32 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Originally written by anon, modified
|
# Originally written by Anon, modified by Emil to better match Bake functionality
|
||||||
|
|
||||||
|
# Issues: sloooow, fails to handle multi-line statements
|
||||||
|
|
||||||
BLUE='\033[34m'
|
BLUE='\033[34m'
|
||||||
GREEN='\033[32m'
|
GREEN='\033[32m'
|
||||||
|
YELLOW='\033[93m'
|
||||||
|
DIM='\033[2m'
|
||||||
BOLD='\033[1m'
|
BOLD='\033[1m'
|
||||||
NORMAL='\033[0m'
|
NORMAL='\033[0m'
|
||||||
|
|
||||||
MARKNAME="@BAKE"
|
MARKNAME="@BAKE"
|
||||||
MARK="${MARKNAME} "
|
MARK="${MARKNAME} "
|
||||||
MARKSTR="${BLUE}${MARKNAME}${NORMAL}"
|
MARKSTR="${GREEN}${MARKNAME}${NORMAL}"
|
||||||
|
|
||||||
enable -n echo
|
enable -n echo
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
IFSTR="${GREEN}<input_file>${NORMAL}"
|
echo -e "$0: [option] ${BOLD}target-file${NORMAL} [${GREEN}arguments${NORMAL} ...]\n"
|
||||||
echo -e "${BOLD}Usage: $0 <input_file>${NORMAL}" >&2
|
echo -e "Use the format \`${BOLD}@BAKE${NORMAL} cmd ...' within the ${BOLD}target-file${NORMAL}."
|
||||||
echo -e "\t$0 runs the value of ${MARKSTR}." >&2
|
echo -e "This will execute until the end of line, or if existing, until the ${BOLD}@STOP${NORMAL} marker.\n"
|
||||||
echo -e "\tThe point of this script is ease to compialation of single source file (toy) programs." >&2
|
echo -e "Options [Must be first]"
|
||||||
echo -e "\tThe value of ${MARKSTR} is read from ${IFSTR} in is whatever comes after '${MARK}' until the end of the line." >&2
|
echo -e "\t${DIM}-h --help${NORMAL}, ${BOLD}-n --dry-run${NORMAL}\n"
|
||||||
echo -e "\tInside the value of ${MARKSTR} all mentions of special placeholders are replaced:" >&2
|
echo -e "Expansions\n"
|
||||||
echo -e "\t\t${BLUE}\$@${NORMAL} - ${IFSTR}"
|
echo -e "\t${YELLOW}@FILENAME${NORMAL} returns target-file (abc.x.txt)"
|
||||||
echo -e "\t\t${BLUE}\$*${NORMAL} - ${IFSTR} with the last extension cut off"
|
echo -e "\t${YELLOW}@SHORT${NORMAL} returns target-file without suffix (^-> abc.x)"
|
||||||
echo -e "\t\t${BLUE}\$+${NORMAL} - All remaining arguments"
|
echo -e "\t${YELLOW}@ARGS${NORMAL} returns ${GREEN}arguments${NORMAL}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# -lt 1 ]]; then
|
if [[ $# -lt 1 ]]; then
|
||||||
@ -53,17 +57,25 @@ if [[ ! -f $input_file ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cd $(dirname "$(readlink -f "$input_file")")
|
||||||
|
input_file=${input_file##*/}
|
||||||
|
|
||||||
line=$(grep "$MARK" "$input_file" | head -1)
|
line=$(grep "$MARK" "$input_file" | head -1)
|
||||||
|
|
||||||
|
if [[ -n $line ]]; then
|
||||||
|
|
||||||
line=${line//\$@/$input_file}
|
line=${line//\$@/$input_file}
|
||||||
line=${line//\$\*/${input_file%.*}}
|
line=${line//\$\*/${input_file%.*}}
|
||||||
line=${line//\$+/$@}
|
line=${line//\$+/$@}
|
||||||
|
line=${line//@FILENAME/$input_file}
|
||||||
|
line=${line//@SHORT/${input_file%.*}}
|
||||||
|
line=${line//@ARGS/$@}
|
||||||
|
line=$(echo "$line" | sed 's/\W*@STOP.*//')
|
||||||
|
|
||||||
if [[ -n $line ]]; then
|
|
||||||
command="${line#*${MARK}}"
|
command="${line#*${MARK}}"
|
||||||
command=$(echo $command | sed 's/[^\\]\?#.*//')
|
echo -e "${BOLD}${GREEN}$0${NORMAL}: $command"
|
||||||
echo "Exec: $command"
|
|
||||||
if [[ $run -eq 1 ]]; then
|
if [[ $run -eq 1 ]]; then
|
||||||
echo "Output:"
|
echo -e "${BOLD}${GREEN}output${NORMAL}:"
|
||||||
sh -c "$command"
|
sh -c "$command"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user