xfind: more includes and excludes
This commit is contained in:
@@ -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)
|
||||
|
||||
15
XFIND.md
Normal file
15
XFIND.md
Normal file
@@ -0,0 +1,15 @@
|
||||
[<<back](README.md)
|
||||
|
||||
## Xfind utility
|
||||
|
||||
This utility makes it easier to use find.
|
||||
|
||||
```bash
|
||||
Usage: xfind options term(s)
|
||||
-d, --[no-]debug
|
||||
-n NAME include NAME
|
||||
-N NAME exclude NAME
|
||||
-p PATH include PATH
|
||||
-P PATH exclude PATH
|
||||
-h, --help
|
||||
```
|
||||
12
XGREP.md
12
XGREP.md
@@ -3,3 +3,15 @@
|
||||
## Xgrep utility
|
||||
|
||||
This utility makes it easier to use git-grep.
|
||||
|
||||
```bash
|
||||
Usage: xgrep options term(s)
|
||||
-d, --[no-]debug
|
||||
-f, --file
|
||||
-i, --invert
|
||||
-p, --include-path PATHS
|
||||
-P, --exclude-path PATHS
|
||||
-t, --include-type TYPES
|
||||
-T, --exclude-type TYPES
|
||||
-h, --help
|
||||
```
|
||||
|
||||
@@ -12,8 +12,8 @@ module Xfind
|
||||
options.debug = false
|
||||
options.names = []
|
||||
options.paths = [
|
||||
'.git',
|
||||
'node_modules'
|
||||
{exclude: true, pattern: '.git'},
|
||||
{exclude: true, pattern: 'node_modules'}
|
||||
]
|
||||
|
||||
@option_parser = OptionParser.new do |op|
|
||||
@@ -23,12 +23,20 @@ module Xfind
|
||||
options.debug = argument
|
||||
end
|
||||
|
||||
op.on('-n','--name NAME') do |argument|
|
||||
options.names << argument
|
||||
op.on('-n NAME', 'include NAME') do |argument|
|
||||
options.names << {exclude: false, pattern: argument}
|
||||
end
|
||||
|
||||
op.on('-p','--path PATH') do |argument|
|
||||
options.paths << argument
|
||||
op.on('-N NAME','exclude NAME') do |argument|
|
||||
options.names << {exclude: true, pattern: argument}
|
||||
end
|
||||
|
||||
op.on('-p PATH','include PATH') do |argument|
|
||||
options.paths << {exclude: false, pattern: argument}
|
||||
end
|
||||
|
||||
op.on('-P PATH','exclude PATH') do |argument|
|
||||
options.paths << {exclude: true, pattern: argument}
|
||||
end
|
||||
|
||||
op.on_tail('-h','--help') do |argument|
|
||||
@@ -52,18 +60,37 @@ module Xfind
|
||||
end
|
||||
|
||||
def execute
|
||||
paths = options.paths.map {|x| "! -path '*/#{x}/*'"}.join(' ')
|
||||
|
||||
names = options.names.map {|x| "-name '*.#{x}'"}
|
||||
if names.size > 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
|
||||
|
||||
Reference in New Issue
Block a user