diff options
-rw-r--r-- | commands/patch/cd.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/commands/patch/cd.go b/commands/patch/cd.go new file mode 100644 index 00000000..86a2db3e --- /dev/null +++ b/commands/patch/cd.go @@ -0,0 +1,42 @@ +package patch + +import ( + "fmt" + "os" + "time" + + "git.sr.ht/~rjarry/aerc/app" + "git.sr.ht/~rjarry/aerc/lib/pama" +) + +type Cd struct{} + +func init() { + register(Cd{}) +} + +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 +} |