-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
os: implement support for VOPEN_URI_CMD env override for os.open_uri
- Loading branch information
Showing
2 changed files
with
29 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
module os | ||
|
||
pub fn open_uri(uri string) ? { | ||
$if macos { | ||
result := execute('open "$uri"') | ||
if result.exit_code != 0 { | ||
return error('unable to open url: $result.output') | ||
} | ||
} $else $if freebsd || openbsd { | ||
result := execute('xdg-open "$uri"') | ||
if result.exit_code != 0 { | ||
return error('unable to open url: $result.output') | ||
} | ||
} $else $if linux { | ||
providers := ['xdg-open', 'x-www-browser', 'www-browser', 'wslview'] | ||
|
||
// There are multiple possible providers to open a browser on linux | ||
// One of them is xdg-open, another is x-www-browser, then there's www-browser, etc. | ||
// Look for one that exists and run it | ||
for provider in providers { | ||
if exists_in_system_path(provider) { | ||
result := execute('$provider "$uri"') | ||
if result.exit_code != 0 { | ||
return error('unable to open url: $result.output') | ||
mut vopen_uri_cmd := getenv('VOPEN_URI_CMD') | ||
if vopen_uri_cmd == '' { | ||
$if macos { | ||
vopen_uri_cmd = 'open' | ||
} $else $if freebsd || openbsd { | ||
vopen_uri_cmd = 'xdg-open' | ||
} $else $if linux { | ||
providers := ['xdg-open', 'x-www-browser', 'www-browser', 'wslview'] | ||
// There are multiple possible providers to open a browser on linux | ||
// One of them is xdg-open, another is x-www-browser, then there's www-browser, etc. | ||
// Look for one that exists and run it | ||
for provider in providers { | ||
if exists_in_system_path(provider) { | ||
vopen_uri_cmd = provider | ||
break | ||
} | ||
break | ||
} | ||
} | ||
} $else { | ||
} | ||
if vopen_uri_cmd == '' { | ||
return error('unsupported platform') | ||
} | ||
result := execute('$vopen_uri_cmd "$uri"') | ||
if result.exit_code != 0 { | ||
return error('unable to open url: $result.output') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters