summaryrefslogtreecommitdiff
path: root/.config/wmii-hg
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-01-10 19:38:58 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2018-01-10 19:38:58 -0500
commita2cd9d788f7b39e9f17d1fa2dc1382bd2f98e2c1 (patch)
treef2f5c900f0c9aded26d3d9ca0c25e9a6029a7a9e /.config/wmii-hg
parent75a63c7e7b3b055198884f31c0d7c516eaf9d32e (diff)
parent971e265cac74976670da2a87805b644e90826b95 (diff)
Merge branch 'master' into build64-par/master
Diffstat (limited to '.config/wmii-hg')
-rw-r--r--.config/wmii-hg/.gitignore1
-rw-r--r--.config/wmii-hg/Makefile10
-rwxr-xr-x.config/wmii-hg/rbar_clock16
-rw-r--r--.config/wmii-hg/rbar_clock.go29
-rw-r--r--.config/wmii-hg/rbar_util/main.go76
-rw-r--r--.config/wmii-hg/rbar_util/util.go49
-rwxr-xr-x.config/wmii-hg/wmiirc2
7 files changed, 166 insertions, 17 deletions
diff --git a/.config/wmii-hg/.gitignore b/.config/wmii-hg/.gitignore
new file mode 100644
index 0000000..455b2ee
--- /dev/null
+++ b/.config/wmii-hg/.gitignore
@@ -0,0 +1 @@
+/rbar_clock \ No newline at end of file
diff --git a/.config/wmii-hg/Makefile b/.config/wmii-hg/Makefile
new file mode 100644
index 0000000..4ba64a3
--- /dev/null
+++ b/.config/wmii-hg/Makefile
@@ -0,0 +1,10 @@
+all: rbar_clock
+.PHONY: all
+
+%: %.go
+ go build -o $@ $<
+
+rbar_clock: rbar_util $(wildcard rbar_util/*)
+
+.SECONDARY:
+.DELETE_ON_ERROR:
diff --git a/.config/wmii-hg/rbar_clock b/.config/wmii-hg/rbar_clock
deleted file mode 100755
index c66b21e..0000000
--- a/.config/wmii-hg/rbar_clock
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env bash
-
-update() {
- id=$1
- setup_trap "$id"
-
- while true; do
- {
- printf 'label '
- date +'%a %F %T %Z(%:::z)'
- } | write "$id"
- sleep .5
- done
-}
-
-. "$(dirname "$0")/rbar.sh"
diff --git a/.config/wmii-hg/rbar_clock.go b/.config/wmii-hg/rbar_clock.go
new file mode 100644
index 0000000..247dd3a
--- /dev/null
+++ b/.config/wmii-hg/rbar_clock.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "time"
+
+ "./rbar_util"
+)
+
+func main() {
+ rbar_util.Main(rbar_util.Impl{
+ Update: func(id string) error {
+ defer rbar_util.Remove(rbar_util.GlobEscape(id))
+
+ now := time.Now()
+ start := now.Truncate(time.Second).Add(time.Second)
+ time.Sleep(start.Sub(now))
+
+ clock := time.NewTicker(1*time.Second)
+ defer clock.Stop()
+ for now := range clock.C {
+ err := rbar_util.Write(id, now.Format("label Mon 2006-01-02 15:04:05 MST(-07)"))
+ if err != nil {
+ return err
+ }
+ }
+ panic("not reached")
+ },
+ })
+}
diff --git a/.config/wmii-hg/rbar_util/main.go b/.config/wmii-hg/rbar_util/main.go
new file mode 100644
index 0000000..5fccd7e
--- /dev/null
+++ b/.config/wmii-hg/rbar_util/main.go
@@ -0,0 +1,76 @@
+package rbar_util
+
+import (
+ "os"
+ "io"
+ "fmt"
+)
+
+
+type Impl struct {
+ LeftClick func() error
+ MiddleClick func() error
+ RightClick func() error
+ ScrollUp func() error
+ ScrollDown func() error
+ Update func(tag string) error
+}
+
+func gerror(status int, err error, format string, a ...interface{}) {
+ msg := fmt.Sprintf(format, a...)
+ if err == nil {
+ fmt.Fprintf(os.Stderr, "%s: %s", os.Args[0], msg)
+ } else {
+ fmt.Fprintf(os.Stderr, "%s: %s: %v", os.Args[0], msg, err)
+ }
+ if status != 0 {
+ os.Exit(status)
+ }
+}
+
+func errusage(fmt string, a ...interface{}) {
+ gerror(0, nil, fmt, a...)
+ usage(os.Stderr)
+ os.Exit(2)
+}
+
+func usage(w io.Writer) {
+ fmt.Fprintf(w, "Usage: %[1]v NN_LABEL\n or: %[1]v BTN_ID\n or: %[1]v -h\n", os.Args[0])
+}
+
+func Main(impl Impl) {
+ if len(os.Args) != 2 {
+ errusage("exactly 1 argument expected, got %d", len(os.Args)-1)
+ }
+ var fn func() error
+ switch os.Args[1] {
+ case "-h":
+ usage(os.Stdout)
+ os.Exit(0)
+ case "1": fn = impl.LeftClick;
+ case "2": fn = impl.MiddleClick;
+ case "3": fn = impl.RightClick;
+ case "4": fn = impl.ScrollUp;
+ case "5": fn = impl.ScrollDown;
+ default:
+ arg := os.Args[1]
+ if len(arg) > 3 && '0' <= arg[0] && arg[0] <= '9' && '0' <= arg[1] && arg[1] <= '9' && arg[2] == '_' {
+ if impl.Update != nil {
+ fn = func() error { return impl.Update(arg) }
+ }
+ } else {
+ errusage("invalid argument: %s\n", os.Args[1])
+ }
+ }
+ if fn == nil {
+ fn = func() error { return nil }
+ }
+ if os.Getenv("XDG_RUNTIME_DIR") == "" {
+ gerror(6, nil, "XDG_RUNTIME_DIR isn't set")
+ }
+ err := fn()
+ if err != nil && err != NoRbar{
+ gerror(1, err, "")
+ }
+ os.Exit(0)
+}
diff --git a/.config/wmii-hg/rbar_util/util.go b/.config/wmii-hg/rbar_util/util.go
new file mode 100644
index 0000000..9e5d622
--- /dev/null
+++ b/.config/wmii-hg/rbar_util/util.go
@@ -0,0 +1,49 @@
+package rbar_util
+
+import (
+ "os"
+ "io"
+ "path/filepath"
+ "strings"
+ "errors"
+
+ "fmt"
+)
+
+func GlobEscape(lit string) string {
+ glob := lit
+ glob = strings.Replace(glob, "\\", "\\\\", -1)
+ glob = strings.Replace(glob, "*", "\\*", -1)
+ glob = strings.Replace(glob, "?", "\\?", -1)
+ glob = strings.Replace(glob, "[", "\\[", -1)
+ return glob
+}
+
+var NoRbar = errors.New("no WMII rbars found")
+
+func Write(filename string, msg string) error {
+ dirnames, _ := filepath.Glob(GlobEscape(os.Getenv("XDG_RUNTIME_DIR"))+"/wmii*/rbar")
+ if len(dirnames) == 0 {
+ return NoRbar
+ }
+ for _, dirname := range dirnames {
+ file, err := os.OpenFile(filepath.Join(dirname, filename), os.O_WRONLY| os.O_APPEND|os.O_CREATE, 0666)
+ if err != nil {
+ continue
+ }
+ io.WriteString(file, msg)
+ file.Close()
+ }
+ return nil
+}
+
+func Remove(glob string) {
+ fmt.Println("remove", glob);
+ fullglob := GlobEscape(os.Getenv("XDG_RUNTIME_DIR"))+"/wmii*/rbar/"+glob
+ fmt.Println("glob", fullglob)
+ filenames, err := filepath.Glob(fullglob)
+ fmt.Println("globerr", err)
+ for _, filename := range filenames {
+ os.Remove(filename)
+ }
+}
diff --git a/.config/wmii-hg/wmiirc b/.config/wmii-hg/wmiirc
index c6e05bf..f96642b 100755
--- a/.config/wmii-hg/wmiirc
+++ b/.config/wmii-hg/wmiirc
@@ -15,5 +15,5 @@ systemd-notify --ready || true
trap "Event Quit" EXIT
while read -r event; do
- Event $event
+ Event $event <&-
done < <(wmiir read /event 2>/dev/null)