Skip to content

Commit

Permalink
lookup gitdir config variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 13, 2021
1 parent 811a044 commit 967cdd7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package cmd
import (
"flag"
"fmt"
"os"
"os/exec"
"path"
"strings"

// "strings"

"github.com/kkga/kks/kak"
)

Expand All @@ -34,38 +33,37 @@ func (c *EditCmd) Run() error {
return err
}

// TODO config env var
conf_gitdir_autosess := true
_, useGitDirSessions := os.LookupEnv("KKS_USE_GITDIR_SESSIONS")

gitdir_sess := struct {
gitdirSess := struct {
name string
exists bool
}{"", false}

if conf_gitdir_autosess {
if useGitDirSessions {
gitOut, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err == nil {
gitdir_sess.name = strings.TrimSpace(strings.ReplaceAll(path.Base(string(gitOut)), ".", "-"))
gitdirSess.name = strings.TrimSpace(strings.ReplaceAll(path.Base(string(gitOut)), ".", "-"))
sessions, _ := kak.List()
for _, s := range sessions {
if s.Name == gitdir_sess.name {
gitdir_sess.exists = true
if s.Name == gitdirSess.name {
gitdirSess.exists = true
}
}
}
}

switch c.session {
case "":
if gitdir_sess.name != "" {
if !gitdir_sess.exists {
sessionName, err := kak.Create(gitdir_sess.name)
if gitdirSess.name != "" {
if !gitdirSess.exists {
sessionName, err := kak.Create(gitdirSess.name)
if err != nil {
return err
}
fmt.Println("git-dir session started:", sessionName)
}
if err := kak.Connect(fp.Name, fp.Line, fp.Column, gitdir_sess.name); err != nil {
if err := kak.Connect(fp.Name, fp.Line, fp.Column, gitdirSess.name); err != nil {
return err
}
} else {
Expand Down

0 comments on commit 967cdd7

Please sign in to comment.