diff --git a/VERSION b/VERSION index 8acdd82..4e379d2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.1 +0.0.2 diff --git a/constants.go b/constants.go new file mode 100644 index 0000000..be2f65e --- /dev/null +++ b/constants.go @@ -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" +) diff --git a/contrib/256backgrounds.sh b/contrib/256backgrounds.sh new file mode 100755 index 0000000..73bb91b --- /dev/null +++ b/contrib/256backgrounds.sh @@ -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 diff --git a/contrib/256colors.sh b/contrib/256colors.sh new file mode 100755 index 0000000..c7b0421 --- /dev/null +++ b/contrib/256colors.sh @@ -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 diff --git a/contrib/backgrounds.sh b/contrib/backgrounds.sh new file mode 100755 index 0000000..4079c70 --- /dev/null +++ b/contrib/backgrounds.sh @@ -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 diff --git a/contrib/colors.sh b/contrib/colors.sh new file mode 100755 index 0000000..4d1dd66 --- /dev/null +++ b/contrib/colors.sh @@ -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 diff --git a/foo b/foo new file mode 100644 index 0000000..6563189 --- /dev/null +++ b/foo @@ -0,0 +1 @@ +develop diff --git a/git.go b/git.go new file mode 100644 index 0000000..dc1c463 --- /dev/null +++ b/git.go @@ -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 +} diff --git a/main.go b/main.go index afd6692..3de23b1 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import "fmt" func main() { - prompt := getPrompt() + var p Prompt + prompt := p.getPrompt() fmt.Printf(prompt) } diff --git a/prompt.go b/prompt.go index b95e7d5..c399fd1 100644 --- a/prompt.go +++ b/prompt.go @@ -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 } diff --git a/shot.png b/shot.png new file mode 100644 index 0000000..f61bc22 Binary files /dev/null and b/shot.png differ