Skip to content

Instantly share code, notes, and snippets.

@metlos
Last active February 27, 2024 14:04
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 metlos/42c935f459cd60b9a596552455004758 to your computer and use it in GitHub Desktop.
Save metlos/42c935f459cd60b9a596552455004758 to your computer and use it in GitHub Desktop.
To be put in the $PATH. You tell it a directory and it will search for all git repositories underneath it, outputting the current branch and clean/dirty state for each
#!/bin/sh
function usage {
echo "USAGE"
echo "git where-am-i DIR"
}
function report_dir {
local prefix=$1
local branch=$(git rev-parse --abbrev-ref HEAD)
if git diff --quiet; then
status="✅"
else
status="❌"
fi
echo "$prefix: $branch $status"
}
if [ $# == 0 ]; then
usage
exit 1
fi
DIR=$(realpath $1)
for git_dir in $(find "$DIR" -name .git -type d); do
path=$(realpath --relative-to "$DIR" "${git_dir}/..")
cd "${git_dir}/.."
report_dir "$path"
cd "$DIR"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment