aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:05 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commitc711fe1cab738fdc1e9c12c601d80d6bf5892c9e (patch)
tree216bb9b30ce1e147d7c7c4d8c447d76a797a055e /commands
parent41e066768c18268fe3deecc60b5797e26f44cf4e (diff)
downloadaerc-c711fe1cab738fdc1e9c12c601d80d6bf5892c9e.tar.gz
patch/cd: add cd sub-cmd
Implement the :patch cd command. Change the directory to the project's root directory that was determined during the :patch init setup process. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/patch/cd.go42
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
+}