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 Last Command #165

Merged
merged 5 commits into from
Sep 13, 2024
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ bind-key x kill-pane # skip "kill-pane 1? (y/n)" prompt
set -g detach-on-destroy off # don't exit from tmux when closing a session
```

## Bonus: sesh last

The default `<prefix>+L` command will "Switch the attached client back to the last session." However, if you close a session while `detach-on-destroy off` is set, the last session will not be found. To fix this, I have a `sesh last` command that will always switch the client to the second to last session that has been attached.

Add the following to your `tmux.conf` to overwrite the default `last-session` command:

```sh
bind -N "last-session (via sesh) " L run-shell "sesh-dev last"
```

````

## Configuration

You can configure sesh by creating a `sesh.toml` file in your `$XDG_CONFIG_HOME/sesh` or `$HOME/.config/sesh` directory.
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.

1 change: 1 addition & 0 deletions lister/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type Lister interface {
List(opts ListOptions) (model.SeshSessions, error)
FindTmuxSession(name string) (model.SeshSession, bool)
GetLastTmuxSession() (model.SeshSession, bool)
FindConfigSession(name string) (model.SeshSession, bool)
FindZoxideSession(name string) (model.SeshSession, bool)
}
Expand Down
57 changes: 56 additions & 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.

12 changes: 12 additions & 0 deletions lister/tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ func (l *RealLister) FindTmuxSession(name string) (model.SeshSession, bool) {
return model.SeshSession{}, false
}
}

func (l *RealLister) GetLastTmuxSession() (model.SeshSession, bool) {
sessions, err := listTmux(l)
if err != nil {
return model.SeshSession{}, false
}
if len(sessions.OrderedIndex) < 2 {
return model.SeshSession{}, false
}
secondSessionIndex := sessions.OrderedIndex[1]
return sessions.Directory[secondSessionIndex], true
}
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 runtimewrap/mock_Runtime.go

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

26 changes: 26 additions & 0 deletions seshcli/last.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seshcli

import (
"github.com/joshmedeski/sesh/lister"
"github.com/joshmedeski/sesh/tmux"
cli "github.com/urfave/cli/v2"
)

func Last(l lister.Lister, t tmux.Tmux) *cli.Command {
return &cli.Command{
Name: "last",
Aliases: []string{"L"},
Usage: "Connect to the last tmux session",
UseShortOptionHandling: true,
Flags: []cli.Flag{},
Action: func(cCtx *cli.Context) error {
lastSession, exists := l.GetLastTmuxSession()
if !exists {
// TODO: silently fail?
return cli.Exit("No last session found", 1)
}
t.SwitchClient(lastSession.Name)
return nil
},
}
}
1 change: 1 addition & 0 deletions seshcli/seshcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func App(version string) cli.App {
Usage: "Smart session manager for the terminal",
Commands: []*cli.Command{
List(icon, json, lister),
Last(lister, tmux),
Connect(connector, icon),
Clone(),
},
Expand Down
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 zoxide/mock_Zoxide.go

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