Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ Available fields:
| `startup_command` | Command to run on session creation (supports `{}` for path) |
| `preview_command` | Command to run when previewing the session |
| `disable_startup_command` | Set to `true` to suppress the startup command |
| `windows` | Window layout to use (array of window names from `[[window]]` configs) |

**Note:** Patterns use Go's `filepath.Match` syntax which supports `*` (any sequence), `?` (single character), and `[...]` (character classes). Recursive matching with `**` is not supported -- `~/projects/*` matches `~/projects/foo` but not `~/projects/foo/bar`. Explicit `[[session]]` configs always take priority over wildcard matches. If multiple wildcards match, the first one in config order wins.

Expand Down
10 changes: 6 additions & 4 deletions connector/config_wildcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func configWildcardStrategy(c *RealConnector, name string) (model.Connection, error) {
_, found := c.lister.FindConfigWildcard(name)
wc, found := c.lister.FindConfigWildcard(name)
if !found {
return model.Connection{Found: false}, nil
}
Expand All @@ -30,9 +30,11 @@ func configWildcardStrategy(c *RealConnector, name string) (model.Connection, er
New: true,
AddToZoxide: true,
Session: model.SeshSession{
Src: "config_wildcard",
Name: nameFromPath,
Path: absPath,
Src: "config_wildcard",
Name: nameFromPath,
Path: absPath,
WindowNames: wc.Windows,
DisableStartupCommand: wc.DisableStartCommand,
},
}, nil
}
17 changes: 17 additions & 0 deletions connector/config_wildcard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestConfigWildcardStrategy(t *testing.T) {
mockLister.On("FindConfigWildcard", "~/projects/myapp").Return(model.WildcardConfig{
Pattern: "~/projects/*",
StartupCommand: "nvim",
Windows: []string{"code", "server"},
}, true)
mockHome.On("ExpandHome", "~/projects/myapp").Return("/Users/test/projects/myapp", nil)
mockDir.On("Dir", "/Users/test/projects/myapp").Return(true, "/Users/test/projects/myapp")
Expand All @@ -54,6 +55,22 @@ func TestConfigWildcardStrategy(t *testing.T) {
assert.Equal(t, "myapp", connection.Session.Name)
assert.Equal(t, "/Users/test/projects/myapp", connection.Session.Path)
assert.Equal(t, "config_wildcard", connection.Session.Src)
assert.Equal(t, []string{"code", "server"}, connection.Session.WindowNames)
})

t.Run("should propagate DisableStartupCommand from wildcard config", func(t *testing.T) {
mockLister.On("FindConfigWildcard", "~/projects/quiet").Return(model.WildcardConfig{
Pattern: "~/projects/*",
DisableStartCommand: true,
}, true)
mockHome.On("ExpandHome", "~/projects/quiet").Return("/Users/test/projects/quiet", nil)
mockDir.On("Dir", "/Users/test/projects/quiet").Return(true, "/Users/test/projects/quiet")
mockNamer.On("Name", "/Users/test/projects/quiet").Return("quiet", nil)

connection, err := configWildcardStrategy(c, "~/projects/quiet")
assert.Nil(t, err)
assert.True(t, connection.Found)
assert.True(t, connection.Session.DisableStartupCommand)
})

t.Run("should return not found when no wildcard matches", func(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ type (
}

WildcardConfig struct {
Pattern string `toml:"pattern"`
StartupCommand string `toml:"startup_command"`
DisableStartCommand bool `toml:"disable_startup_command"`
PreviewCommand string `toml:"preview_command"`
Pattern string `toml:"pattern"`
StartupCommand string `toml:"startup_command"`
DisableStartCommand bool `toml:"disable_startup_command"`
PreviewCommand string `toml:"preview_command"`
Windows []string `toml:"windows"`
}
)
7 changes: 7 additions & 0 deletions sesh.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@
"preview_command": {
"type": "string",
"description": "Command used to generate the preview for matching sessions"
},
"windows": {
"type": "array",
"description": "Window layout to use for matching sessions",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down