-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1 | ||
0.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
develop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |