Skip to content

Commit

Permalink
📝Updates for Ahead or Behind (#17)
Browse files Browse the repository at this point in the history
* Basic Updates

* i1

* Trying on git2go

* Trying on git2go

* All in One

* Made the Ahead Behind Arrows working

* Tidy Up

* Added `clean` state

* Update README.md

* Clean Icon

* Refactors

* Updated GIF

* Git Repo Full PAth Display
  • Loading branch information
athul authored Jan 10, 2020
1 parent 6c22dec commit 5ca8933
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 42 deletions.
17 changes: 0 additions & 17 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

</div>

Shelby is a fast ⚡️ ,lightweight 🎈 ,minimal✨, shell prompt written in Pure Go.
Shelby is a fast ⚡️ ,lightweight ☁️ ,minimal✨, shell prompt written in Pure Go.

![](assets/shelby.gif)

Expand Down
Binary file modified assets/shelby.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions mods/directories.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ func getDir(cwd string) string {

pathToDisplay := stripHomeDir(cwd)
//pathToDisplay = shortenLongPath(pathToDisplay, 2)
gbpath := pathToDisplay[strings.LastIndex(pathToDisplay, "/")+1:]
//gbpath := pathToDisplay[strings.LastIndex(pathToDisplay, "/")+1:]
gitDir, err := findGitRepo(cwd)
handleError(err)
env := getenv()
isconmod := iscontentmodified(gitDir)

if gitDir != "" && env != "" && env != "." {
isconmod := iscontentmodified(gitDir)
status := make(chan string)
go findstatus(isconmod, gbpath, gitDir, status)
go dispstats(isconmod, pathToDisplay, gitDir, status)
imod := <-status
return imod + color.Sprintf(color.BrightBlack, "("+env+")")
}
if gitDir != "" {
isconmod := iscontentmodified(gitDir)
status := make(chan string)
go findstatus(isconmod, gbpath, gitDir, status)
go dispstats(isconmod, pathToDisplay, gitDir, status)
imod := <-status
return imod
}
Expand Down
41 changes: 27 additions & 14 deletions mods/display.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
package mods

import (
"fmt"
"strconv"

"github.com/talal/go-bits/color"
)

func findstatus(mods ismodified, path string, gdir string, status chan string) {
branchchannel := make(chan string)
go currentGitBranch(gdir, branchchannel)
branch := <-branchchannel
nm := color.Sprintf(color.BrightYellow, path) + " on " + color.Sprintf(color.BrightGreen, ` `+branch)
switch {
case mods.notStaged != 0 && mods.untracked != 0:
status <- nm + color.Sprintf(color.BrightRed, ` [`+strconv.Itoa(mods.notStaged)+`!]`+`[`+strconv.Itoa(mods.untracked)+`+]`)
case mods.notStaged != 0:
status <- nm + color.Sprintf(color.BrightRed, ` [`+strconv.Itoa(mods.notStaged)+`!]`)
case mods.untracked != 0:
status <- nm + color.Sprintf(color.BrightRed, ` [`+strconv.Itoa(mods.untracked)+`+]`)
default:
status <- nm
func dispstats(m ismodified, path string, gdir string, status chan string) {
branch := currentGitBranch(gdir)
nm := color.Sprintf(color.BrightGreen, path) + " on " + color.Sprintf(color.BrightYellow, ` `+branch)
states := map[string]string{
"ahead": "↑",
"behind": "↓",
"both": "⇅",
}
ius := "!"
itr := "+"
nstg_count := strconv.Itoa(m.notStaged)
ntrc_count := strconv.Itoa(m.untracked)
stt := states[m.state]

if m.utrbool && m.ustbool {
status <- nm + color.Sprintf(color.BrightRed, fmt.Sprintf(" [%s%s][%s%s] %s", nstg_count, ius, ntrc_count, itr, stt))
}
if !m.utrbool && m.ustbool {
status <- nm + color.Sprintf(color.BrightRed, fmt.Sprintf(" [%s%s] %s", nstg_count, ius, stt))
}
if m.utrbool && !m.ustbool {
status <- nm + color.Sprintf(color.BrightRed, fmt.Sprintf(" [%s%s] %s", ntrc_count, itr, stt))
}
if !m.ustbool && !m.utrbool {
status <- nm + color.Sprintf(color.BrightBlue, " "+stt)
}

}
34 changes: 30 additions & 4 deletions mods/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import (
"strings"
)

var dir string = cwdir()

type ismodified struct {
utrbool bool
ustbool bool
untracked int
notStaged int
staged int
state string
}

func findGitRepo(path string) (string, error) {
Expand All @@ -34,21 +40,21 @@ func findGitRepo(path string) (string, error) {

return gitEntry, nil
}
func currentGitBranch(gitDir string, c1 chan string) {
func currentGitBranch(gitDir string) string {
bytes, err := ioutil.ReadFile(filepath.Join(gitDir, "HEAD"))
if err != nil {
handleError(err)
c1 <- "unknown"
return "unknown"
}
refSpec := strings.TrimSpace(string(bytes))

// detached HEAD?
if !strings.HasPrefix(refSpec, "ref: refs/") {
c1 <- "detached"
return "detached"
}

branch := strings.TrimPrefix(refSpec, "ref: refs/heads/")
c1 <- branch
return branch
}
func gitProcessEnv() []string {
home, _ := os.LookupEnv("HOME")
Expand Down Expand Up @@ -79,9 +85,15 @@ func parseGitStats(status []string) ismodified {
switch code {
case "??":
stats.untracked++
stats.utrbool = true
default:
if code[0] != ' ' {
stats.staged++

}
if code[1] != ' ' {
stats.notStaged++
stats.ustbool = true
}
}
}
Expand All @@ -96,6 +108,20 @@ func iscontentmodified(path string) ismodified {

}
stats := parseGitStats(status)
outstat, err := rungitcommands("git", "status", "-u", "no")

if strings.Contains(outstat, "ahead") {
stats.state = "ahead"
} else if strings.Contains(outstat, "behind") == true {
stats.state = "behind"
} else if strings.Contains(outstat, "diverged") == true {
stats.state = "both"
} else {
stats.state = "clean"
}
if err != nil {

}
return stats

}
3 changes: 1 addition & 2 deletions mods/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ func Info() string {

info := make([]string, 1)
info = emptifier(info, getDir(cwd))
return strings.Join(info, " ")

return strings.Join(info, "")
}

0 comments on commit 5ca8933

Please sign in to comment.