From 85df0594be312307ea33086583f590283f828c09 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 20 Dec 2020 17:15:11 +0100 Subject: Support multiple colon-separated commands in `BROWSER` After reading the `urlview` man page, I learned that it supports multiple commands in the `BROWSER` environment variable separated by colons. Read over the source to see what `urlview` does: https://github.com/sigpipe/urlview/blob/08767aa863cd27d1755ba0aff65b8cc1a0c1446a/urlview.c#L617-L630 It tries each command from left to right until one of them exits with a `0` exit code. Use the same logic here. --- browserenv_unix_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'browserenv_unix_test.go') diff --git a/browserenv_unix_test.go b/browserenv_unix_test.go index f79d31d..971454e 100644 --- a/browserenv_unix_test.go +++ b/browserenv_unix_test.go @@ -96,3 +96,23 @@ func TestOpenURLStderr(t *testing.T) { t.Errorf("got stdout value %q want %q", got, url) } } + +func TestOpenURLMultipleBrowserCommands(t *testing.T) { + // The `test -z URL` command must fail, causing `printf URL` to run. + err := os.Setenv("BROWSER", "test -z:printf") + if err != nil { + t.Fatal(err) + } + + var stdout strings.Builder + Stdout = &stdout + + url := "http://localhost:8000" + + OpenURL(url) + + got := stdout.String() + if got != url { + t.Errorf("got stdout value %q want %q", got, url) + } +} -- cgit v1.2.3