Skip to content

Instantly share code, notes, and snippets.

@mpnordland
Last active September 22, 2018 07:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpnordland/710ec6d08ea92218f56f7d4dc78b860c to your computer and use it in GitHub Desktop.
Save mpnordland/710ec6d08ea92218f56f7d4dc78b860c to your computer and use it in GitHub Desktop.
Tiny wrapper that launches a user specifed terminal
// I built this to allow me to launch terminal apps
// for mimetypes in the terminal emulator of my choosing
// Since Firefox uses Glib to lookup and run apps and Glib
// only looks for a hard coded list, I needed something to
// get me in that list. This is my solution.
// Usage:
// Make sure your path includes ~/bin
// early-ish in your login shell's profile
// Build with "go build term-launcher.go"
// then copy the binary to ~/bin and symlink it to color-xterm
// Set $TERMINAL to the terminal emulator you want to use
// make sure it supports starting a program with '-e'
// if not, modify this to support your terminal emulator
package main
import "syscall"
import "os"
import "os/exec"
import "strings"
func main() {
term, termSet := os.LookupEnv("TERMINAL")
if !termSet {
// reasonable default
term = "xterm"
}
binary, lookErr := exec.LookPath(term)
if lookErr != nil {
panic(lookErr)
}
argStart := 1
if os.Args[argStart] == "-e"{
argStart += 1
}
// This is where you'd alter the arguments to match what your
// terminal emulator expects
args := []string{term, "-e", strings.Join(os.Args[argStart:], " ")}
env := os.Environ()
execErr := syscall.Exec(binary, args, env)//&syscall.ProcAttr{Env: env})
if execErr != nil {
panic(execErr)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment