MCPcopy Create free account
hub / github.com/cogentcore/core / Cd

Method Cd

shell/builtins.go:40–68  ·  view source on GitHub ↗

Cd changes the current directory.

(cmdIO *exec.CmdIO, args ...string)

Source from the content-addressed store, hash-verified

38
39// Cd changes the current directory.
40func (sh *Shell) Cd(cmdIO *exec.CmdIO, args ...string) error {
41 if len(args) > 1 {
42 return fmt.Errorf("no more than one argument can be passed to cd")
43 }
44 dir := ""
45 if len(args) == 1 {
46 dir = args[0]
47 }
48 dir, err := homedir.Expand(dir)
49 if err != nil {
50 return err
51 }
52 if dir == "" {
53 dir, err = homedir.Dir()
54 if err != nil {
55 return err
56 }
57 }
58 dir, err = filepath.Abs(dir)
59 if err != nil {
60 return err
61 }
62 err = os.Chdir(dir)
63 if err != nil {
64 return err
65 }
66 sh.Config.Dir = dir
67 return nil
68}
69
70// Exit exits the shell.
71func (sh *Shell) Exit(cmdIO *exec.CmdIO, args ...string) error {

Callers

nothing calls this directly

Calls 2

ErrorfMethod · 0.65
AbsMethod · 0.45

Tested by

no test coverage detected