-
-
Save timyates/149068 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
#!/usr/bin/env groovy | |
// Trying it in Groovy as a shell script (just for fun) | |
import java.util.regex.Pattern | |
// All folders on the path which have contents: | |
path = System.env[ 'PATH' ] | |
.tokenize( File.pathSeparator ) | |
.collect( { new File( it ) } ) | |
.findAll { it.directory && it.listFiles() } | |
args.collect { it.toLowerCase() }.each { name -> | |
println "--- $name --->" | |
counter = 0 | |
path.each { folder -> | |
children = folder.list() | |
found = children.findAll { child -> | |
child.toLowerCase().indexOf( name ) > -1 | |
|| Pattern.compile( name, Pattern.CASE_INSENSITIVE ).matcher( child ).find() | |
} | |
if( found ) { | |
if( folder.getAbsolutePath().indexOf( " " ) > -1 ) { | |
println "\"$folder\":" | |
} | |
else { | |
println "$folder:" | |
} | |
println " ${found.join ', '}" | |
} | |
counter += found.size | |
} | |
println() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment