update sesh
This commit is contained in:
@@ -2,11 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/ktr0731/go-fuzzyfinder"
|
"github.com/ktr0731/go-fuzzyfinder"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -21,7 +21,7 @@ type Window struct {
|
|||||||
func (w Window) ExpandedPath() string {
|
func (w Window) ExpandedPath() string {
|
||||||
expanded, err := expandTilde(w.Path)
|
expanded, err := expandTilde(w.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return expanded
|
return expanded
|
||||||
}
|
}
|
||||||
@@ -36,29 +36,29 @@ const (
|
|||||||
func main() {
|
func main() {
|
||||||
_, err := exec.LookPath(tmux)
|
_, err := exec.LookPath(tmux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = exec.LookPath(mkdir)
|
_, err = exec.LookPath(mkdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configFilePath := filepath.Join(homeDir, ".sesh.yaml")
|
configFilePath := filepath.Join(homeDir, ".sesh.yaml")
|
||||||
f, err := os.Open(configFilePath)
|
f, err := os.Open(configFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var config Config
|
var config Config
|
||||||
err = yaml.NewDecoder(f).Decode(&config)
|
err = yaml.NewDecoder(f).Decode(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
seshNames := make([]string, 0, len(config))
|
seshNames := make([]string, 0, len(config))
|
||||||
@@ -74,11 +74,11 @@ func main() {
|
|||||||
|
|
||||||
seshName := seshNames[i]
|
seshName := seshNames[i]
|
||||||
if HasSession(seshName) {
|
if HasSession(seshName) {
|
||||||
ActivateSession(seshName)
|
TurnIntoTmux(seshName)
|
||||||
} else {
|
} else {
|
||||||
sesh := config[seshName]
|
sesh := config[seshName]
|
||||||
if len(sesh) == 0 {
|
if len(sesh) == 0 {
|
||||||
log.Println("no windows in session")
|
fmt.Println("no windows in session")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, window := range sesh {
|
for _, window := range sesh {
|
||||||
@@ -89,7 +89,7 @@ func main() {
|
|||||||
NewWindowInSession(seshName, window)
|
NewWindowInSession(seshName, window)
|
||||||
}
|
}
|
||||||
exec.Command(tmux, "select-window", "-t", fmt.Sprintf("%s:^", seshName)).Run()
|
exec.Command(tmux, "select-window", "-t", fmt.Sprintf("%s:^", seshName)).Run()
|
||||||
ActivateSession(seshName)
|
TurnIntoTmux(seshName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ func expandTilde(path string) (string, error) {
|
|||||||
|
|
||||||
func NewWindowInSession(seshName string, window Window) {
|
func NewWindowInSession(seshName string, window Window) {
|
||||||
if seshName == "" {
|
if seshName == "" {
|
||||||
log.Fatalln("missing seshName")
|
panic("missing seshName")
|
||||||
}
|
}
|
||||||
var args = []string{}
|
var args = []string{}
|
||||||
if HasSession(seshName) {
|
if HasSession(seshName) {
|
||||||
@@ -131,19 +131,24 @@ func NewWindowInSession(seshName string, window Window) {
|
|||||||
if window.Name != "" {
|
if window.Name != "" {
|
||||||
args = append(args, "-n", window.Name)
|
args = append(args, "-n", window.Name)
|
||||||
}
|
}
|
||||||
args = append(args, window.Program)
|
if window.Program != "" {
|
||||||
|
args = append(args, window.Program)
|
||||||
|
}
|
||||||
exec.Command(tmux, args...).Run()
|
exec.Command(tmux, args...).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ActivateSession(name string) {
|
func TurnIntoTmux(sessionName string) {
|
||||||
_, isInTmux := os.LookupEnv("TMUX")
|
_, isInTmux := os.LookupEnv("TMUX")
|
||||||
var err error
|
tmuxPath, err := exec.LookPath(tmux)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
if isInTmux {
|
if isInTmux {
|
||||||
err = exec.Command(tmux, "switch-client", "-t", name).Run()
|
err = syscall.Exec(tmuxPath, []string{tmuxPath, "switch-client", "-t", sessionName}, os.Environ())
|
||||||
} else {
|
} else {
|
||||||
err = exec.Command(tmux, "attach", "-t", name).Run()
|
err = syscall.Exec(tmuxPath, []string{tmuxPath, "attach", "-t", sessionName}, os.Environ())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -19,7 +19,7 @@ bind c-l select-pane -R
|
|||||||
|
|
||||||
bind c-g popup -E -w 80% -h 80% -d "#{pane_current_path}" -b rounded lazygit
|
bind c-g popup -E -w 80% -h 80% -d "#{pane_current_path}" -b rounded lazygit
|
||||||
bind c-t popup -E -w 80% -h 80% -b rounded -d "#{pane_current_path}"
|
bind c-t popup -E -w 80% -h 80% -b rounded -d "#{pane_current_path}"
|
||||||
bind c-s popup -E -w 80% -h 80% -b rounded "sh $HOME/choose-session.sh"
|
bind c-s popup -E -w 80% -h 80% -b rounded "sesh"
|
||||||
|
|
||||||
bind j command-prompt -p "Join window:" "join-pane -h -s %1"
|
bind j command-prompt -p "Join window:" "join-pane -h -s %1"
|
||||||
bind b break-pane
|
bind b break-pane
|
||||||
|
|||||||
Reference in New Issue
Block a user