-
-
Save swenzel/16cbe583a12cb95008300fed865e734b to your computer and use it in GitHub Desktop.
Iteratively goes through parent directories to find and execute a script called "run.sh"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# You can either copy paste the following function into your shell's rc file or | |
# you can just put this whole script as an executable file somewhere in your PATH for example at ~/.local/bin | |
run(){ | |
local workdir | |
workdir="$(pwd)" | |
while [ ! -f "${workdir}/run.sh" ] && [ "${workdir}" != "/" ]; do | |
workdir="$(dirname "${workdir}")" | |
done | |
if [ -f "${workdir}/run.sh" ] && [ ! -x "${workdir}/run.sh" ]; then | |
echo "Found run.sh file that is not executable." | |
echo "Please run 'chmod +x ${workdir}/run.sh', then try again" | |
return 1 | |
fi | |
if [ "${workdir}" = "/" ]; then | |
echo "Couldn't find run.sh file" | |
return 1 | |
fi | |
"${workdir}/run.sh" ${*} | |
} | |
run ${*} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment