mirror of https://github.com/Hilbis/Hilbish
feat: printf-like formatting for prompt
parent
8b7c7e707a
commit
d945d510f7
27
main.go
27
main.go
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
_ "os/exec"
|
_ "os/exec"
|
||||||
_ "os/user"
|
"os/user"
|
||||||
"syscall"
|
"syscall"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -76,10 +76,10 @@ func main() {
|
||||||
LuaInit()
|
LuaInit()
|
||||||
|
|
||||||
readline.Completer = readline.FilenameCompleter
|
readline.Completer = readline.FilenameCompleter
|
||||||
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
//user, _ := user.Current()
|
|
||||||
//dir, _ := os.Getwd()
|
//dir, _ := os.Getwd()
|
||||||
//host, _ := os.Hostname()
|
|
||||||
|
|
||||||
//reader := bufio.NewReader(os.Stdin)
|
//reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
@ -151,7 +151,26 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fmtPrompt() string {
|
func fmtPrompt() string {
|
||||||
return prompt
|
user, _ := user.Current()
|
||||||
|
host, _ := os.Hostname()
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
|
cwd = strings.Replace(cwd, user.HomeDir, "~", 1)
|
||||||
|
args := []string{
|
||||||
|
"d",
|
||||||
|
cwd,
|
||||||
|
"h",
|
||||||
|
host,
|
||||||
|
"u",
|
||||||
|
user.Name,
|
||||||
|
}
|
||||||
|
for i, v := range args {
|
||||||
|
if i % 2 == 0 {
|
||||||
|
args[i] = "%" + v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r := strings.NewReplacer(args...)
|
||||||
|
nprompt := r.Replace(prompt)
|
||||||
|
return nprompt
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||||
|
|
Loading…
Reference in New Issue