#!/bin/bash | |
DIR=. | |
if [ -n "$1" ] | |
then | |
DIR=$1 | |
fi | |
# Find image files in. | |
FILES=`find $DIR -type f | grep ".*\.\(jpg\|gif\|png\|jpeg\)"` | |
# Default searcher is grep. If Silver Searcher is installed, use that. | |
SEARCHER='grep -r -l ' | |
if command -v ag | |
then | |
# Sweet! Let's use Silver Searcher. | |
SEARCHER='ag -l ' | |
fi | |
# Loop over image files. | |
for f in $FILES | |
do | |
if [[ -f $f ]] | |
then | |
name=$(basename $f) | |
found=$($SEARCHER $name $DIR) | |
if [[ -z $found ]] | |
then | |
echo $f | |
fi | |
fi | |
done |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
stanosmith
commented
Jul 31, 2014
This works well, except when I'm using Silver Searcher (ag version 0.23.0, installed with homebrew) it outputs the location of ag (/usr/local/bin/ag). So if I pipe to xargs rm, ag is removed and I have to relink. I've played with the script a bit to see if I could fix it, but I'm not familiar with shell scripting. Any thoughts? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
selahattinunlu
commented
Mar 8, 2015
Thanks :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works well, except when I'm using Silver Searcher (ag version 0.23.0, installed with homebrew) it outputs the location of ag (/usr/local/bin/ag). So if I pipe to xargs rm, ag is removed and I have to relink. I've played with the script a bit to see if I could fix it, but I'm not familiar with shell scripting. Any thoughts?