commit 303051fd46bea2e6f035419628479a8e5fbe8322 Author: Tordarus Date: Tue Sep 28 20:42:31 2021 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c1e4aa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +i3-wrapper* diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a072565 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.tordarus.net/tordarus/i3-wrapper + +go 1.17 diff --git a/main.go b/main.go new file mode 100644 index 0000000..2a1529e --- /dev/null +++ b/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func main() { + logFile, err := os.Create("/home/tordarus/.i3.log") + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + defer logFile.Close() + + os.Stdout = logFile + os.Stderr = logFile + + for { + cmd := exec.Command("i3") + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + cmd.Env = os.Environ() + if envData, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".config/i3wrapper/environment")); err == nil { + cmd.Env = append(cmd.Env, strings.Split(string(envData), "\n")...) + } else { + fmt.Println(err) + } + + err = cmd.Start() + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + + err = cmd.Wait() + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + + if _, ok := err.(*exec.ExitError); ok { + break + } + } +}