status: Major cleanup of status
[guilt.git] / guilt-status
blob3ffd31618bcb499eea8cac7f3f9739b040e39fea
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[-a|-A] [-c|-C] [-d|-D] [-m|-M] [-r|-R] [-t|-T] [-u|-U] [-x|-X]"
7 . guilt
9 untracked=""
10 DIFF_FILTER=""
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 -a|-A)
14 DIFF_FILTER="A$DIFF_FILTER"
16 -c|-C)
17 DIFF_FILTER="C$DIFF_FILTER"
19 -d|-D)
20 DIFF_FILTER="D$DIFF_FILTER"
22 -m|-M)
23 DIFF_FILTER="M$DIFF_FILTER"
25 -r|-R)
26 DIFF_FILTER="R$DIFF_FILTER"
28 -t|-T)
29 DIFF_FILTER="T$DIFF_FILTER"
31 -u|-U)
32 DIFF_FILTER="U$DIFF_FILTER"
34 -x|-X)
35 untracked="t"
36 DIFF_FILTER="X$DIFF_FILTER"
39 usage
41 esac
42 shift
43 done
45 # default status displays all
46 if [ -z "$DIFF_FILTER" ]; then
47 untracked="t"
48 DIFF_FILTER="ACDMRT"
51 git-rev-parse --verify HEAD >/dev/null 2>&1 || IS_INITIAL=t
53 function print_status
55 while read status name newname
57 case "$status" in
58 A*) echo "A $name";;
59 C*) echo "C $name -> $newname";;
60 D*) echo "D $name";;
61 M ) echo "M $name";;
62 R*) echo "R $name -> $newname";;
63 T ) echo "T $name";;
64 U ) echo "U $name";;
65 ? ) echo "? $name";;
66 esac
67 done
71 # untracked; FIXME: there's got to be a better way
72 if [ ! -z "$untracked" ]; then
73 if [ -f "$GIT_DIR/info/exclude" ]; then
74 git-ls-files -z --others \
75 --exclude-from="$GIT_DIR/info/exclude" \
76 --exclude-per-directory=.gitignore
77 else
78 git-ls-files -z --others --exclude-per-directory=.gitignore
79 fi | xargs -0 -L 1 echo | while read n; do
80 [ -z "$n" ] && continue
81 echo "$n" | sed -e "s/^/?\t/"
82 done
85 # added
86 if [ -z "$IS_INITIAL" ]; then
87 # non-initial commit
88 git-diff-index -M --name-status --diff-filter=$DIFF_FILTER HEAD
89 else
90 # initial commit
91 git-ls-files | sed -e "s/^/A\t/"
92 fi | sed -e '
93 s/\\/\\\\/g
94 s/ /\\ /g
96 ) | print_status