-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
47 lines (42 loc) · 1008 Bytes
/
util.go
File metadata and controls
47 lines (42 loc) · 1008 Bytes
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
package main
import (
"bufio"
"errors"
"fmt"
"os"
"strings"
)
func prompt() (string, error) {
var userInputCommand string
var emptySlice []string
curDir, _ := execCommandString("pwd", emptySlice...)
curDirTrimmed := strings.Trim(curDir, "\t \n")
fmt.Printf("\342\232\241 [%s] ", curDirTrimmed)
stdin := bufio.NewScanner(os.Stdin)
scanner := stdin.Scan()
if scanner {
rawText := stdin.Text()
sanitized := strings.TrimLeft(rawText, "\t \n")
userInputCommand = sanitized
}
eof := !scanner && stdin.Err() == nil
if eof {
Logger.Debug().Msg("Caught CTRL+D, exiting...")
os.Exit(0)
}
if len(userInputCommand) == 0 {
return "", errors.New("EMPTYMESSAGE")
}
return userInputCommand, nil
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func stringSlicer(whiteSpaceDelimittedString string) []string {
substringSlice := strings.Fields(whiteSpaceDelimittedString)
return substringSlice
}