Skip to content

Commit

Permalink
fix: use existing sessions path for adding to zoxide
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmedeski committed Jan 25, 2024
1 parent e6e2879 commit db29565
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions session/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func DeterminePath(choice string) (string, error) {
return fullPath, nil
}

if tmux.IsSession(fullPath) {
return fullPath, nil
isSession, sessionPath := tmux.IsSession(fullPath)
if isSession && sessionPath != "" {
return sessionPath, nil
}

zoxideResult, err := zoxide.Query(fullPath)
Expand Down
12 changes: 6 additions & 6 deletions tmux/tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ func isAttached() bool {
return len(os.Getenv("TMUX")) > 0
}

func IsSession(session string) bool {
func IsSession(session string) (bool, string) {
sessions, err := List()
if err != nil {
return false
return false, ""
}

for _, s := range sessions {
if s.Name == session {
return true
return true, s.Path
}
}
return false
return false, ""
}

func attachSession(session string) error {
Expand Down Expand Up @@ -83,11 +83,11 @@ func NewSession(s TmuxSession) (string, error) {
}

func Connect(s TmuxSession, alwaysSwitch bool, command string) error {
isSession := IsSession(s.Name)
isSession, _ := IsSession(s.Name)
if !isSession {
_, err := NewSession(s)
if err != nil {
fmt.Errorf("unable to connect to tmux session %q: %w", s.Name, err)
return fmt.Errorf("unable to connect to tmux session %q: %w", s.Name, err)
}
if command != "" {
runPersistentCommand(s.Name, command)
Expand Down

0 comments on commit db29565

Please sign in to comment.