Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tmuxinator Support #171

Merged
merged 23 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3680d88
Added support for listing configs and connecting via tmuxinator with -T
kadriandev Sep 3, 2024
f60fea7
Formatted code with go fmt ./...
kadriandev Sep 3, 2024
ef2bfad
Removed tmuxinator lister and connector and moved tmuxinator config
kadriandev Sep 4, 2024
2b41a9e
Formatted code
kadriandev Sep 4, 2024
80f9a7f
Added back listing tmuxinator configs and fixed tests
kadriandev Sep 18, 2024
363f5fa
feat: add json flag
joshmedeski Sep 6, 2024
d0b61a9
feat: adding --hide-attached flag to list
joshmedeski Sep 6, 2024
ad67c1c
feat: evaluate symlinks when connecting (#150)
glebglazov Sep 6, 2024
72ff812
fix: remove hide attached because it breaks the app
joshmedeski Sep 6, 2024
a63a66d
fix: FindZoxideSession exists boolean (#162)
dbistriceanu Sep 6, 2024
118c1a7
feat: add GetLastTmuxSession function
joshmedeski Sep 13, 2024
3951b56
feat: add a last cli command
joshmedeski Sep 13, 2024
c25d501
docs: describe sesh last and config sample
joshmedeski Sep 13, 2024
91527b0
chore: udpate mock lister
joshmedeski Sep 13, 2024
ee88f06
feat: update mockery version
joshmedeski Sep 13, 2024
50c59e6
docs: fix typo for config sample
albertilagan Sep 13, 2024
b34c9cf
Added support for listing configs and connecting via tmuxinator with -T
kadriandev Sep 3, 2024
5600db1
Added tests and changed mockery versions to not be changed
kadriandev Sep 18, 2024
724bce7
Merge branch 'main' of github.com:joshmedeski/sesh into kadriandev/main
joshmedeski Sep 20, 2024
14b7ec4
feat: improve tmuxinator features
joshmedeski Sep 20, 2024
dc7b555
chore: update mockery
joshmedeski Sep 20, 2024
19284a5
fix: tests and remove log
joshmedeski Sep 20, 2024
3b2a35c
fix: silently fail if tmuxinator isn't found
joshmedeski Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloner/mock_Cloner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configurator/mock_Configurator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions connector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/joshmedeski/sesh/namer"
"github.com/joshmedeski/sesh/startup"
"github.com/joshmedeski/sesh/tmux"
"github.com/joshmedeski/sesh/tmuxinator"
"github.com/joshmedeski/sesh/zoxide"
"github.com/stretchr/testify/assert"
mock "github.com/stretchr/testify/mock"
Expand All @@ -23,6 +24,7 @@ func TestConfigStrategy(t *testing.T) {
mockStartup := new(startup.MockStartup)
mockTmux := new(tmux.MockTmux)
mockZoxide := new(zoxide.MockZoxide)
mockTmuxinator := new(tmuxinator.MockTmuxinator)

c := &RealConnector{
model.Config{},
Expand All @@ -33,6 +35,7 @@ func TestConfigStrategy(t *testing.T) {
mockStartup,
mockTmux,
mockZoxide,
mockTmuxinator,
}
mockTmux.On("AttachSession", mock.Anything).Return("attaching", nil)
mockZoxide.On("Add", mock.Anything).Return(nil)
Expand Down
16 changes: 9 additions & 7 deletions connector/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ func (c *RealConnector) Connect(name string, opts model.ConnectOpts) (string, er
// sesh connect --config (sesh list --config | fzf)
strategies := []func(*RealConnector, string) (model.Connection, error){
tmuxStrategy,
tmuxinatorStrategy,
configStrategy,
dirStrategy,
zoxideStrategy,
}

connectStrategy := map[string]func(c *RealConnector, connection model.Connection, opts model.ConnectOpts) (string, error){
"tmux": connectToTmux,
"tmuxinator": connectToTmuxinator,
"config": connectToTmux,
"zoxide": connectToTmux,
}

for _, strategy := range strategies {
if connection, err := strategy(c, name); err != nil {
return "", fmt.Errorf("failed to establish connection: %w", err)
Expand All @@ -28,13 +36,7 @@ func (c *RealConnector) Connect(name string, opts model.ConnectOpts) (string, er
if connection.AddToZoxide {
c.zoxide.Add(connection.Session.Path)
}
if connection.New {
c.tmux.NewSession(connection.Session.Name, connection.Session.Path)
c.startup.Exec(connection.Session)
}
// TODO: configure the ability to create a session in a detached way (like update)
// TODO: configure the ability to create a popup instead of switching (with no tmux bar?)
return c.tmux.SwitchOrAttach(connection.Session.Name, opts)
return connectStrategy[connection.Session.Src](c, connection, opts)
}
}

Expand Down
20 changes: 12 additions & 8 deletions connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/joshmedeski/sesh/namer"
"github.com/joshmedeski/sesh/startup"
"github.com/joshmedeski/sesh/tmux"
"github.com/joshmedeski/sesh/tmuxinator"
"github.com/joshmedeski/sesh/zoxide"
)

Expand All @@ -16,14 +17,15 @@ type Connector interface {
}

type RealConnector struct {
config model.Config
dir dir.Dir
home home.Home
lister lister.Lister
namer namer.Namer
startup startup.Startup
tmux tmux.Tmux
zoxide zoxide.Zoxide
config model.Config
dir dir.Dir
home home.Home
lister lister.Lister
namer namer.Namer
startup startup.Startup
tmux tmux.Tmux
zoxide zoxide.Zoxide
tmuxinator tmuxinator.Tmuxinator
}

func NewConnector(
Expand All @@ -35,6 +37,7 @@ func NewConnector(
startup startup.Startup,
tmux tmux.Tmux,
zoxide zoxide.Zoxide,
tmuxinator tmuxinator.Tmuxinator,
) Connector {
return &RealConnector{
config,
Expand All @@ -45,5 +48,6 @@ func NewConnector(
startup,
tmux,
zoxide,
tmuxinator,
}
}
2 changes: 1 addition & 1 deletion connector/mock_Connector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions connector/tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ func tmuxStrategy(c *RealConnector, name string) (model.Connection, error) {
// Switch: true
}, nil
}

func connectToTmux(c *RealConnector, connection model.Connection, opts model.ConnectOpts) (string, error) {
if connection.New {
return c.tmux.SwitchOrAttach(connection.Session.Name, opts)
}
c.tmux.NewSession(connection.Session.Name, connection.Session.Path)
c.startup.Exec(connection.Session)
return c.tmux.SwitchOrAttach(connection.Session.Name, opts)
}
3 changes: 3 additions & 0 deletions connector/tmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/joshmedeski/sesh/namer"
"github.com/joshmedeski/sesh/startup"
"github.com/joshmedeski/sesh/tmux"
"github.com/joshmedeski/sesh/tmuxinator"
"github.com/joshmedeski/sesh/zoxide"
"github.com/stretchr/testify/assert"
mock "github.com/stretchr/testify/mock"
Expand All @@ -23,6 +24,7 @@ func TestEstablishTmuxConnection(t *testing.T) {
mockStartup := new(startup.MockStartup)
mockTmux := new(tmux.MockTmux)
mockZoxide := new(zoxide.MockZoxide)
mockTmuxinator := new(tmuxinator.MockTmuxinator)

c := &RealConnector{
model.Config{},
Expand All @@ -33,6 +35,7 @@ func TestEstablishTmuxConnection(t *testing.T) {
mockStartup,
mockTmux,
mockZoxide,
mockTmuxinator,
}
mockTmux.On("AttachSession", mock.Anything).Return("attaching", nil)
mockZoxide.On("Add", mock.Anything).Return(nil)
Expand Down
23 changes: 23 additions & 0 deletions connector/tmuxinator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package connector

import (
"github.com/joshmedeski/sesh/model"
)

func tmuxinatorStrategy(c *RealConnector, name string) (model.Connection, error) {
session, exists := c.lister.FindTmuxinatorConfig(name)
if !exists {
return model.Connection{Found: false}, nil
}

return model.Connection{
Found: true,
Session: session,
New: true,
AddToZoxide: false,
}, nil
}

func connectToTmuxinator(c *RealConnector, connection model.Connection, opts model.ConnectOpts) (string, error) {
return c.tmuxinator.Start(connection.Session.Name)
}
2 changes: 1 addition & 1 deletion dir/mock_Dir.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion execwrap/mock_Exec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion execwrap/mock_ExecCmd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion git/mock_Git.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion home/mock_Home.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions icon/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ func NewIcon(config model.Config) Icon {
}

var (
zoxideIcon string = ""
tmuxIcon string = ""
configIcon string = ""
zoxideIcon string = ""
tmuxIcon string = ""
configIcon string = ""
tmuxinatorIcon string = ""
)

func ansiString(code int, s string) string {
Expand All @@ -37,6 +38,9 @@ func (i *RealIcon) AddIcon(s model.SeshSession) string {
case "tmux":
icon = tmuxIcon
colorCode = 34 // blue
case "tmuxinator":
icon = tmuxinatorIcon
colorCode = 33 // yellow
case "zoxide":
icon = zoxideIcon
colorCode = 36 // cyan
Expand All @@ -51,7 +55,7 @@ func (i *RealIcon) AddIcon(s model.SeshSession) string {
}

func (i *RealIcon) RemoveIcon(name string) string {
if strings.HasPrefix(name, tmuxIcon) || strings.HasPrefix(name, zoxideIcon) || strings.HasPrefix(name, configIcon) {
if strings.HasPrefix(name, tmuxIcon) || strings.HasPrefix(name, zoxideIcon) || strings.HasPrefix(name, configIcon) || strings.HasPrefix(name, tmuxinatorIcon) {
return name[4:]
}
return name
Expand Down
2 changes: 1 addition & 1 deletion icon/mock_Icon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion json/mock_Json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lister/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func listConfig(l *RealLister) (model.SeshSessions, error) {
Name: session.Name,
Path: path,
StartupCommand: session.StartupCommand,
Tmuxinator: session.Tmuxinator,
}
}
}
Expand All @@ -36,8 +37,8 @@ func listConfig(l *RealLister) (model.SeshSessions, error) {
}

func (l *RealLister) FindConfigSession(name string) (model.SeshSession, bool) {
sessions, _ := listConfig(l)
key := configKey(name)
sessions, _ := listConfig(l)
if session, exists := sessions.Directory[key]; exists {
return session, exists
} else {
Expand Down
4 changes: 3 additions & 1 deletion lister/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/joshmedeski/sesh/home"
"github.com/joshmedeski/sesh/model"
"github.com/joshmedeski/sesh/tmux"
"github.com/joshmedeski/sesh/tmuxinator"
"github.com/joshmedeski/sesh/zoxide"
"github.com/stretchr/testify/assert"
)
Expand All @@ -16,6 +17,7 @@ func TestListConfigSessions(t *testing.T) {
mockHome.On("ExpandHome", "/Users/joshmedeski/.config/sesh").Return("/Users/joshmedeski/.config/sesh", nil)
mockZoxide := new(zoxide.MockZoxide)
mockTmux := new(tmux.MockTmux)
mockTmuxinator := new(tmuxinator.MockTmuxinator)
config := model.Config{
SessionConfigs: []model.SessionConfig{
{
Expand All @@ -24,7 +26,7 @@ func TestListConfigSessions(t *testing.T) {
},
},
}
lister := NewLister(config, mockHome, mockTmux, mockZoxide)
lister := NewLister(config, mockHome, mockTmux, mockZoxide, mockTmuxinator)

realLister, ok := lister.(*RealLister)
if !ok {
Expand Down
8 changes: 5 additions & 3 deletions lister/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ type (
Json bool
Tmux bool
Zoxide bool
Tmuxinator bool
}
srcStrategy func(*RealLister) (model.SeshSessions, error)
)

var srcStrategies = map[string]srcStrategy{
"tmux": listTmux,
"config": listConfig,
"zoxide": listZoxide,
"tmux": listTmux,
"config": listConfig,
"tmuxinator": listTmuxinator,
"zoxide": listZoxide,
}

func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
Expand Down
15 changes: 9 additions & 6 deletions lister/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/joshmedeski/sesh/home"
"github.com/joshmedeski/sesh/model"
"github.com/joshmedeski/sesh/tmux"
"github.com/joshmedeski/sesh/tmuxinator"
"github.com/joshmedeski/sesh/zoxide"
)

Expand All @@ -13,15 +14,17 @@ type Lister interface {
GetLastTmuxSession() (model.SeshSession, bool)
FindConfigSession(name string) (model.SeshSession, bool)
FindZoxideSession(name string) (model.SeshSession, bool)
FindTmuxinatorConfig(name string) (model.SeshSession, bool)
}

type RealLister struct {
home home.Home
tmux tmux.Tmux
zoxide zoxide.Zoxide
config model.Config
config model.Config
home home.Home
tmux tmux.Tmux
zoxide zoxide.Zoxide
tmuxinator tmuxinator.Tmuxinator
}

func NewLister(config model.Config, home home.Home, tmux tmux.Tmux, zoxide zoxide.Zoxide) Lister {
return &RealLister{home, tmux, zoxide, config}
func NewLister(config model.Config, home home.Home, tmux tmux.Tmux, zoxide zoxide.Zoxide, tmuxinator tmuxinator.Tmuxinator) Lister {
return &RealLister{config, home, tmux, zoxide, tmuxinator}
}
Loading