public
Last active

  • Download Gist
dont-mate-your-root.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
## Tom's Magical "Don't Mate Your Root" Script
# Prevents "mate /" from crashing your Mac.
 
function mateforce(){
`which mate` $*
}
 
function line_count_less_than(){
ruby -e "
max_count = ARGV.first.to_i
count = 0
 
while STDIN.gets
count += 1
exit 1 if count > max_count
end
exit 0
" $*
}
 
 
function mate(){
if find $* -type f | grep -v '.git' | line_count_less_than 10000
then
mateforce $*
else
echo "Too many files!"
echo "If you are sure you wish to do this, then please use mateforce"
false
fi
}
 
function m(){
if [ -z $1 ]
then
mate .
else
mate $*
fi
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.