diff --git a/README.md b/README.md index 7bf80e5..18b370f 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ The command-line scripts include: * [feature](FEATURE.md) - make working with feature branches easier * [release](RELEASE.md)- make working with release branches and tags easier * [xgrep](XGREP.md)- make using `git-grep` easier +* [xfind](XFIND.md)- make using `find` easier The command-line scripts are written in Ruby 2.x using just the standard libraries and do not require any gems to be installed. For OS X users, these should just work out-of-box. @@ -37,3 +38,4 @@ cd ~/GitHub/rkiel/git-utilities * [See feature](FEATURE.md) * [See release](RELEASE.md) * [See xgrep](XGREP.md) +* [See xfind](XFIND.md) diff --git a/XFIND.md b/XFIND.md new file mode 100644 index 0000000..1e42b2c --- /dev/null +++ b/XFIND.md @@ -0,0 +1,15 @@ +[< 1 - names = names.join(' -o ') - names = ['\(', names, '\)'] + include_paths = options.paths.reject {|x| x[:exclude] }.map {|x| "-path '*/#{x[:pattern]}/*'"} + if include_paths.size > 1 + include_paths = include_paths.join(' -o ') + include_paths = ['\(', include_paths, '\)'] end - names = names.join(' ') + include_paths = include_paths.join(' ') + + exclude_paths = options.paths.select {|x| x[:exclude] }.map {|x| "! -path '*/#{x[:pattern]}/*'"} + if exclude_paths.size > 1 + exclude_paths = exclude_paths.join(' -a ') + exclude_paths = ['\(', exclude_paths, '\)'] + end + exclude_paths = exclude_paths.join(' ') + + include_names = options.names.reject {|x| x[:exclude] }.map {|x| "-name '*.#{x[:pattern]}'"} + if include_names.size > 1 + include_names = include_names.join(' -o ') + include_names = ['\(', include_names, '\)'] + end + include_names = include_names.join(' ') + + exclude_names = options.names.select {|x| x[:exclude] }.map {|x| "! -name '*.#{x[:pattern]}'"} + if exclude_names.size > 1 + exclude_names = exclude_names.join(' -a ') + exclude_names = ['\(', exclude_names, '\)'] + end + exclude_names = exclude_names.join(' ') commands = [ - ["find", ".", "-type f", names, paths].join(" "), + ["find", ".", "-type f", include_names, exclude_names, include_paths, exclude_paths].join(" "), "sort", ] if options.terms.size > 0