-
Notifications
You must be signed in to change notification settings - Fork 2
/
goshell.go
55 lines (46 loc) · 929 Bytes
/
goshell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"bufio"
"os"
"os/user"
"./Handler"
"./Pim"
//"./Executer"
"strings"
"path/filepath"
//"github.com/fatih/color"
)
func Prompter(prefix ...string) string {
//color.Red("We have red")
u,_ := user.Current()
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
if strings.Contains(dir, u.HomeDir) {
replacer := strings.NewReplacer(u.HomeDir, "~")
dir = replacer.Replace(dir)
}
prompt := u.Username+" @ "+dir+" : "
return prompt
}
func Prompt(reader *bufio.Reader, state int) int {
if(state == 0) {
pim.Success("-> ")
} else {
pim.Error("-> ")
}
fmt.Print(Prompter())
input, err := reader.ReadString('\n')
if(err != nil) {
fmt.Println(err)
}
replacer := strings.NewReplacer("\n", "")
input = replacer.Replace(input)
return Handler.Handle(input)
}
func main() {
reader := bufio.NewReader(os.Stdin)
var status = 0;
for status != -99 {
status = Prompt(reader, status)
}
}