-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
64 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env zsh | ||
# | ||
# Extends `find` to use .gitignore to exclude | ||
# paths from results. | ||
# | ||
# Created M. Massenzio, 2024-05-04 | ||
declare -r search_dir=${1:-.} | ||
|
||
# Start constructing the find command | ||
cmd="find ${search_dir} -type f" | ||
|
||
# Exclude common "noisy" directories | ||
patterns=('.git' '.run' '.idea' '.cache') | ||
for p in "${patterns[@]}"; do | ||
cmd+=" -not -path ${search_dir}/$p/'*'" | ||
done | ||
|
||
# If it exists in the current directory, | ||
# or in the $search_dir path, | ||
# read each line from .gitignore | ||
gitignore=$(test -f ./.gitignore && echo './.gitignore' || \ | ||
echo "${search_dir}/.gitignore") | ||
if [[ -n ${gitignore} ]]; then | ||
while read -r pattern; do | ||
# Ignore empty lines and comments | ||
# Append the exclusion pattern to the find command | ||
# only if it is a directory exclusion pattern. | ||
if [[ -n "$pattern" && ! ( "$pattern" =~ '^#' || "$pattern" =~ '^!' ) \ | ||
&& "$pattern" =~ '/$' ]]; then | ||
cmd+=" -not -path '$search_dir/$pattern*'" | ||
fi | ||
done < ${gitignore} | ||
fi | ||
|
||
# Execute the find command | ||
eval "$cmd" |
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
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
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