Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 81 lines (69 sloc) 1.66 KB
#!/bin/bash
function c () {
local a
(( $# > 0 )) && a="$@" || read -r -p "calc: " a
bc -l <<< "$a"
}
function round()
{
echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
};
function print_output (){
#Find file size
var=$(stat -c%s "$2")
mb=$(bc <<< 'scale=2; '$var'/1000000')
#Colors
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
NC=`tput sgr0`
#Display file depending on git status
case $1 in
M*) echo "${RED}Modified${NC}: $2 - $mb mb" ;;
A*) echo "${GREEN}Added${NC}: $2 - $mb mb" ;;
U*) echo "${GREEN}Updated${NC}: $2 - $mb mb" ;;
D*) echo "${RED}Deleted${NC}: $2 - $mb mb" ;;
C*) echo "${YELLOW}Copied${NC}: $2 - $mb mb" ;;
R*) echo "${RED}Renamed${NC}: $2 - $mb mb" ;;
'??') echo "${RED}Untracked${NC}: $2 - $mb mb" ;;
esac
test=$(bc <<< 'scale=0; '$var'/1000000')
echo $test
if (($test > 100))
then
return 1
else
return 0
fi
}
function add_files()
{
echo $(touch .gitignore)
while read status; do
file=$(cut -d " " -f 2 <<< "$status")
var=$(stat -c%s "$file")
mb=$(bc <<< 'scale=0; '$var'/1000000')
if (($mb > 100))
then
echo $file >> .gitignore
fi
done < <( git status --porcelain )
}
large_files=()
while read status_file; do
print_output $status_file
large_files+=( $? )
done < <( git status --porcelain )
for i in ${large_files[@]};
do
echo $i
if (($i == 1))
then
read -p "Do you want to add your large files to your .gitignore? [Y/N] " answer
case $answer in
[Yy]* ) add_files; break;;
[Nn]* ) exit;;
* ) echo "Please answer Y or N.";;
esac
fi
done