-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve connect.Connect error handling (#44)
- Loading branch information
1 parent
500a9af
commit 8623bb7
Showing
7 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
package connect | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/joshmedeski/sesh/session" | ||
"github.com/joshmedeski/sesh/tmux" | ||
"github.com/joshmedeski/sesh/zoxide" | ||
) | ||
|
||
func Connect(choice string, alwaysSwitch bool, command string) error { | ||
session := session.Determine(choice) | ||
zoxide.Add(session.Path) | ||
tmux.Connect(tmux.TmuxSession{ | ||
Name: session.Name, | ||
Path: session.Path, | ||
}, alwaysSwitch, command) | ||
return nil | ||
session, err := session.Determine(choice) | ||
if err != nil { | ||
return fmt.Errorf("unable to connect to %q: %w", choice, err) | ||
} | ||
|
||
if err := zoxide.Add(session.Path); err != nil { | ||
return fmt.Errorf("unable to connect to %q: %w", choice, err) | ||
} | ||
|
||
return tmux.Connect( | ||
tmux.TmuxSession{Name: session.Name, Path: session.Path}, | ||
alwaysSwitch, | ||
command, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
package session | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
func Determine(choice string) Session { | ||
func Determine(choice string) (s Session, err error) { | ||
path, err := DeterminePath(choice) | ||
if err != nil { | ||
log.Fatal("Couldn't determine the session path", err) | ||
return s, fmt.Errorf( | ||
"couldn't determine the path for %q: %w", | ||
choice, | ||
err, | ||
) | ||
} | ||
s.Path = path | ||
|
||
name := DetermineName(path) | ||
if name == "" { | ||
log.Fatal("Couldn't determine the session name", err) | ||
return s, fmt.Errorf( | ||
"couldn't determine the session name for %q", | ||
choice, | ||
) | ||
} | ||
s.Name = name | ||
|
||
return Session{ | ||
Name: name, | ||
Path: path, | ||
} | ||
return s, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters