Skip to content

Commit 0f93be1

Browse files
committed
feat: add startup command
1 parent 6a62cbe commit 0f93be1

File tree

17 files changed

+333
-41
lines changed

17 files changed

+333
-41
lines changed

cloner/mock_Cloner.go

Lines changed: 88 additions & 0 deletions
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
@@ -8,6 +8,7 @@ import (
88
"github.com/joshmedeski/sesh/lister"
99
"github.com/joshmedeski/sesh/model"
1010
"github.com/joshmedeski/sesh/namer"
11+
"github.com/joshmedeski/sesh/startup"
1112
"github.com/joshmedeski/sesh/tmux"
1213
"github.com/joshmedeski/sesh/zoxide"
1314
"github.com/stretchr/testify/assert"
@@ -19,6 +20,7 @@ func TestConfigStrategy(t *testing.T) {
1920
mockHome := new(home.MockHome)
2021
mockLister := new(lister.MockLister)
2122
mockNamer := new(namer.MockNamer)
23+
mockStartup := new(startup.MockStartup)
2224
mockTmux := new(tmux.MockTmux)
2325
mockZoxide := new(zoxide.MockZoxide)
2426

@@ -28,6 +30,7 @@ func TestConfigStrategy(t *testing.T) {
2830
mockHome,
2931
mockLister,
3032
mockNamer,
33+
mockStartup,
3134
mockTmux,
3235
mockZoxide,
3336
}

connector/connect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ func (c *RealConnector) Connect(name string, opts model.ConnectOpts) (string, er
2121

2222
for _, strategy := range strategies {
2323
if connection, err := strategy(c, name); err != nil {
24-
} else if connection.Found {
2524
return "", fmt.Errorf("failed to establish connection: %w", err)
25+
} else if connection.Found {
2626
// TODO: allow CLI flag to disable zoxide and overwrite all settings?
2727
// sesh connect --ignore-zoxide "dotfiles"
2828
if connection.AddToZoxide {
2929
c.zoxide.Add(connection.Session.Path)
3030
}
3131
if connection.New {
3232
c.tmux.NewSession(connection.Session.Name, connection.Session.Path)
33+
c.startup.Exec(connection.Session)
3334
}
3435
// TODO: configure the ability to create a session in a detached way (like update)
3536
// TODO: configure the ability to create a popup instead of switching (with no tmux bar?)

connector/connector.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/joshmedeski/sesh/lister"
77
"github.com/joshmedeski/sesh/model"
88
"github.com/joshmedeski/sesh/namer"
9+
"github.com/joshmedeski/sesh/startup"
910
"github.com/joshmedeski/sesh/tmux"
1011
"github.com/joshmedeski/sesh/zoxide"
1112
)
@@ -15,13 +16,14 @@ type Connector interface {
1516
}
1617

1718
type RealConnector struct {
18-
config model.Config
19-
dir dir.Dir
20-
home home.Home
21-
lister lister.Lister
22-
namer namer.Namer
23-
tmux tmux.Tmux
24-
zoxide zoxide.Zoxide
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
2527
}
2628

2729
func NewConnector(
@@ -30,6 +32,7 @@ func NewConnector(
3032
home home.Home,
3133
lister lister.Lister,
3234
namer namer.Namer,
35+
startup startup.Startup,
3336
tmux tmux.Tmux,
3437
zoxide zoxide.Zoxide,
3538
) Connector {
@@ -39,6 +42,7 @@ func NewConnector(
3942
home,
4043
lister,
4144
namer,
45+
startup,
4246
tmux,
4347
zoxide,
4448
}

connector/tmux_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/joshmedeski/sesh/lister"
99
"github.com/joshmedeski/sesh/model"
1010
"github.com/joshmedeski/sesh/namer"
11+
"github.com/joshmedeski/sesh/startup"
1112
"github.com/joshmedeski/sesh/tmux"
1213
"github.com/joshmedeski/sesh/zoxide"
1314
"github.com/stretchr/testify/assert"
@@ -19,6 +20,7 @@ func TestEstablishTmuxConnection(t *testing.T) {
1920
mockHome := new(home.MockHome)
2021
mockLister := new(lister.MockLister)
2122
mockNamer := new(namer.MockNamer)
23+
mockStartup := new(startup.MockStartup)
2224
mockTmux := new(tmux.MockTmux)
2325
mockZoxide := new(zoxide.MockZoxide)
2426

@@ -28,6 +30,7 @@ func TestEstablishTmuxConnection(t *testing.T) {
2830
mockHome,
2931
mockLister,
3032
mockNamer,
33+
mockStartup,
3134
mockTmux,
3235
mockZoxide,
3336
}

lister/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ func listConfig(l *RealLister) (model.SeshSessions, error) {
2222
return model.SeshSessions{}, fmt.Errorf("couldn't expand home: %q", err)
2323
}
2424
directory[key] = model.SeshSession{
25-
Src: "config",
26-
Name: session.Name,
27-
Path: path,
25+
Src: "config",
26+
Name: session.Name,
27+
Path: path,
28+
StartupCommand: session.StartupCommand,
2829
}
2930
}
3031
}

model/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ type (
88
}
99

1010
DefaultSessionConfig struct {
11-
StartupScript string `toml:"startup_script"`
11+
// TODO: mention breaking change in v2 release notes
12+
// StartupScript string `toml:"startup_script"`
1213
StartupCommand string `toml:"startup_command"`
1314
Tmuxp string `toml:"tmuxp"`
1415
Tmuxinator string `toml:"tmuxinator"`

model/sesh_session.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ type (
1515
Name string // The display name
1616
Path string // The absolute directory path
1717

18-
Attached int // Whether the session is currently attached
19-
Windows int // The number of windows in the session
20-
Score float64 // The score of the session (from Zoxide)
18+
StartupCommand string // The command to run when the session is started
19+
Attached int // Whether the session is currently attached
20+
Windows int // The number of windows in the session
21+
Score float64 // The score of the session (from Zoxide)
2122
}
2223

2324
SeshSrcs struct {

namer/git.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import "strings"
55
// Gets the name from a git bare repository
66
func gitBareName(n *RealNamer, path string) (string, error) {
77
var name string
8-
isGit, commonDir, err := n.git.GitCommonDir(path)
9-
if err != nil {
10-
return "", err
11-
}
8+
isGit, commonDir, _ := n.git.GitCommonDir(path)
129
if isGit && strings.HasSuffix(commonDir, "/.bare") {
1310
topLevelDir := strings.TrimSuffix(commonDir, "/.bare")
1411
relativePath := strings.TrimPrefix(path, topLevelDir)

namer/namer_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,3 @@ func TestFromPath(t *testing.T) {
3838
assert.Equal(t, "neovim", name)
3939
})
4040
}
41-
42-
func TestConvertToValidName(t *testing.T) {
43-
t.Run("Test with dot", func(t *testing.T) {
44-
input := "test.name"
45-
want := "test_name"
46-
assert.Equal(t, want, convertToValidName(input))
47-
})
48-
49-
t.Run("Test with colon", func(t *testing.T) {
50-
input := "test:name"
51-
want := "test_name"
52-
assert.Equal(t, want, convertToValidName(input))
53-
})
54-
55-
t.Run("Test with multiple special characters", func(t *testing.T) {
56-
input := "test.name:with.multiple"
57-
want := "test_name_with_multiple"
58-
assert.Equal(t, want, convertToValidName(input))
59-
})
60-
}

0 commit comments

Comments
 (0)