Skip to content

Instantly share code, notes, and snippets.

@timonweb
Forked from purpleidea/pmake.sh
Created August 15, 2019 09:20
Show Gist options
  • Save timonweb/daab7da95e0b99b984ab2526cdde912d to your computer and use it in GitHub Desktop.
Save timonweb/daab7da95e0b99b984ab2526cdde912d to your computer and use it in GitHub Desktop.
#!/bin/bash
# James Shubin, 2018
# run `make` in the first directory (or its parent recursively) that it works in
# https://purpleidea.com/blog/2018/03/10/running-make-from-anywhere/
MF='Makefile' # looks for this file, could look for others, but that's silly
CWD=$(pwd) # starting here
while true; do
if [ -e "$MF" ]; then
make $@ # run make!
e=$?
cd "$CWD" # go home first
exit $e # pass on the exit status
fi
# stop if we get home
if [ "$(pwd)" = "$HOME" ]; then
cd "$CWD"
exit 2 # the exit status of `make` when it errors
fi
#echo "searching..."
cd .. # go up one dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment