From 038c1cf119dad7fbdc165d7f31876d3fb130a613 Mon Sep 17 00:00:00 2001 From: cmcode Date: Thu, 8 Aug 2024 20:18:03 -0700 Subject: [PATCH] add 'launchSeparately' config option for async tasks; bump version to 0.0.4 --- Makefile | 2 +- main.go | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 39c497a..91bafe1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY=build BUILDDIR=build -VER=0.0.3 +VER=0.0.4 BIN=$(BUILDDIR)/frequencmd-v$(VER) UNAME=$(shell go env GOOS) ARCH=$(shell go env GOARCH) diff --git a/main.go b/main.go index fa10433..32c8a4c 100644 --- a/main.go +++ b/main.go @@ -109,13 +109,21 @@ func parseConfigCommands(conf Config) { c := conf.Commands[i] n := Command{ - Command: c.Command, - Env: c.Env, - Label: c.Label, + Command: c.Command, + Env: c.Env, + Label: c.Label, + ShellBashArgs: c.ShellBashArgs, + LaunchSeparately: c.LaunchSeparately, } if c.Shell != "" { - n.Args = []string{"-c", c.Shell} + if c.ShellBashArgs != "" { + n.Args = []string{} + n.Args = append(n.Args, strings.Split(c.ShellBashArgs, " ")...) + n.Args = append(n.Args, "-c", c.Shell) + } else { + n.Args = []string{"-c", c.Shell} + } } else { n.Args = strings.Split(c.Args, " ") } @@ -207,7 +215,12 @@ func runCommand(command *Command /* command string, args []string, env []string cmd.Stdout = info cmd.Stderr = errors // Run the command - err := cmd.Run() + var err error + if command.LaunchSeparately { + err = cmd.Start() + } else { + err = cmd.Run() + } if err != nil { runIndex.Store(jobId, false) errors.SetText(fmt.Sprintf("error running command: %v", err.Error())) @@ -235,14 +248,24 @@ type Command struct { Command string Args []string Env []string + // Arguments to always pass to the /bin/bash executable when using a shell. + // For example, normally commands are executed via /bin/bash -c "shell" + // but you may want to specify a login shell via /bin/bash -i -c "shell", + // in which case ShellBashArgs would be "-i". + ShellBashArgs string + // Instead of following the output, the program gets launched and + // frequencmd doesn't care about it. Useful for graphical apps. + LaunchSeparately bool } type ConfigCommand struct { - Label string `yaml:"label"` - Command string `yaml:"command"` - Shell string `yaml:"shell"` - Args string `yaml:"args"` - Env []string `yaml:"env"` + Label string `yaml:"label"` + Command string `yaml:"command"` + Shell string `yaml:"shell"` + Args string `yaml:"args"` + Env []string `yaml:"env"` + ShellBashArgs string `yaml:"shellBashArgs"` + LaunchSeparately bool `yaml:"launchSeparately"` } func getFilteredList(l *tview.List, commands []Command, filterString string) {