Created
April 12, 2014 07:53
-
-
Save thirdreplicator/10523756 to your computer and use it in GitHub Desktop.
Bash script to fuzzy find files and copy file name to clip board if there is only 1 result.
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
# Usage example: | |
# f entry factory tests | |
# vi <CTRL-V> | |
# | |
# You can change the filtered directories and file types in the first line of the function. | |
# | |
# Find groovy files and copy the unique result to the clip board. | |
function f() { | |
files=`find grails-app src test -name "*.groovy" -type f` | |
for pat in "$@" | |
do | |
files=`echo "$files" | grep -i $pat` | |
done | |
lines=`echo "$files" | wc -l | tr -s ' ' | cut -d ' ' -f 2` | |
#echo "lines: $lines" | |
if [ $lines -eq 1 ]; then | |
result=`echo $files | tee /dev/tty | tr -d '\n'` | |
size_result=`echo $result | wc -c | tr -s ' ' | cut -d ' ' -f 2` | |
if [ $size_result -gt 1 ]; then | |
echo $result | tr -d '\n' | pbcopy | |
fi | |
else | |
echo "$files" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment