82 lines
1.5 KiB
Bash
Executable file
82 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
function elem_in_array()
|
|
{
|
|
for cur in $2
|
|
do
|
|
if [ "$1" == "$cur" ]
|
|
then
|
|
echo "1"
|
|
return 1
|
|
fi
|
|
done
|
|
echo "0"
|
|
return 0
|
|
}
|
|
|
|
function array_in_array()
|
|
{
|
|
for cur in $1
|
|
do
|
|
match=$(elem_in_array "$cur" "$2")
|
|
if [ "$match" -ne 1 ]
|
|
then
|
|
echo "0"
|
|
return 0
|
|
fi
|
|
done
|
|
echo "1"
|
|
return 1
|
|
}
|
|
|
|
word=$(git status -s | sed 's/.* //')
|
|
red="\033[38;5;1m"
|
|
gre="\033[38;5;2m"
|
|
cya="\033[38;5;6m"
|
|
res="\033[0m"
|
|
|
|
for i in $word
|
|
do
|
|
if [ -e $i ]
|
|
then
|
|
if [ -f $i ]
|
|
then
|
|
diff=$(git diff -U0 --exit-code --color $i)
|
|
if [ "$?" -eq 1 ]
|
|
then
|
|
nb_lines=$(echo "$diff" | wc -l)
|
|
if [ "$nb_lines" -eq 7 ]
|
|
then
|
|
match=$(array_in_array "-9 +9 Updated: by ### ########.fr" "$diff")
|
|
if [ $match -eq 1 ]
|
|
then
|
|
echo "\n$cya CHANGES on $i :$res"
|
|
echo "$diff"
|
|
echo "$cya Are you sure?$res"
|
|
read -r -p " [y/N]" response
|
|
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
|
|
then
|
|
i_tmp=$(echo $i | sed 's/\//_/g')
|
|
cp $i "$HOME/Documents/.$i_tmp.back"
|
|
git checkout $i
|
|
echo "$gre D - O - N - E $res"
|
|
echo "$cya $i was checked out. A copy still exist in $HOME/Documents/.$i_tmp.back$res\n"
|
|
else
|
|
echo "$cya Nothing done for $i$res\n"
|
|
fi
|
|
else
|
|
echo "$gre$i is not concerned (diff on the good lines)$res"
|
|
fi
|
|
else
|
|
echo "$gre$i is not concerned (diff is too big)$res"
|
|
fi
|
|
else
|
|
echo "$gre$i is not concerned (diff is null)$res"
|
|
fi
|
|
else
|
|
echo "$red$i is not a regular file$res"
|
|
fi
|
|
else
|
|
echo "$red$i doesn't exist$res"
|
|
fi
|
|
done
|