summaryrefslogtreecommitdiff
path: root/cmds/cd.go
blob: 8fa3c5e7ea11182af18402bfffd189a8cbd13aea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package cmds

import "os"

// chDir: changes the current working directory
// if no directory is specifed sets it to home
func ChDir(args []string) (int, error) {
	var dir string
	if len(args) == 1 {
		dir, _ = os.UserHomeDir()
	} else {
		dir = args[1]
	}
	if err := os.Chdir(dir); err != nil {
		return 1, err
	}
	return 0, nil
}