From b44f4c7e340c13c5736e247871107d0fa82e051e Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Tue, 14 Sep 2021 09:32:57 +0300 Subject: [PATCH] wip: default session --- cmd/edit.go | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/edit.go b/cmd/edit.go index ee53b44..2f912cb 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -34,23 +34,12 @@ func (c *EditCmd) Run() error { } _, useGitDirSessions := os.LookupEnv("KKS_USE_GITDIR_SESSIONS") + // defaultSession := os.Getenv("KKS_DEFAULT_SESSION") - gitdirSess := struct { - name string - exists bool - }{"", false} + var gitDirSess *gitDirSession if useGitDirSessions { - gitOut, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() - if err == nil { - gitdirSess.name = strings.TrimSpace(strings.ReplaceAll(path.Base(string(gitOut)), ".", "-")) - sessions, _ := kak.List() - for _, s := range sessions { - if s.Name == gitdirSess.name { - gitdirSess.exists = true - } - } - } + _ = gitDirSess.Init() } switch c.session { @@ -97,3 +86,24 @@ func (c *EditCmd) Run() error { return nil } + +type gitDirSession struct { + name string + exists bool +} + +func (gs *gitDirSession) Init() error { + gitOut, err := exec.Command("git", "rev-parse", "--show-toplevel").Output() + if err != nil { + return err + } + gs.name = strings.TrimSpace(strings.ReplaceAll(path.Base(string(gitOut)), ".", "-")) + + sessions, _ := kak.List() + for _, s := range sessions { + if s.Name == gs.name { + gs.exists = true + } + } + return nil +}