package cmd import ( "gosh/types" "gosh/utils" "os" "strings" "github.com/fatih/color" ) func GoshLs(sh *types.Shell, paths ...string) types.CmdOutput { var dir string if len(paths) > 0 && paths[0] != "" { dir = paths[0] } else { dir = sh.Cd } dir = utils.ExpandHome(dir) children, err := os.ReadDir(dir) red := color.New(color.FgRed).SprintFunc() if err != nil { return types.CmdOutput{Id: 1, Output: red(err)} } var output strings.Builder for _, child := range children { if child.IsDir() { output.WriteString(color.CyanString(child.Name()+"/") + "\n") } else { output.WriteString(child.Name() + "\n") } } return types.CmdOutput{Id: 0, Output: output.String()} }