-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocmt.sh
50 lines (45 loc) · 1.22 KB
/
autocmt.sh
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
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
if [ $# == 0 ]; then
echo "No arguments specified"
echo ""
# ^ how to line break
echo "Usage:"
echo "autocmt ~/Documents/myrepo"
exit
fi
if [ -d $1 ]; then
cd $1
if [ ! -d .git ]; then
echo "This is not a repository"
exit
fi
else
echo "Invalid directory"
exit
fi
declare -i a
#git restore --staged .
git reset HEAD .
git status --porcelain | grep -E '[AM]?[^\?]\s+.*' | cut -c4- > /tmp/autocmt.lst
echo -n "autocmt: " > /tmp/autocmt.msg
for MODFILES in $(</tmp/autocmt.lst)
do
echo -n "$MODFILES: ..." >> /tmp/autocmt.msg
a=$RANDOM/4000+1
echo -n $((git diff --word-diff -U0 $MODFILES 2>&1 | grep -E "{\+.+\+}" | sed -E 's/\s?(\[-.*-\])?\{\+//' | sed -E 's/\+\}//') | cut -c$a-$(echo "$a+16" | bc)) >> /tmp/autocmt.msg
# stupid thing --> | awk -F: '{ printf $1}' |
echo -n "... " >> /tmp/autocmt.msg
done
git status --porcelain | grep -E '\?\?\s+.*' | cut -c4- > /tmp/autocmt.lst
for NEWFILES in $(</tmp/autocmt.lst)
do
echo -n "$NEWFILES: ..." >> /tmp/autocmt.msg
a=$RANDOM/4000+1
echo -n $(awk -F: '{ printf $1 }' $NEWFILES | cut -c$a-$(echo "$a+16" | bc)) >> /tmp/autocmt.msg
echo -n "... " >> /tmp/autocmt.msg
done
git add .
git commit -m "$(</tmp/autocmt.msg)"
if [ "$2" == "-p" ]; then
git push
fi