Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
repejota committed Sep 7, 2016
2 parents eb82414 + 0dc2320 commit de83e78
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
21 changes: 21 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

const (
// Current username
USER = "\\u"

// Current hostname
HOSTNAME = "\\H"

// User and Hostname
USER_HOSTNAME = USER + "@" + HOSTNAME

// Current path
PATH = "\\w"

// Prompt : $ or users and # for root
PROMPT = "\\$"

// Number of jobs of this session
JOBS = "\\j"
)
11 changes: 11 additions & 0 deletions contrib/256backgrounds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# tputcolors

echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"

for i in $(seq $1 256); do
echo " $(tput setab $i)Text$(tput sgr0) $(tput bold)$(tput setab $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setab $i)Text$(tput sgr0) \$(tput setab $i)"
done

echo
14 changes: 14 additions & 0 deletions contrib/256colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# tputcolors

echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"

for i in $(seq 1 256); do
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)"
done

echo ' Bold $(tput bold)'
echo ' Underline $(tput sgr 0 1)'
echo ' Reset $(tput sgr0)'
echo
11 changes: 11 additions & 0 deletions contrib/backgrounds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# tputcolors

echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"

for i in $(seq 1 7); do
echo " $(tput setab $i)Text$(tput sgr0) $(tput bold)$(tput setab $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setab $i)Text$(tput sgr0) \$(tput setab $i)"
done

echo
14 changes: 14 additions & 0 deletions contrib/colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# tputcolors

echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"

for i in $(seq 1 7); do
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)"
done

echo ' Bold $(tput bold)'
echo ' Underline $(tput sgr 0 1)'
echo ' Reset $(tput sgr0)'
echo
1 change: 1 addition & 0 deletions foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
develop
40 changes: 40 additions & 0 deletions git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"bufio"
"bytes"
"fmt"
"os/exec"
"strings"
)

func getGitBranch() string {
out, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
if err != nil {
return ""
}
return strings.Trim(string(out), "\n")
}

func getGitChanges() int {
out, err := exec.Command("git", "status", "-s", "--porcelain").Output()
if err != nil {
return -1
}
changes := 0
s := bufio.NewScanner(bytes.NewReader(out))
for s.Scan() {
changes++
}
return changes
}

func getGitPartial() string {
partial := ""
changes := getGitChanges()
if changes > 0 {
partial = fmt.Sprintf("%d  ", changes)
}
partial = fmt.Sprintf("%s%s", partial, getGitBranch())
return partial
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import "fmt"

func main() {
prompt := getPrompt()
var p Prompt
prompt := p.getPrompt()
fmt.Printf(prompt)
}
70 changes: 67 additions & 3 deletions prompt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
package main

func getPrompt() string {
prompt := "\\u@\\H:\\w\\$ "
return prompt
import (
"fmt"
"strconv"
)

// Prompt type
type Prompt struct {
prompt string
}

func (p *Prompt) append(partial string) {
p.prompt = fmt.Sprintf("%s%s", p.prompt, partial)
}

func (p *Prompt) prepend(partial string) {
p.prompt = fmt.Sprintf("%s%s", partial, p.prompt)
}

func (p *Prompt) reset() {
p.prompt = fmt.Sprintf("%s%s", p.prompt, "$(tput sgr0)")
}

func (p *Prompt) setColor(fg int, bg int) {
foreground := "$(tput setaf " + strconv.Itoa(fg) + ")"
background := "$(tput setab " + strconv.Itoa(bg) + ")"
p.prompt = fmt.Sprintf("%s%s%s", p.prompt, foreground, background)
}

func (p *Prompt) setBg(bg int) {
background := "$(tput setab " + strconv.Itoa(bg) + ")"
p.prompt = fmt.Sprintf("%s%s", p.prompt, background)
}

func (p *Prompt) setFg(fg int) {
foreground := "$(tput setaf " + strconv.Itoa(fg) + ")"
p.prompt = fmt.Sprintf("%s%s", p.prompt, foreground)
}

// Build the prompt
func (p *Prompt) getPrompt() string {
p.reset()
p.setBg(244)
p.append(JOBS)
p.setColor(244, 240)
p.append(" ")

p.reset()
p.setBg(240)
p.append(PATH)
p.append(" ")

p.reset()
p.setColor(240, 236)
p.append(" ")

p.reset()
p.setBg(236)
p.append(getGitPartial())
p.append(" ")
p.reset()
p.setFg(236)
p.append("")

p.reset()
p.append(" ")

return p.prompt
}
Binary file added shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de83e78

Please sign in to comment.