Created
July 9, 2017 02:49
-
-
Save lionelyoung/e889d20deb318e71b3fe775d059e2aa6 to your computer and use it in GitHub Desktop.
Find a subdirectory name with maxdepth
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
# Find dir | |
# https://stackoverflow.com/questions/2824504/how-do-i-prevent-find-from-printing-git-folders | |
function finddir () { | |
# Defaults | |
DEPTH=4 | |
# Arg check | |
if [ "$#" -gt 2 ] || [ "$#" -lt 1 ] ; then | |
echo "Illegal number of parameters" | |
fi | |
# override defaults if not empty | |
if ! [ -z "$2" ]; then | |
echo "Overriding DEPTH with $2" | |
DEPTH=$2 | |
fi | |
########################### | |
# Execute the find command | |
########################### | |
echo "Searching for '$1' with -maxdepth $DEPTH" | |
find . -name '.git*' -prune -o -name "*$1*" -maxdepth $DEPTH -type d -print | |
} | |
alias fd="finddir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment