diff --git a/go.mod b/go.mod index a072565..942d848 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ -module git.tordarus.net/tordarus/i3-wrapper +module git.milar.in/milarin/i3-wrapper -go 1.17 +go 1.18 + +require git.milar.in/milarin/slices v0.0.6 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5553408 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +git.milar.in/milarin/slices v0.0.6 h1:AQoSarZ58WHYol9c6woWJSe8wFpPC2RC4cvIlZpfg9s= +git.milar.in/milarin/slices v0.0.6/go.mod h1:NOr53AOeur/qscu/FBj3lsFR262PNYBccLYSTCAXRk4= diff --git a/main.go b/main.go index ffdffb3..ff058ca 100644 --- a/main.go +++ b/main.go @@ -3,13 +3,14 @@ package main import ( "flag" "fmt" - "io/ioutil" "os" "os/exec" "os/signal" "path/filepath" "strings" "syscall" + + "git.milar.in/milarin/slices" ) var ( @@ -49,8 +50,8 @@ func main() { cmd.Stderr = os.Stderr cmd.Env = os.Environ() - if envData, err := ioutil.ReadFile(os.ExpandEnv(*envFile)); err == nil { - cmd.Env = append(cmd.Env, strings.Split(string(envData), "\n")...) + if envData, err := os.ReadFile(os.ExpandEnv(*envFile)); err == nil { + cmd.Env = append(cmd.Env, slices.Filter(strings.Split(string(envData), "\n"), IsNotEmpty)...) } else { fmt.Println(err) } @@ -71,3 +72,7 @@ func main() { } } } + +func IsNotEmpty(str string) bool { + return len(strings.TrimSpace(str)) > 0 +}