-
Notifications
You must be signed in to change notification settings - Fork 9
/
utils.go
49 lines (42 loc) · 843 Bytes
/
utils.go
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
package main
import (
"encoding/base64"
"fmt"
"os"
"os/exec"
"runtime"
"strings"
)
func IndexOf(candidate string, arr []string) int {
for index, element := range arr {
if element == candidate {
return index
}
}
return -1
}
func SetTermTitle(name string) {
fmt.Printf("\033]0;gtt - %s\007", name)
}
func CopyToClipboard(text string) {
if uiStyle.OSC52 {
fmt.Printf("\033]52;c;%s\a", base64.StdEncoding.EncodeToString([]byte(text)))
return
}
var cmd *exec.Cmd
switch runtime.GOOS {
case "linux":
switch os.Getenv("XDG_SESSION_TYPE") {
case "x11":
cmd = exec.Command("xclip", "-selection", "clipboard")
case "wayland":
cmd = exec.Command("wl-copy")
}
case "darwin":
cmd = exec.Command("pbcopy")
case "windows":
cmd = exec.Command("clip")
}
cmd.Stdin = strings.NewReader(text)
cmd.Start()
}