I received a great function for highlighting files in Apple's finder using the command-line. It's basically a wrapper for osascript.
I got it from Mac OS X: How to change the color label of files from the Terminal and it looks like this,
# Set Finder label color
label(){
if [ $# -lt 2 ]; then
echo "USAGE: label [0-7] file1 [file2] ..."
echo "Sets the Finder label (color) for files"
echo "Default colors:"
echo " 0 No color"
echo " 1 Orange"
echo " 2 Red"
echo " 3 Yellow"
echo " 4 Blue"
echo " 5 Purple"
echo " 6 Green"
echo " 7 Gray"
else
osascript - "$@" << EOF
on run argv
set labelIndex to (item 1 of argv as number)
repeat with i from 2 to (count of argv)
tell application "Finder"
set theFile to POSIX file (item i of argv) as alias
set label index of theFile to labelIndex
end tell
end repeat
end run
EOF
fi
}
I put it in via vim .bash_profile
, ran source .bash_profile
and was able to run the function with label 2 /Users/brett/Desktop/test.txt
. Perfect.
But what if I'm updating all our old PHP mysql_query( statements to PDO and I want to visually highlight the files I need to edit?
I would normally run,
find /Users/brett/Development/repos/my-repo/ -name "*.php" -print0 | xargs -0 grep -Iil 'mysql_query(' | xargs -I '{}' -n 1 label 2 {}
But it returns,
xargs: label: No such file or directory
I read that I should try running export -f label
, but that doesn't seem to help either.
Does anyone know how I can pipe paths/files from grep
through xargs
to a .bash_profile function?
xargs
can not execute functions.