10 func HandleShellCommand(input string, view *View) {
11 inputCmd := strings.Split(input, " ")[0]
12 args := strings.Split(input, " ")[1:]
15 cmdout := exec.Command(inputCmd, args...)
16 output, err := cmdout.Output()
18 messenger.Error("Error: " + err.Error())
22 // Display last line of output
23 messenger.Message(string(output))
27 // HandleCommand handles input from the user
28 func HandleCommand(input string, view *View) {
29 inputCmd := strings.Split(input, " ")[0]
30 args := strings.Split(input, " ")[1:]
32 commands := []string{"set", "quit", "save", "replace"}
37 for _, c := range commands {
38 if strings.HasPrefix(c, inputCmd) {
51 if view.CanClose("Quit anyway? ") {
58 r := regexp.MustCompile(`"[^"\\]*(?:\\.[^"\\]*)*"|[^\s]*`)
59 replaceCmd := r.FindAllString(strings.Join(args, " "), -1)
60 if len(replaceCmd) < 2 {
61 messenger.Error("Invalid replace statement: " + strings.Join(args, " "))
66 if len(replaceCmd) == 3 {
67 // The user included some flags
71 search := string(replaceCmd[0])
72 replace := string(replaceCmd[1])
74 if strings.HasPrefix(search, `"`) && strings.HasSuffix(search, `"`) {
75 search = search[1 : len(search)-1]
77 if strings.HasPrefix(replace, `"`) && strings.HasSuffix(replace, `"`) {
78 replace = replace[1 : len(replace)-1]
81 search = strings.Replace(search, `\"`, `"`, -1)
82 replace = strings.Replace(replace, `\"`, `"`, -1)
84 // messenger.Error(search + " -> " + replace)
86 regex, err := regexp.Compile(search)
88 messenger.Error(err.Error())
94 match := regex.FindStringIndex(view.buf.text)
99 if strings.Contains(flags, "c") {
100 // // The 'check' flag was used
101 // if messenger.YesNoPrompt("Perform replacement?") {
102 // view.eh.Replace(match[0], match[1], replace)
107 view.eh.Replace(match[0], match[1], replace)
110 messenger.Message("Nothing matched " + search)
113 messenger.Error("Unknown command: " + inputCmd)