Skip to content

Commit 7c05d27

Browse files
feat: add tmuxinator support (#171)
* Added support for listing configs and connecting via tmuxinator with -T flag * feat: improve tmuxinator features - Simplify module names - Change connection strategy to use mapping based of connect Src - Add icon support to tmuxinator entries - Changed the priority to list and connect to tmuxinator before zoxide * chore: update mockery * fix: tests and remove log --------- Co-authored-by: kadriandev <[email protected]>
1 parent 18eda33 commit 7c05d27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+526
-63
lines changed

cloner/mock_Cloner.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configurator/mock_Configurator.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connector/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/joshmedeski/sesh/namer"
1111
"github.com/joshmedeski/sesh/startup"
1212
"github.com/joshmedeski/sesh/tmux"
13+
"github.com/joshmedeski/sesh/tmuxinator"
1314
"github.com/joshmedeski/sesh/zoxide"
1415
"github.com/stretchr/testify/assert"
1516
mock "github.com/stretchr/testify/mock"
@@ -23,6 +24,7 @@ func TestConfigStrategy(t *testing.T) {
2324
mockStartup := new(startup.MockStartup)
2425
mockTmux := new(tmux.MockTmux)
2526
mockZoxide := new(zoxide.MockZoxide)
27+
mockTmuxinator := new(tmuxinator.MockTmuxinator)
2628

2729
c := &RealConnector{
2830
model.Config{},
@@ -33,6 +35,7 @@ func TestConfigStrategy(t *testing.T) {
3335
mockStartup,
3436
mockTmux,
3537
mockZoxide,
38+
mockTmuxinator,
3639
}
3740
mockTmux.On("AttachSession", mock.Anything).Return("attaching", nil)
3841
mockZoxide.On("Add", mock.Anything).Return(nil)

connector/connect.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ func (c *RealConnector) Connect(name string, opts model.ConnectOpts) (string, er
1414
// sesh connect --config (sesh list --config | fzf)
1515
strategies := []func(*RealConnector, string) (model.Connection, error){
1616
tmuxStrategy,
17+
tmuxinatorStrategy,
1718
configStrategy,
1819
dirStrategy,
1920
zoxideStrategy,
2021
}
2122

23+
connectStrategy := map[string]func(c *RealConnector, connection model.Connection, opts model.ConnectOpts) (string, error){
24+
"tmux": connectToTmux,
25+
"tmuxinator": connectToTmuxinator,
26+
"config": connectToTmux,
27+
"zoxide": connectToTmux,
28+
}
29+
2230
for _, strategy := range strategies {
2331
if connection, err := strategy(c, name); err != nil {
2432
return "", fmt.Errorf("failed to establish connection: %w", err)
@@ -28,13 +36,7 @@ func (c *RealConnector) Connect(name string, opts model.ConnectOpts) (string, er
2836
if connection.AddToZoxide {
2937
c.zoxide.Add(connection.Session.Path)
3038
}
31-
if connection.New {
32-
c.tmux.NewSession(connection.Session.Name, connection.Session.Path)
33-
c.startup.Exec(connection.Session)
34-
}
35-
// TODO: configure the ability to create a session in a detached way (like update)
36-
// TODO: configure the ability to create a popup instead of switching (with no tmux bar?)
37-
return c.tmux.SwitchOrAttach(connection.Session.Name, opts)
39+
return connectStrategy[connection.Session.Src](c, connection, opts)
3840
}
3941
}
4042

connector/connector.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/joshmedeski/sesh/namer"
99
"github.com/joshmedeski/sesh/startup"
1010
"github.com/joshmedeski/sesh/tmux"
11+
"github.com/joshmedeski/sesh/tmuxinator"
1112
"github.com/joshmedeski/sesh/zoxide"
1213
)
1314

@@ -16,14 +17,15 @@ type Connector interface {
1617
}
1718

1819
type RealConnector struct {
19-
config model.Config
20-
dir dir.Dir
21-
home home.Home
22-
lister lister.Lister
23-
namer namer.Namer
24-
startup startup.Startup
25-
tmux tmux.Tmux
26-
zoxide zoxide.Zoxide
20+
config model.Config
21+
dir dir.Dir
22+
home home.Home
23+
lister lister.Lister
24+
namer namer.Namer
25+
startup startup.Startup
26+
tmux tmux.Tmux
27+
zoxide zoxide.Zoxide
28+
tmuxinator tmuxinator.Tmuxinator
2729
}
2830

2931
func NewConnector(
@@ -35,6 +37,7 @@ func NewConnector(
3537
startup startup.Startup,
3638
tmux tmux.Tmux,
3739
zoxide zoxide.Zoxide,
40+
tmuxinator tmuxinator.Tmuxinator,
3841
) Connector {
3942
return &RealConnector{
4043
config,
@@ -45,5 +48,6 @@ func NewConnector(
4548
startup,
4649
tmux,
4750
zoxide,
51+
tmuxinator,
4852
}
4953
}

connector/mock_Connector.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connector/tmux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ func tmuxStrategy(c *RealConnector, name string) (model.Connection, error) {
1515
// Switch: true
1616
}, nil
1717
}
18+
19+
func connectToTmux(c *RealConnector, connection model.Connection, opts model.ConnectOpts) (string, error) {
20+
if connection.New {
21+
return c.tmux.SwitchOrAttach(connection.Session.Name, opts)
22+
}
23+
c.tmux.NewSession(connection.Session.Name, connection.Session.Path)
24+
c.startup.Exec(connection.Session)
25+
return c.tmux.SwitchOrAttach(connection.Session.Name, opts)
26+
}

connector/tmux_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/joshmedeski/sesh/namer"
1111
"github.com/joshmedeski/sesh/startup"
1212
"github.com/joshmedeski/sesh/tmux"
13+
"github.com/joshmedeski/sesh/tmuxinator"
1314
"github.com/joshmedeski/sesh/zoxide"
1415
"github.com/stretchr/testify/assert"
1516
mock "github.com/stretchr/testify/mock"
@@ -23,6 +24,7 @@ func TestEstablishTmuxConnection(t *testing.T) {
2324
mockStartup := new(startup.MockStartup)
2425
mockTmux := new(tmux.MockTmux)
2526
mockZoxide := new(zoxide.MockZoxide)
27+
mockTmuxinator := new(tmuxinator.MockTmuxinator)
2628

2729
c := &RealConnector{
2830
model.Config{},
@@ -33,6 +35,7 @@ func TestEstablishTmuxConnection(t *testing.T) {
3335
mockStartup,
3436
mockTmux,
3537
mockZoxide,
38+
mockTmuxinator,
3639
}
3740
mockTmux.On("AttachSession", mock.Anything).Return("attaching", nil)
3841
mockZoxide.On("Add", mock.Anything).Return(nil)

connector/tmuxinator.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package connector
2+
3+
import (
4+
"github.com/joshmedeski/sesh/model"
5+
)
6+
7+
func tmuxinatorStrategy(c *RealConnector, name string) (model.Connection, error) {
8+
session, exists := c.lister.FindTmuxinatorConfig(name)
9+
if !exists {
10+
return model.Connection{Found: false}, nil
11+
}
12+
13+
return model.Connection{
14+
Found: true,
15+
Session: session,
16+
New: true,
17+
AddToZoxide: false,
18+
}, nil
19+
}
20+
21+
func connectToTmuxinator(c *RealConnector, connection model.Connection, opts model.ConnectOpts) (string, error) {
22+
return c.tmuxinator.Start(connection.Session.Name)
23+
}

dir/mock_Dir.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)