Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the swaymsg flag to launch a program with swaymsg exec and prevent potential involuntary closing with Jetbrains IDEs #101

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func defaultStringIfBlank(s, fallback string) string {
return s
}

func defaultBoolIfBlank(s string, fallback bool) bool {
s = strings.TrimSpace(s)
// os.Getenv("TERM") returns "linux" instead of empty string, if program has been started
// from a key binding defined in the config file. See #23.
if s != "sway" {
return fallback
}
return true
}

// Flags
var cssFileName = flag.String("s", "drawer.css", "Styling: css file name")
var targetOutput = flag.String("o", "", "name of the Output to display the drawer on (sway only)")
Expand All @@ -134,6 +144,7 @@ var itemSpacing = flag.Uint("spacing", 20, "icon spacing")
var lang = flag.String("lang", "", "force lang, e.g. \"en\", \"pl\"")
var fileManager = flag.String("fm", "thunar", "File Manager")
var term = flag.String("term", defaultStringIfBlank(os.Getenv("TERM"), "foot"), "Terminal emulator")
var swaymsg = flag.Bool("swaymsg", defaultBoolIfBlank(os.Getenv("XDG_CURRENT_DESKTOP"), false), "Use swaymsg (sway only)")
var nameLimit = flag.Int("fslen", 80, "File Search name LENgth Limit")
var noCats = flag.Bool("nocats", false, "Disable filtering by category")
var noFS = flag.Bool("nofs", false, "Disable file search")
Expand Down
11 changes: 8 additions & 3 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,20 @@ func launch(command string, terminal bool) {

cmd := exec.Command(elements[cmdIdx], elements[1+cmdIdx:]...)

var prefixCommand string
var args []string
if terminal {
var args []string
prefixCommand = *term
if *term != "foot" {
args = []string{"-e", elements[cmdIdx]}
} else {
args = []string{elements[cmdIdx]}
}

cmd = exec.Command(*term, args...)
cmd = exec.Command(prefixCommand, args...)
} else if *swaymsg {
prefixCommand = "swaymsg"
args = []string{"exec", elements[cmdIdx]}
cmd = exec.Command(prefixCommand, args...)
}

// set env variables
Expand Down