Skip to content
Merged
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ You can configure sesh by creating a `sesh.toml` file in your `$XDG_CONFIG_HOME/
mkdir -p ~/.config/sesh && touch ~/.config/sesh/sesh.toml
```

### Blacklist

You may want to blacklist certain tmux sessions from showing up in the results. For example, you may want to exclude your `scratch` directory from the results.

```sh
blacklist = ["scratch"]
```

> [!NOTE]
> Works great with [tmux-floatx](https://github.com/omerxx/tmux-floax)

### Default Session

The default session can be configured to run a command when connecting to a session. This is useful for running a dev server or starting a tmux plugin.
Expand Down
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.

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.

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.

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.

20 changes: 20 additions & 0 deletions lister/blacklist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package lister

import "strings"

func isBlacklisted(blacklist []string, name string) bool {
for _, blacklistedName := range blacklist {
if strings.EqualFold(blacklistedName, name) {
return true
}
}
return false
}

func createBlacklistSet(blacklist []string) map[string]struct{} {
blacklistSet := make(map[string]struct{}, len(blacklist))
for _, name := range blacklist {
blacklistSet[name] = struct{}{}
}
return blacklistSet
}
2 changes: 1 addition & 1 deletion lister/mock_Lister.go

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

2 changes: 1 addition & 1 deletion lister/mock_srcStrategy.go

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

29 changes: 17 additions & 12 deletions lister/tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ func listTmux(l *RealLister) (model.SeshSessions, error) {
if err != nil {
return model.SeshSessions{}, fmt.Errorf("couldn't list tmux sessions: %q", err)
}
numOfSessions := len(tmuxSessions)
orderedIndex := make([]string, numOfSessions)
directory := make(model.SeshSessionMap)
for i, session := range tmuxSessions {
key := tmuxKey(session.Name)
orderedIndex[i] = key
directory[key] = model.SeshSession{
Src: "tmux",
Name: session.Name,
Path: session.Path,
Attached: session.Attached,
Windows: session.Windows,

blacklistSet := createBlacklistSet(l.config.Blacklist)
directory := make(map[string]model.SeshSession)
orderedIndex := []string{}

for _, session := range tmuxSessions {
if _, blacklisted := blacklistSet[session.Name]; !blacklisted {
key := tmuxKey(session.Name)
orderedIndex = append(orderedIndex, key)
directory[key] = model.SeshSession{
Src: "tmux",
Name: session.Name,
Path: session.Path,
Attached: session.Attached,
Windows: session.Windows,
}
}
}

return model.SeshSessions{
Directory: directory,
OrderedIndex: orderedIndex,
Expand Down
104 changes: 104 additions & 0 deletions lister/tmux_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lister

import (
"fmt"
"log"
"testing"
"time"
Expand Down Expand Up @@ -90,3 +91,106 @@ func TestListTmuxSessions(t *testing.T) {
assert.Equal(t, nil, err)
})
}

func TestListTmuxSessionsError(t *testing.T) {
mockTmux := new(tmux.MockTmux)
t.Run("should return error when unable to list tmux sessions", func(t *testing.T) {
mockTmux.On("ListSessions").Return(nil, fmt.Errorf("some error"))

mockConfig := model.Config{}
mockHome := new(home.MockHome)
mockZoxide := new(zoxide.MockZoxide)
mockTmuxinator := new(tmuxinator.MockTmuxinator)
lister := NewLister(mockConfig, mockHome, mockTmux, mockZoxide, mockTmuxinator)

realLister, ok := lister.(*RealLister)
if !ok {
log.Fatal("Cannot convert lister to *RealLister")
}

sessions, err := listTmux(realLister)
assert.Equal(t, model.SeshSessions{}, sessions)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "couldn't list tmux sessions")
})
}

func TestBlacklistHidesTmuxSession(t *testing.T) {
mockTmux := new(tmux.MockTmux)
t.Run("should hide blacklisted tmux sessions", func(t *testing.T) {
const timeFormat = "2006-01-02 15:04:05 -0700 MST"
createdFA, _ := time.Parse(timeFormat, "2024-04-25 19:02:45 -0500 CDT")
lastAttachedFA, _ := time.Parse(timeFormat, "2024-04-25 19:30:06 -0500 CDT")
activityFA, _ := time.Parse(timeFormat, "2024-04-25 19:44:06 -0500 CDT")
firstAttached := model.TmuxSession{
Created: &createdFA,
LastAttached: &lastAttachedFA,
Activity: &activityFA,
Group: "",
Path: "/Users/joshmedeski/c/sesh/main",
Name: "sesh/main",
ID: "$1",
AttachedList: []string{""},
GroupList: []string{""},
GroupAttachedList: []string{""},
Stack: []int{2, 1},
Alerts: []int{},
GroupSize: 0,
GroupAttached: 0,
Attached: 0,
Windows: 2,
Format: true,
GroupManyAttached: false,
Grouped: false,
ManyAttached: false,
Marked: false,
}

createdLA, _ := time.Parse(timeFormat, "2024-04-25 19:02:45 -0500 CDT")
lastAttachedLA, _ := time.Parse(timeFormat, "2024-04-25 19:44:06 -0500 CDT")
activityLA, _ := time.Parse(timeFormat, "2024-04-25 19:44:06 -0500 CDT")
lastAttached := model.TmuxSession{
Created: &createdLA,
LastAttached: &lastAttachedLA,
Activity: &activityLA,
Group: "",
Path: "/Users/joshmedeski/c/sesh/v2",
Name: "sesh/v2",
ID: "$1",
AttachedList: []string{""},
GroupList: []string{""},
GroupAttachedList: []string{""},
Stack: []int{2, 1},
Alerts: []int{},
GroupSize: 0,
GroupAttached: 0,
Attached: 0,
Windows: 2,
Format: true,
GroupManyAttached: false,
Grouped: false,
ManyAttached: false,
Marked: false,
}
mockTmux.On("ListSessions").Return([]*model.TmuxSession{&firstAttached, &lastAttached}, nil)

mockConfig := model.Config{
Blacklist: []string{"sesh/main"},
}
mockHome := new(home.MockHome)
mockZoxide := new(zoxide.MockZoxide)
mockTmuxinator := new(tmuxinator.MockTmuxinator)
lister := NewLister(mockConfig, mockHome, mockTmux, mockZoxide, mockTmuxinator)

realLister, ok := lister.(*RealLister)
if !ok {
log.Fatal("Cannot convert lister to *RealLister")
}

sessions, err := listTmux(realLister)
assert.Equal(t, 1, len(sessions.OrderedIndex))
assert.Equal(t, "tmux:sesh/v2", sessions.OrderedIndex[0])
assert.Equal(t, "sesh/v2", sessions.Directory["tmux:sesh/v2"].Name)
assert.Equal(t, nil, err)
})
}
2 changes: 1 addition & 1 deletion ls/mock_Ls.go

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

1 change: 1 addition & 0 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type (
Config struct {
ImportPaths []string `toml:"import"`
DefaultSessionConfig DefaultSessionConfig `toml:"default_session"`
Blacklist []string `toml:"blacklist"`
SessionConfigs []SessionConfig `toml:"session"`
}

Expand Down
2 changes: 1 addition & 1 deletion namer/mock_Namer.go

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

2 changes: 1 addition & 1 deletion oswrap/mock_Os.go

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

2 changes: 1 addition & 1 deletion pathwrap/mock_Path.go

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

2 changes: 1 addition & 1 deletion previewer/mock_PreviewStrategy.go

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

2 changes: 1 addition & 1 deletion previewer/mock_Previewer.go

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

2 changes: 1 addition & 1 deletion runtimewrap/mock_Runtime.go

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

2 changes: 1 addition & 1 deletion shell/mock_Shell.go

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

2 changes: 1 addition & 1 deletion startup/mock_Startup.go

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

2 changes: 1 addition & 1 deletion tmux/mock_Tmux.go

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

2 changes: 1 addition & 1 deletion tmuxinator/mock_Tmuxinator.go

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

2 changes: 1 addition & 1 deletion zoxide/mock_Zoxide.go

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