Skip to content

Commit db29565

Browse files
committed
fix: use existing sessions path for adding to zoxide
1 parent e6e2879 commit db29565

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

session/path.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ func DeterminePath(choice string) (string, error) {
3030
return fullPath, nil
3131
}
3232

33-
if tmux.IsSession(fullPath) {
34-
return fullPath, nil
33+
isSession, sessionPath := tmux.IsSession(fullPath)
34+
if isSession && sessionPath != "" {
35+
return sessionPath, nil
3536
}
3637

3738
zoxideResult, err := zoxide.Query(fullPath)

tmux/tmux.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ func isAttached() bool {
3636
return len(os.Getenv("TMUX")) > 0
3737
}
3838

39-
func IsSession(session string) bool {
39+
func IsSession(session string) (bool, string) {
4040
sessions, err := List()
4141
if err != nil {
42-
return false
42+
return false, ""
4343
}
4444

4545
for _, s := range sessions {
4646
if s.Name == session {
47-
return true
47+
return true, s.Path
4848
}
4949
}
50-
return false
50+
return false, ""
5151
}
5252

5353
func attachSession(session string) error {
@@ -83,11 +83,11 @@ func NewSession(s TmuxSession) (string, error) {
8383
}
8484

8585
func Connect(s TmuxSession, alwaysSwitch bool, command string) error {
86-
isSession := IsSession(s.Name)
86+
isSession, _ := IsSession(s.Name)
8787
if !isSession {
8888
_, err := NewSession(s)
8989
if err != nil {
90-
fmt.Errorf("unable to connect to tmux session %q: %w", s.Name, err)
90+
return fmt.Errorf("unable to connect to tmux session %q: %w", s.Name, err)
9191
}
9292
if command != "" {
9393
runPersistentCommand(s.Name, command)

0 commit comments

Comments
 (0)