Created
October 25, 2019 09:05
-
-
Save imaami/7961d986487ec2950f925128899c9064 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# | |
# Save this script as $HOME/.local/lib/git/find (make sure it's | |
# executable), then add a git alias: | |
# | |
# $ git config --global alias.find '!$HOME/.local/lib/git/find' | |
# | |
T="$(git rev-parse --show-toplevel)" | |
[[ -z "$T" ]] || T="$T/" | |
P="$T$GIT_PREFIX" | |
if (( ${#@} )); then | |
A=("${@/#/$P}") | |
else | |
A=("$P") | |
fi | |
git ls-tree -r HEAD -- "${A[@]}" | grep -E '^[0-9]+ blob ' | cut -f2 \ | |
| head -c-1 | tr '\n' '\0' | xargs -0 realpath --relative-to="$P" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment