-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattach.go
More file actions
62 lines (56 loc) · 1.44 KB
/
attach.go
File metadata and controls
62 lines (56 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"fmt"
"github.com/urfave/cli/v3"
"github.com/winter-again/flow/internal/tmux"
)
func Attach() *cli.Command {
var target string
socketName, socketPath := tmux.GetDefaultSocket()
return &cli.Command{
Name: "attach",
Aliases: []string{"a"},
Usage: "Attach to existing tmux server and session",
MutuallyExclusiveFlags: []cli.MutuallyExclusiveFlags{
{
Flags: [][]cli.Flag{
{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Value: socketName,
Usage: "tmux server socket name",
Destination: &socketName,
},
},
{
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Value: socketPath,
Usage: "tmux server socket path",
Destination: &socketPath,
},
},
},
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "target",
Aliases: []string{"t"},
Usage: "Target tmux session. Defaults to most recently used unattached session.",
Destination: &target,
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
server := tmux.NewServer(socketName, socketPath)
_, _, err := server.Attach(target)
if err != nil {
cli.Exit(fmt.Errorf("error while attaching to server with socket name '%s' and socket path '%s': %w", server.SocketName, server.SocketPath, err), 1)
}
return nil
},
}
}