From 6c4f6e067a7d2d7a7dfca348de224246277f8547 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 27 May 2022 15:43:29 +0700 Subject: [PATCH] feat: Allow stopping smug session without specifying a project --- main.go | 21 ++++++++++++++------- tmux.go | 11 +++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index e557ebf..d71be96 100644 --- a/main.go +++ b/main.go @@ -68,13 +68,6 @@ func main() { userConfigDir := filepath.Join(ExpandPath("~/"), ".config/smug") - var configPath string - if options.Config != "" { - configPath = options.Config - } else { - configPath = filepath.Join(userConfigDir, options.Project+".yml") - } - var logger *log.Logger if options.Debug { logFile, err := os.Create(filepath.Join(userConfigDir, "smug.log")) @@ -90,6 +83,20 @@ func main() { smug := Smug{tmux, commander} context := CreateContext() + var configPath string + if options.Config != "" { + configPath = options.Config + } else if options.Project != "" { + configPath = filepath.Join(userConfigDir, options.Project+".yml") + } else { + s, err := tmux.CurrentSession() + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + configPath = filepath.Join(userConfigDir, s+".yml") + } + switch options.Command { case CommandStart: if len(options.Windows) == 0 { diff --git a/tmux.go b/tmux.go index e00750f..7f30a44 100644 --- a/tmux.go +++ b/tmux.go @@ -181,3 +181,14 @@ func (tmux Tmux) ListPanes(target string) ([]TmuxPane, error) { return panes, nil } + +func (tmux Tmux) CurrentSession() (string, error) { + cmd := exec.Command("tmux", "display-message", "-p", "#S") + sessionName, err := tmux.commander.Exec(cmd) + + if err != nil { + return sessionName, err + } + + return sessionName, nil +}