Skip to content

Commit

Permalink
🔀Added Updates for Staged Files and Refactors (#23)
Browse files Browse the repository at this point in the history
* Update README.md

* Refactors

* SSH Refactor
  • Loading branch information
athul authored Jan 15, 2020
1 parent 56e0dc5 commit 0fbb379
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ PROMPT=$'%(?.%{\e[92m%}.%{\e[91m%})${prompt_symbol}%f'
### Extra Bits
- Displays the Current Git Branch
- `` shows if any staged files are present
- `[+]` shows if you've got Untracked Files
- `[2+]` shows if you've got 2 untracked files
- `[!]` shows if you've got Unstaged Files
Expand Down
2 changes: 1 addition & 1 deletion mods/directories.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func getDir(cwd string) string {
status := make(chan string)
go dispstats(isconmod, pathToDisplay, gitDir, status)
imod := <-status
return imod + color.Sprintf(color.BrightBlack, "("+env+")")
return imod + color.Sprintf(color.BrightBlack, "(%s)", env)
}
if gitDir != "" {
isconmod := iscontentmodified(gitDir)
Expand Down
31 changes: 14 additions & 17 deletions mods/display.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
package mods

import (
"fmt"
"strconv"

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

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": "⇅",
"ahead": "↑",
"behind": "↓",
"diverged": "⇅",
}
ius := "!"
itr := "+"
nstg_count := strconv.Itoa(m.notStaged)
ntrc_count := strconv.Itoa(m.untracked)
stg := "✔"
//nstgcount := strconv.Itoa(m.notStaged)
//ntrccount := 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))
status <- nm + color.Sprintf(color.BrightRed, " [%d%s][%d%s] %s", m.notStaged, ius, m.untracked, itr, stt)
}
if !m.utrbool && m.ustbool {
status <- nm + color.Sprintf(color.BrightRed, fmt.Sprintf(" [%s%s] %s", nstg_count, ius, stt))
status <- nm + color.Sprintf(color.BrightRed, " [%d%s] %s", m.notStaged, ius, stt)
}
if m.utrbool && !m.ustbool {
status <- nm + color.Sprintf(color.BrightRed, fmt.Sprintf(" [%s%s] %s", ntrc_count, itr, stt))
status <- nm + color.Sprintf(color.BrightRed, " [%d%s] %s", m.untracked, itr, stt)
}
if !m.ustbool && !m.utrbool && m.staged {
status <- nm + color.Sprintf(color.BrightMagenta, " %s %s ", stg, stt)
}
if !m.ustbool && !m.utrbool {
status <- nm + color.Sprintf(color.BrightBlue, " "+stt)
status <- nm + color.Sprintf(color.BrightBlue, " %s", stt)
}

}
9 changes: 6 additions & 3 deletions mods/env_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ func gethost() (string, string) {
uname := os.Getenv("USER")
return uname, strings.SplitN(hname, ".", 2)[0]
}
func isssh(probs chan bool) {
func isssh() bool {
var probs bool
cmd := os.Getenv("SSH_CLIENT")
if cmd != "" {
probs <- true
probs = true
return probs
}
probs <- false
probs = false
return probs
}
func getenv() string {
env := os.Getenv("VIRTUAL_ENV")
Expand Down
20 changes: 7 additions & 13 deletions mods/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ismodified struct {
ustbool bool
untracked int
notStaged int
staged int
staged bool
state string
}

Expand Down Expand Up @@ -88,8 +88,7 @@ func parseGitStats(status []string) ismodified {
stats.utrbool = true
default:
if code[0] != ' ' {
stats.staged++

stats.staged = true
}
if code[1] != ' ' {
stats.notStaged++
Expand All @@ -104,18 +103,13 @@ func parseGitStats(status []string) ismodified {
func iscontentmodified(path string) ismodified {
out, err := rungitcommands("git", "status", "--porcelain", "-b", "--ignore-submodules")
status := strings.Split(out, "\n")
if err != nil {

}
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 {
if strings.Contains(out, ",") {
stats.state = "diverged"
} else if strings.Contains(out, "behind") {
stats.state = "behind"
} else if strings.Contains(outstat, "diverged") == true {
stats.state = "both"
} else if strings.Contains(out, "ahead") {
stats.state = "ahead"
} else {
stats.state = "clean"
}
Expand Down
5 changes: 2 additions & 3 deletions mods/home_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ func emptifier(list []string, val string) []string {
return append(list, val)
}
func stripHomeDir(path string) string {
ssh := make(chan bool)
go isssh(ssh)
sshtrue := <-ssh

sshtrue := isssh()
name, host := gethost()
if sshtrue == true {
return strings.Replace(path, os.Getenv("HOME"), color.Sprintf(color.BrightGreen, name+" on "+host)+" ~", 1)
Expand Down

0 comments on commit 0fbb379

Please sign in to comment.