diff --git a/smug.go b/smug.go index dd49151..4e97eba 100644 --- a/smug.go +++ b/smug.go @@ -168,7 +168,12 @@ func (smug Smug) Start(config Config, options Options, context Context) error { func (smug Smug) GetConfigFromSession(options Options, context Context) (Config, error) { config := Config{} - config.Session = options.Project + + tmuxSession, err := smug.tmux.SessionName() + if err != nil { + return Config{}, err + } + config.Session = tmuxSession tmuxWindows, err := smug.tmux.ListWindows(options.Project) if err != nil { diff --git a/smug_test.go b/smug_test.go index aeb9da1..ae91c8f 100644 --- a/smug_test.go +++ b/smug_test.go @@ -349,7 +349,7 @@ func TestStartStopSession(t *testing.T) { func TestPrintCurrentSession(t *testing.T) { expectedConfig := Config{ - Session: "test", + Session: "session_name", Windows: []Window{ Window{ Name: "win1", @@ -366,6 +366,7 @@ func TestPrintCurrentSession(t *testing.T) { } commander := &MockCommander{[]string{}, []string{ + "session_name", "id1;win1;layout;root", "root\n/tmp", }} diff --git a/tmux.go b/tmux.go index 647df5c..449c8c1 100644 --- a/tmux.go +++ b/tmux.go @@ -115,6 +115,18 @@ func (tmux Tmux) SwitchClient(target string) error { return tmux.commander.ExecSilently(cmd) } +func (tmux Tmux) SessionName() (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 +} + func (tmux Tmux) ListWindows(target string) ([]TmuxWindow, error) { var windows []TmuxWindow