@@ -10,33 +10,50 @@ import (
1010)
1111
1212// TODO: implement random color func
13- // TODO: Add flag -b branch -m modidied -d deleted -u untraced (-bmdu)
1413
1514func main () {
16- vers := flag .Bool ("v" , false , "get the version" )
15+ vers := flag .Bool ("v" , false , "get the version" )
16+ status := flag .Bool ("status" , false , "formatting git status if any" )
17+ branch := flag .Bool ("b" , false , "get active branch" )
18+ modified := flag .Bool ("m" , false , "get number of tracked modified files" )
19+ deleted := flag .Bool ("d" , false , "get number of tracked deleted files" )
20+ untracked := flag .Bool ("u" , false , "get number of untracked files" )
21+ color := flag .Bool ("c" , false , "color the status output" )
1722
18- status := flag .Bool ("status" , false , "formatting git status if any" )
1923 flag .Parse ()
2024 if * vers == true {
21- fmt .Println ("Git Prettier version v0.0.2 " )
25+ fmt .Println ("Git Prettier version v0.0.3 " )
2226 os .Exit (1 )
2327 }
2428 if * status {
25- nMod , nDel , nUntr := gitStatus ()
29+ nMod , nDel , isUntr := gitStatus ()
2630 branch := gitBranch ()
27-
2831 if branch == "" { os .Exit (1 ) }
29-
30- fmtStats := fmtResults (branch , nMod , nDel , nUntr )
32+ var fmtStats string
33+ if * color {
34+ fmtStats = fmtResultsColor (branch , nMod , nDel , isUntr )
35+ } else {
36+ fmtStats = fmtResults (branch , nMod , nDel , isUntr )
37+ }
3138 fmt .Println (fmtStats )
3239 }
40+ if * branch { fmt .Println (gitBranch ()) }
41+ if * modified {
42+ if nMod , _ , _ := gitStatus (); nMod > 0 { fmt .Printf ("+%v\n " , nMod ) }
43+ }
44+ if * deleted {
45+ if _ , nDel , _ := gitStatus (); nDel > 0 { fmt .Printf ("-%v\n " , nDel ) }
46+ }
47+ if * untracked {
48+ if _ , _ , isUntr := gitStatus (); isUntr { fmt .Println ("U…" ) }
49+ }
3350}
3451
3552func gitBranch () (string ){
3653 cmd := exec .Command ("git" , "branch" )
3754 output , err := cmd .Output ()
3855 if err != nil {}
39- rBranch := regexp .MustCompile (`^ \*\s.*` )
56+ rBranch := regexp .MustCompile (`\*\s.*` )
4057 branch := rBranch .FindAllString (string (output [:]), 1000 )
4158 branch = strings .Split (strings .Join (branch , "" ), "* " )
4259 parsBranch := strings .Join (branch , "" )
@@ -47,18 +64,29 @@ func gitStatus() (int, int, bool){
4764 cmd := exec .Command ("git" , "status" )
4865 output , err := cmd .Output ()
4966 if err != nil {}
50- rMod := regexp .MustCompile (`modified:` )
51- nMod := len (rMod .FindAllString (string (output [:]), 1000 ))
67+ rMod := regexp .MustCompile (`modified:` )
68+ nMod := len (rMod .FindAllString (string (output [:]), 1000 ))
69+ rNew := regexp .MustCompile (`new file:` )
70+ nNew := len (rNew .FindAllString (string (output [:]), 1000 ))
71+ nMod = nMod + nNew
5272 rDel := regexp .MustCompile (`deleted:` )
5373 nDel := len (rDel .FindAllString (string (output [:]), 1000 ))
54- rNew := regexp .MustCompile (`new file:` )
55- nNew := len (rNew .FindAllString (string (output [:]), 1000 ))
5674 rUntr := regexp .MustCompile (`Untracked files:` )
57- nMod = nMod + nNew
5875 return nMod , nDel , rUntr .MatchString (string (output [:]))
5976}
6077
6178func fmtResults (branch string , nMod int , nDel int , isUntr bool ) (string ) {
79+ stats := "["
80+ stats += branch
81+ if nMod > 0 || nDel > 0 { stats += " |" }
82+ if nMod > 0 { stats = fmt .Sprint (stats , " +" , nMod ) }
83+ if nDel > 0 { stats = fmt .Sprint (stats , " -" , nDel ) }
84+ if isUntr { stats = fmt .Sprint (stats , " U…" ) }
85+ stats += "]"
86+ return stats
87+ }
88+
89+ func fmtResultsColor (branch string , nMod int , nDel int , isUntr bool ) (string ) {
6290 RED := "\033 [91m"
6391 BLUE := "\033 [34m"
6492 GREEN := "\033 [32m"
0 commit comments