tidy and readme
This commit is contained in:
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# gitcheck
|
||||||
|
Basic cli utils to check if any projects have uncommited changes
|
||||||
87
main.go
87
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,11 +12,48 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
defaultDir = "."
|
||||||
green = "\033[32m"
|
green = "\033[32m"
|
||||||
red = "\033[31m"
|
red = "\033[31m"
|
||||||
reset = "\033[0m"
|
reset = "\033[0m"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
args := flag.Args()
|
||||||
|
|
||||||
|
dir := defaultDir
|
||||||
|
if len(args) > 0 {
|
||||||
|
dir = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
path, err := expandTilde(dir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range entries {
|
||||||
|
cpath := filepath.Join(path, d.Name())
|
||||||
|
|
||||||
|
status, err := getStatus(cpath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(cpath)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !status.IsClean() {
|
||||||
|
fmt.Printf("%s%s (%v)%s\n", green, cpath, len(status), reset)
|
||||||
|
} else {
|
||||||
|
fmt.Println(cpath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getStatus(repoPath string) (git.Status, error) {
|
func getStatus(repoPath string) (git.Status, error) {
|
||||||
repo, err := git.PlainOpen(repoPath)
|
repo, err := git.PlainOpen(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -42,52 +80,3 @@ func expandTilde(path string) (string, error) {
|
|||||||
}
|
}
|
||||||
return filepath.Join(home, path[1:]), nil
|
return filepath.Join(home, path[1:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
// dirPath := flag.String("dir", ".", "path to directory")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
args := flag.Args()
|
|
||||||
dir := "."
|
|
||||||
if len(args) > 0 {
|
|
||||||
// log.Fatal("usage: gitcheck <dirpath>")
|
|
||||||
dir = args[0]
|
|
||||||
}
|
|
||||||
path, err := expandTilde(dir)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
entries, err := os.ReadDir(path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
for _, d := range entries {
|
|
||||||
cpath := filepath.Join(path, d.Name())
|
|
||||||
// fmt.Println(cpath)
|
|
||||||
// p, err := os.Stat(cpath)
|
|
||||||
if err != nil {
|
|
||||||
// fmt.Println(err)
|
|
||||||
fmt.Println(cpath)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// if !p.IsDir() {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
status, err := getStatus(cpath)
|
|
||||||
if err != nil {
|
|
||||||
// fmt.Println(err)
|
|
||||||
fmt.Println(cpath)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// fmt.Println("----------")
|
|
||||||
// pp.Println(res)
|
|
||||||
// fmt.Printf("%v: %v \n", cpath, res)
|
|
||||||
if !status.IsClean() {
|
|
||||||
fmt.Printf("%s%s (%v)%s\n", green, cpath, len(status), reset)
|
|
||||||
// fmt.Println(status.String())
|
|
||||||
} else {
|
|
||||||
fmt.Println(cpath)
|
|
||||||
// fmt.Printf("%s%s%s\n", red, cpath, reset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user