2021-09-28 20:42:31 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-09-28 21:05:45 +02:00
|
|
|
"flag"
|
2021-09-28 20:42:31 +02:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-09-28 21:05:45 +02:00
|
|
|
var (
|
|
|
|
envFile = flag.String("env", "$HOME/.config/i3-wrapper/environment", "environment file with variable definitions")
|
|
|
|
)
|
|
|
|
|
2021-09-28 20:42:31 +02:00
|
|
|
func main() {
|
2021-09-28 21:05:45 +02:00
|
|
|
logFile, err := os.Create(filepath.Join(os.Getenv("HOME"), ".i3.log"))
|
2021-09-28 20:42:31 +02:00
|
|
|
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()
|
2021-09-28 21:05:45 +02:00
|
|
|
if envData, err := ioutil.ReadFile(os.ExpandEnv(*envFile)); err == nil {
|
2021-09-28 20:42:31 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|