package cd import ( "bbash/environment" "bbash/input_parser" "fmt" "os" "path/filepath" ) func Cd(in input_parser.Input, env *environment.Env) { var new_path string if in.Args_raw == "" { new_path = env.Env["HOME"] } else { if in.Args_raw[0] == '/' { new_path = in.Args_raw } else { new_path = filepath.Join(env.Path, in.Args_raw) } } file, err := os.Stat(new_path) if err != nil { fmt.Print(fmt.Sprintf("Error changing directory %s", err.Error())) return } if !file.IsDir() { fmt.Print("New path is not a directory") return } env.Path = new_path }