dotfiles/zsh/.zsh/runfile.zsh

24 lines
619 B
Bash
Raw Normal View History

2024-08-09 22:39:10 +02:00
# It's like makefile/justfile but using a simple script!
# usage: run <arguments passed to runfile>
# runfile can be placed in CWD or parents
run () {
local runfile
runfile="$(_run "$PWD")" && "$runfile" "$@"
}
_run () {
RUNFILE_DIR=$1
if [ ! -e "$RUNFILE_DIR/runfile" ] && [ ! -e "$RUNFILE_DIR/.runfile" ]; then
if [ "$RUNFILE_DIR" = "/" ]; then
echo "Runfile not found" 1>&2; return 1
else
_run "$(dirname $RUNFILE_DIR)"
fi
elif [ -e "$RUNFILE_DIR/runfile" ]; then
echo "$RUNFILE_DIR/runfile"
elif [ -e "$RUNFILE_DIR/.runfile" ]; then
echo "$RUNFILE_DIR/.runfile"
fi
}