-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsvn-color.sh
executable file
·84 lines (72 loc) · 2 KB
/
svn-color.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
function svn
{
# rebuild args to get quotes right
CMD=
for i in "$@"
do
if [[ "$i" =~ \ ]]
then
CMD="$CMD \"$i\""
else
CMD="$CMD $i"
fi
done
# pad with spaces to strip --nocol
CMD=" $CMD "
CMDLEN=${#CMD}
# parse disabling arg
CMD="${CMD/ --nocol / }"
# check if disabled
test "$CMDLEN" = "${#CMD}"
NOCOL=$?
if [ "$SVN_COLOR" != "always" ] && ( [ $NOCOL = 1 ] || [ "$SVN_COLOR" = "never" ] || [ ! -t 1 ] )
then
eval $(which svn) $CMD
return
fi
# supported svn actions for "status-like" output
ACTIONS="add|checkout|co|cp|del|export|remove|rm|st"
ACTIONS="$ACTIONS|merge|mkdir|move|mv|ren|sw|up"
# actions that outputs "status-like" data
if [[ "$1" =~ ^($ACTIONS) ]]
then
eval $(which svn) $CMD | while IFS= read -r RL
do
if [[ $RL =~ ^\ ?M ]]; then C="\033[34m";
elif [[ $RL =~ ^\ ?C ]]; then C="\033[41m\033[37m\033[1m";
elif [[ $RL =~ ^A ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^D ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^X ]]; then C="\033[37m";
elif [[ $RL =~ ^! ]]; then C="\033[43m\033[37m\033[1m";
elif [[ $RL =~ ^I ]]; then C="\033[33m";
elif [[ $RL =~ ^R ]]; then C="\033[35m";
else C=
fi
echo -e "$C${RL/\\/\\\\}\033[0m\033[0;0m"
done
# actions that outputs "diff-like" data
elif [[ "$1" =~ ^diff ]]
then
eval $(which svn) $CMD | while IFS= read -r RL
do
if [[ $RL =~ ^Index:\ ]]; then C="\033[34m\033[1m";
elif [[ $RL =~ ^@@ ]]; then C="\033[37m";
# removed
elif [[ $RL =~ ^-\<\<\< ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^-\>\>\> ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^-=== ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^- ]]; then C="\033[31m";
# added
elif [[ $RL =~ ^\+\<\<\< ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^\+\>\>\> ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^\+=== ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^\+ ]]; then C="\033[32m";
else C=
fi
echo -e "$C${RL/\\/\\\\}\033[0m\033[0;0m"
done
else
eval $(which svn) $CMD
fi
}