-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-datus
executable file
·67 lines (62 loc) · 1.27 KB
/
git-datus
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
#!/bin/bash
case `uname` in
Linux|CYGWIN*) ECHO="echo -e" ;;
*) ECHO="echo" ;;
esac
usage() {
$ECHO "git datus [options]"
$ECHO
$ECHO "Options:"
$ECHO "-u[mode] \tshow untracked files (mode = no, normal, all)"
$ECHO "-l,--long \tshow long timestamp"
$ECHO "-h,--help \tshow this message and exit"
$ECHO "-- \tseparator; anything after this will be passed to git status"
exit $1
}
UARG=""
LONGTIME=""
while [ $# -gt 0 ]; do
case $1 in
-u*)
UARG=$1
shift
;;
-l|--long)
LONGTIME=true
shift
;;
-h|--help)
HELP=true
shift
;;
--)
shift
break
;;
-*)
$ECHO "Unknown option $1"
usage 1
;;
esac
done
if [ "$HELP" == "true" ]; then
usage 0
fi
GITARGS="$@"
# handles moved or deleted files, keeps track of staging
git status -s $UARG $GITARGS | while IFS= read -r; do
mode=${REPLY:0:2}
unset IFS; read -r junk file <<< "$REPLY"
afile=($file)
nowfile=${afile[${#afile[@]}-1]}
if [ -f $nowfile ]; then
if [ -n "$LONGTIME" ]; then
datestr=$(stat -c %y $nowfile)
else
datestr=$(date -d "$(stat -c %y $nowfile)" '+%F %T')
fi
else
datestr="---"
fi
echo "$mode" "$datestr" "$file"
done | sort -k1.4