Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 6, 2021
1 parent 60cf542 commit b2474f1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
1 change: 0 additions & 1 deletion .envrc

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
kaks
kks
36 changes: 31 additions & 5 deletions cmd/edit.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
package cmd

import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"syscall"
)

func Edit(filename, session, client string) {
kakBinary, lookErr := exec.LookPath("kak")
if lookErr != nil {
panic(lookErr)
if session != "" && client != "" {
kakCommand := fmt.Sprintf("edit %s", filename)
Send(kakCommand, session, client)
os.Exit(0)
}

kakExecArgs := []string{"kak", "-s", session, filename}
kakBinary, err := exec.LookPath("kak")
if err != nil {
log.Fatal(err)
}

kakExecArgs := []string{"kak"}

sessions, err := exec.Command("kak", "-l").Output()
if err != nil {
log.Fatal(err)
}

if session != "" && strings.Contains(string(sessions), session) {
kakExecArgs = append(kakExecArgs, "-c", session)
} else if session != "" {
// TODO: this gets killed if parent shell closes, use setsid?
kakExecArgs = append(kakExecArgs, "-s", session)
}

kakExecArgs = append(kakExecArgs, filename)

fmt.Print(kakExecArgs)

execErr := syscall.Exec(kakBinary, kakExecArgs, os.Environ())
if execErr != nil {
panic(execErr)
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module kaks
module kks

go 1.17
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"kaks/cmd"
"kks/cmd"
"os"
"strings"
)
Expand Down

0 comments on commit b2474f1

Please sign in to comment.