change command execution logic and use env command
This commit is contained in:
57
tools.go
57
tools.go
@@ -557,55 +557,22 @@ func launch(command string, terminal bool) {
|
|||||||
themeToPrepend = th.(string)
|
themeToPrepend = th.(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// trim % and everything afterwards
|
|
||||||
if strings.Contains(command, "%") {
|
|
||||||
cutAt := strings.Index(command, "%")
|
|
||||||
if cutAt != -1 {
|
|
||||||
command = command[:cutAt-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elements := strings.Split(command, " ")
|
|
||||||
|
|
||||||
envVarsNum := 0
|
|
||||||
if strings.Contains(elements[0], "=") {
|
|
||||||
for _, element := range elements {
|
|
||||||
if strings.Contains(element, "=") {
|
|
||||||
envVarsNum++
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// find prepended env variables, if any
|
|
||||||
var envVars []string
|
|
||||||
|
|
||||||
if themeToPrepend != "" {
|
if themeToPrepend != "" {
|
||||||
envVars = append(envVars, fmt.Sprintf("GTK_THEME=%s", themeToPrepend))
|
command = fmt.Sprintf("GTK_THEME=%q %s", themeToPrepend, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdIdx := envVarsNum
|
var elements = []string{"/usr/bin/env", "-S", command}
|
||||||
firstArgIdx := envVarsNum + 1
|
|
||||||
|
|
||||||
if envVarsNum > 0 {
|
cmd := exec.Command(elements[0], elements[1:]...)
|
||||||
for idx, item := range elements {
|
|
||||||
if envVarsNum > idx && strings.Contains(item, "=") {
|
|
||||||
envVars = append(envVars, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(elements[cmdIdx], elements[firstArgIdx:]...)
|
|
||||||
|
|
||||||
var prefixCommand string
|
|
||||||
var args []string
|
|
||||||
if terminal {
|
if terminal {
|
||||||
prefixCommand = *term
|
var prefixCommand = *term
|
||||||
if *term != "foot" {
|
var args []string
|
||||||
args = []string{"-e", strings.Join(elements, " ")}
|
if prefixCommand != "foot" {
|
||||||
|
args = []string{"-e", command}
|
||||||
} else {
|
} else {
|
||||||
args = elements[cmdIdx:]
|
args = elements
|
||||||
}
|
}
|
||||||
cmd = exec.Command(prefixCommand, args...)
|
cmd = exec.Command(prefixCommand, args...)
|
||||||
} else if *wm == "sway" {
|
} else if *wm == "sway" {
|
||||||
@@ -614,13 +581,7 @@ func launch(command string, terminal bool) {
|
|||||||
cmd = exec.Command("hyprctl", "dispatch", "exec", strings.Join(elements, " "))
|
cmd = exec.Command("hyprctl", "dispatch", "exec", strings.Join(elements, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
// set env variables
|
msg := fmt.Sprintf("command: %q; args: %q\n", cmd.Args[0], cmd.Args[1:])
|
||||||
if len(envVars) > 0 {
|
|
||||||
cmd.Env = os.Environ()
|
|
||||||
cmd.Env = append(cmd.Env, envVars...)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := fmt.Sprintf("env vars: %s; command: '%s'; args: %s\n", envVars, cmd.Args[0], cmd.Args[1:])
|
|
||||||
log.Info(msg)
|
log.Info(msg)
|
||||||
|
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
|
|||||||
Reference in New Issue
Block a user