-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (49 loc) · 891 Bytes
/
main.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
50
51
52
53
54
55
56
57
58
59
60
/*
Utility to execute Put via keyboard bindings
Usage of save:
Execute save from the shell
*/
package main
import (
"fmt"
"os"
"path"
"strings"
"github.com/dnjp/nyne"
)
func isterm(w *nyne.Win) bool {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
_, file := path.Split(w.File)
file = strings.TrimPrefix(file, "-")
return strings.Contains(hostname, file)
}
func main() {
os.Unsetenv("winid") // do not trust the execution environment
winid, err := nyne.FocusedWinID(nyne.FocusedWinAddr())
if err != nil {
panic(err)
}
wins, err := nyne.Windows()
if err != nil {
panic(err)
}
w, ok := wins[winid]
if !ok {
panic(fmt.Errorf("could not find window with id %d", winid))
}
// ignore terminal window
if isterm(w) {
return
}
_, _, err = w.CurrentAddr()
if err != nil {
panic(err)
}
err = w.Put()
if err != nil {
panic(err)
}
}