-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (45 loc) · 1017 Bytes
/
main.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
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/Limerio/shell-go/commands"
"github.com/Limerio/shell-go/utils"
)
func main() {
go utils.SignalC()
fmt.Println("Hello in the best shell (jk)")
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("%s > ", utils.FormatPathInShell(os.Getenv("PWD")))
scanner.Scan()
prompt := strings.Fields(scanner.Text())
cmd := prompt[0]
args := prompt[1:]
cmdMap := map[string]func([]string){
"cat": commands.Cat,
"cd": commands.Cd,
"clear": commands.Clear,
"echo": commands.Echo,
"exit": commands.Exit,
"hostname": commands.Hostname,
"mkdir": commands.Mkdir,
"nslookup": commands.NsLookup,
"pwd": commands.Pwd,
"ls": commands.Ls,
"rm": commands.Rm,
"rmdir": commands.Rmdir,
"touch": commands.Touch,
}
command, ok := cmdMap[cmd]
if !ok {
defaultFunc()
continue
}
command(args)
}
}
func defaultFunc() {
fmt.Println("Unknown command")
}