summaryrefslogtreecommitdiff
path: root/.config/wmii-hg/rbar_util/util.go
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/rbar_util/util.go
parent75a63c7e7b3b055198884f31c0d7c516eaf9d32e (diff)
parent971e265cac74976670da2a87805b644e90826b95 (diff)
Merge branch 'master' into build64-par/master
Diffstat (limited to '.config/wmii-hg/rbar_util/util.go')
-rw-r--r--.config/wmii-hg/rbar_util/util.go49
1 files changed, 49 insertions, 0 deletions
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)
+ }
+}