shell/handle.go

47 lines
731 B
Go
Raw Normal View History

2023-03-19 13:08:11 +01:00
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"git.milar.in/milarin/adverr"
)
func handle(input string) {
input = strings.TrimSpace(input)
if input == "" {
return
}
if input == "up" {
goUp()
return
}
if strings.HasPrefix(input, "cd ") {
os.Chdir(strings.Split(input, " ")[1])
return
}
cook()
defer doItRaw()
parts := strings.Split(input, " ")
cmd := exec.Command(parts[0], parts[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
fmt.Println(adverr.Wrap("Could not start process", err))
return
}
if err := cmd.Wait(); err != nil {
fmt.Println(adverr.Wrap("Could not wait for process to complete", err))
return
}
}