From c711fe1cab738fdc1e9c12c601d80d6bf5892c9e Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Fri, 24 Nov 2023 16:03:05 +0100 Subject: 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 Acked-by: Robin Jarry --- commands/patch/cd.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 commands/patch/cd.go (limited to 'commands') 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 +} -- cgit