all repos — dotfiles @ c8b57d5f847c9d840b3174674a1a083aa0434ef1

my *nix dotfiles

prompt: clean up
Anirudh Oppiliappan x@icyphox.sh
Thu, 24 Feb 2022 11:34:48 +0530
commit

c8b57d5f847c9d840b3174674a1a083aa0434ef1

parent

b3cf48f70b54896e5137dc4e545317fd5f3cc13c

2 files changed, 8 insertions(+), 24 deletions(-)

jump to
M prompt/git.goprompt/git.go

@@ -24,31 +24,31 @@ }

} // Returns the current git branch or current ref sha. -func getGitBranch(repo *git.Repository, ch chan<- string) { +func getGitBranch(repo *git.Repository) string { ref, _ := repo.Head() // Quick hack to fix crash when ref is nil; // i.e., new repo with no commits. if ref == nil { - ch <- "no commit" + return "no commit" } if ref.IsBranch() { name, _ := ref.Branch().Name() - ch <- name + return name } else { - ch <- ref.Target().String()[:8] + return ref.Target().String()[:8] } } // Returns • if clean, else ×. -func getGitStatus(repo *git.Repository, ch chan<- string) { +func getGitStatus(repo *git.Repository, clean, dirty string) string { sl, _ := repo.StatusList(&git.StatusOptions{ Show: git.StatusShowIndexAndWorkdir, Flags: git.StatusOptIncludeUntracked, }) n, _ := sl.EntryCount() if n != 0 { - ch <- "×" + return dirty } else { - ch <- "•" + return clean } }
M prompt/prompt.goprompt/prompt.go

@@ -22,28 +22,13 @@ path = cwd

return path } return path - // items := strings.Split(path, "/") - // truncItems := []string{} - // for i, item := range items { - // if i == (len(items) - 1) { - // truncItems = append(truncItems, item) - // break - // } - // truncItems = append(truncItems, item[:1]) - // } - // return filepath.Join(truncItems...) } func main() { - - help := `usage: prompt OPTIONS PATH - -p path to truncate - -gb git branch - -gs git status` if len(os.Args) != 3 { - fmt.Println(help) os.Exit(1) } + gitDir := getGitDir(os.Args[2]) switch os.Args[1] { case "-p":

@@ -68,7 +53,6 @@ fmt.Print(<-statusCh)

} fmt.Print("") default: - fmt.Println(help) os.Exit(1) } }