Skip to content

Commit

Permalink
feat: add root flag to connect command
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmedeski committed Sep 27, 2024
1 parent eb0adc1 commit 008312f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion seshcli/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"strings"

"github.com/joshmedeski/sesh/connector"
"github.com/joshmedeski/sesh/dir"
"github.com/joshmedeski/sesh/icon"
"github.com/joshmedeski/sesh/model"
cli "github.com/urfave/cli/v2"
)

func Connect(c connector.Connector, i icon.Icon) *cli.Command {
func Connect(c connector.Connector, i icon.Icon, d dir.Dir) *cli.Command {
return &cli.Command{
Name: "connect",
Aliases: []string{"cn"},
Expand All @@ -32,6 +33,11 @@ func Connect(c connector.Connector, i icon.Icon) *cli.Command {
Aliases: []string{"T"},
Usage: "Use tmuxinator to start session if it doesnt exist",
},
&cli.BoolFlag{
Name: "root",
Aliases: []string{"r"},
Usage: "Switches to the root of the current session",
},
},
Action: func(cCtx *cli.Context) error {
if cCtx.NArg() == 0 {
Expand All @@ -41,6 +47,14 @@ func Connect(c connector.Connector, i icon.Icon) *cli.Command {
if name == "" {
return nil
}

if cCtx.Bool("root") {
hasRootDir, rootDir := d.RootDir(name)
if hasRootDir {
name = rootDir
}
}

opts := model.ConnectOpts{Switch: cCtx.Bool("switch"), Command: cCtx.String("command"), Tmuxinator: cCtx.Bool("tmuxinator")}
trimmedName := i.RemoveIcon(name)
if _, err := c.Connect(trimmedName, opts); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions seshcli/seshcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func App(version string) cli.App {
runtime := runtimewrap.NewRunTime()

// base dependencies
dir := dir.NewDir(os, path)
shell := shell.NewShell(exec)
home := home.NewHome(os)
json := json.NewJson()

// resource dependencies
git := git.NewGit(shell)
dir := dir.NewDir(os, git, path)
tmux := tmux.NewTmux(os, shell)
zoxide := zoxide.NewZoxide(shell)
tmuxinator := tmuxinator.NewTmuxinator(shell)
Expand All @@ -62,7 +62,7 @@ func App(version string) cli.App {
Commands: []*cli.Command{
List(icon, json, lister),
Last(lister, tmux),
Connect(connector, icon),
Connect(connector, icon, dir),
Clone(),
},
}
Expand Down

0 comments on commit 008312f

Please sign in to comment.