Debian Codegraph @

commands/patch/cd.go

raw
1 package patch
2
3 import (
4 "fmt"
5 "os"
6 "time"
7
8 "git.sr.ht/~rjarry/aerc/app"
9 "git.sr.ht/~rjarry/aerc/commands"
10 "git.sr.ht/~rjarry/aerc/lib/pama"
11 )
12
13 type Cd struct{}
14
15 func init() {
16 register(Cd{})
17 }
18
19 func (Cd) Description() string {
20 return "Change aerc's working directory to the current project."
21 }
22
23 func (Cd) Context() commands.CommandContext {
24 return commands.GLOBAL
25 }
26
27 func (Cd) Aliases() []string {
28 return []string{"cd"}
29 }
30
31 func (Cd) Execute(args []string) error {
32 p, err := pama.New().CurrentProject()
33 if err != nil {
34 return err
35 }
36 cwd, err := os.Getwd()
37 if err != nil {
38 return err
39 }
40 if cwd == p.Root {
41 app.PushStatus("Already here.", 10*time.Second)
42 return nil
43 }
44 err = os.Chdir(p.Root)
45 if err != nil {
46 return err
47 }
48 app.PushStatus(fmt.Sprintf("Changed to %s.", p.Root),
49 10*time.Second)
50 return nil
51 }