Skip to content

Instantly share code, notes, and snippets.

@swenzel
Last active April 26, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swenzel/16cbe583a12cb95008300fed865e734b to your computer and use it in GitHub Desktop.
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"
#!/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