i3-wrapper/main.go
2021-09-28 20:42:31 +02:00

50 lines
843 B
Go

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
}
}
}