package main import ( "fmt" "gosh/cmd" "gosh/types" "gosh/utils" "os" "os/exec" "path/filepath" "strings" "github.com/chzyer/readline" "github.com/fatih/color" ) func gosh_print_output(cmdo types.CmdOutput) { switch cmdo.Id { case 0: fmt.Printf(cmdo.Output) case 1: fmt.Printf("Error: %s\n", cmdo.Output) } } func parse_flags(parts []string) (map[string]string, []string) { flags := make(map[string]string) args := []string{} i := 0 for i < len(parts) { if strings.HasPrefix(parts[i], "-") { key := parts[i] val := "" if i+1 < len(parts) && !strings.HasPrefix(parts[i+1], "-") { val = parts[i+1] i++ } flags[key] = val } else { args = append(args, parts[i]) } i++ } return flags, args } func process_golshscript(sh *types.Shell, file_path string) { data, err := os.ReadFile(file_path) if err != nil { fmt.Println("Error: ", err) return } lines := strings.Split(string(data), "\n") for _, line := range lines { gosh_process_input(sh, strings.TrimSpace(line)) } } func check_pathes(sh *types.Shell, name string, args []string) bool { var output types.CmdOutput program_found := false // Check Python Pathes for _, path := range sh.PyPaths { children, err := os.ReadDir(path) if err != nil { color.Red("Error reading path.") fmt.Println(err) } for _, child := range children { child_name := strings.TrimSpace(child.Name()) if !child.IsDir() && child_name == name { program_found = true full_path := filepath.Join(path, child.Name()) path_args := append([]string{full_path}, args...) comd := exec.Command("python3", path_args...) out, err := comd.Output() if err != nil { fmt.Print("Error: ") color.Red(err.Error()) } output = types.CmdOutput{Id: 0, Output: string(out)} } } } if program_found { gosh_print_output(output) } return program_found } func gosh_process_input(sh *types.Shell, input string) { // Split by pipe and trim spaces commands := strings.Split(input, "|") var prevOutput types.CmdOutput for _, cmdStr := range commands { cmdStr = strings.TrimSpace(cmdStr) parts := strings.Fields(cmdStr) if len(parts) == 0 { continue } switch parts[0] { case "pwd": prevOutput = cmd.GoshPwd(sh) case "cd": if len(parts) < 2 { fmt.Println("Usage: cd