Skip to content

Commit 7b283a7

Browse files
committed
fix: add determine logic back
1 parent 960bd75 commit 7b283a7

File tree

1 file changed

+8
-40
lines changed

1 file changed

+8
-40
lines changed

connect/connect.go

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package connect
22

33
import (
4-
"errors"
54
"fmt"
6-
"os"
7-
"path/filepath"
85

96
"github.com/joshmedeski/sesh/config"
7+
"github.com/joshmedeski/sesh/session"
108
"github.com/joshmedeski/sesh/tmux"
119
"github.com/joshmedeski/sesh/zoxide"
1210
)
@@ -17,45 +15,15 @@ func Connect(
1715
command string,
1816
config *config.Config,
1917
) error {
20-
var errorStack []error
21-
isActiveSession := true
22-
s, err := tmux.GetSession(choice)
18+
session, err := session.Determine(choice, config)
2319
if err != nil {
24-
isActiveSession = false
25-
errorStack = append(errorStack, err)
26-
}
27-
if !isActiveSession {
28-
p, err := filepath.Abs(choice)
29-
if err != nil {
30-
errorStack = append(errorStack, err)
31-
p = choice
32-
}
33-
info, err := os.Stat(p)
34-
if err != nil {
35-
errorStack = append(errorStack, err)
36-
return fmt.Errorf(
37-
"unable to connect to %q: %w",
38-
choice,
39-
errors.Join(errorStack...),
40-
)
41-
}
42-
if !info.IsDir() {
43-
errorStack = append(
44-
errorStack,
45-
fmt.Errorf("%q found but is not a directory", p),
46-
)
47-
return errors.Join(errorStack...)
48-
}
49-
s = tmux.TmuxSession{
50-
Name: filepath.Base(p),
51-
Path: p,
52-
Attached: 0,
53-
}
20+
return fmt.Errorf("unable to connect to %q: %w", choice, err)
5421
}
55-
56-
if err = zoxide.Add(s.Path); err != nil {
22+
if err = zoxide.Add(session.Path); err != nil {
5723
return fmt.Errorf("unable to connect to %q: %w", choice, err)
5824
}
59-
60-
return tmux.Connect(s, alwaysSwitch, command, s.Path, config)
25+
return tmux.Connect(tmux.TmuxSession{
26+
Name: session.Name,
27+
Path: session.Path,
28+
}, alwaysSwitch, command, session.Path, config)
6129
}

0 commit comments

Comments
 (0)