aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch/cd.go
blob: bbca1ebaa62c8def8e9384ea85cc6009bc39e98f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package patch

import (
	"fmt"
	"os"
	"time"

	"git.sr.ht/~rjarry/aerc/app"
	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib/pama"
)

type Cd struct{}

func init() {
	register(Cd{})
}

func (Cd) Context() commands.CommandContext {
	return commands.GLOBAL
}

func (Cd) Aliases() []string {
	return []string{"cd"}
}

func (Cd) Execute(args []string) error {
	p, err := pama.New().CurrentProject()
	if err != nil {
		return err
	}
	cwd, err := os.Getwd()
	if err != nil {
		return err
	}
	if cwd == p.Root {
		app.PushStatus("Already here.", 10*time.Second)
		return nil
	}
	err = os.Chdir(p.Root)
	if err != nil {
		return err
	}
	app.PushStatus(fmt.Sprintf("Changed to %s.", p.Root),
		10*time.Second)
	return nil
}