Skip to content

Commit

Permalink
fix: add determine logic back
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmedeski committed Feb 4, 2024
1 parent 960bd75 commit 7b283a7
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions connect/connect.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package connect

import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/joshmedeski/sesh/config"
"github.com/joshmedeski/sesh/session"
"github.com/joshmedeski/sesh/tmux"
"github.com/joshmedeski/sesh/zoxide"
)
Expand All @@ -17,45 +15,15 @@ func Connect(
command string,
config *config.Config,
) error {
var errorStack []error
isActiveSession := true
s, err := tmux.GetSession(choice)
session, err := session.Determine(choice, config)
if err != nil {
isActiveSession = false
errorStack = append(errorStack, err)
}
if !isActiveSession {
p, err := filepath.Abs(choice)
if err != nil {
errorStack = append(errorStack, err)
p = choice
}
info, err := os.Stat(p)
if err != nil {
errorStack = append(errorStack, err)
return fmt.Errorf(
"unable to connect to %q: %w",
choice,
errors.Join(errorStack...),
)
}
if !info.IsDir() {
errorStack = append(
errorStack,
fmt.Errorf("%q found but is not a directory", p),
)
return errors.Join(errorStack...)
}
s = tmux.TmuxSession{
Name: filepath.Base(p),
Path: p,
Attached: 0,
}
return fmt.Errorf("unable to connect to %q: %w", choice, err)
}

if err = zoxide.Add(s.Path); err != nil {
if err = zoxide.Add(session.Path); err != nil {
return fmt.Errorf("unable to connect to %q: %w", choice, err)
}

return tmux.Connect(s, alwaysSwitch, command, s.Path, config)
return tmux.Connect(tmux.TmuxSession{
Name: session.Name,
Path: session.Path,
}, alwaysSwitch, command, session.Path, config)
}

0 comments on commit 7b283a7

Please sign in to comment.