v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-15 23:30:27 -07:00
GTT/utils.go

46 lines
861 B
Go

package main
import (
"fmt"
"os"
"os/exec"
"runtime"
)
func IndexOf(candidate string, arr []string) int {
for index, element := range arr {
if element == candidate {
return index
}
}
return -1
}
func SetTermTitle(title string) {
print("\033]0;", title, "\007")
}
func CopyToClipboard(text string) {
switch runtime.GOOS {
case "linux":
switch os.Getenv("XDG_SESSION_TYPE") {
case "x11":
exec.Command("sh", "-c",
fmt.Sprintf("echo -n '%s' | xclip -selection clipboard", text)).
Start()
case "wayland":
exec.Command("sh", "-c",
fmt.Sprintf("echo -n '%s' | wl-copy", text)).
Start()
}
case "darwin":
exec.Command("sh", "-c",
fmt.Sprintf("echo -n '%s' | pbcopy", text)).
Start()
case "windows":
exec.Command("cmd", "/c",
fmt.Sprintf("echo %s | clip", text)).
Start()
}
}