diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | lib/pure/browsers.nim | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md index 52b202d8c..33be5da21 100644 --- a/changelog.md +++ b/changelog.md @@ -44,6 +44,7 @@ - introduced new procs in `tables.nim`: `OrderedTable.pop`, `CountTable.del`, `CountTable.pop`, `Table.pop` - To `strtabs.nim`, added `StringTable.clear` overload that reuses the existing mode. +- Added `browsers.osOpen` const alias for the operating system specific *"open"* command. - Added `sugar.outplace` for turning in-place algorithms like `sort` and `shuffle` into operations that work on a copy of the data and return the mutated copy. As the existing `sorted` does. diff --git a/lib/pure/browsers.nim b/lib/pure/browsers.nim index 3f2045c3b..ee302f950 100644 --- a/lib/pure/browsers.nim +++ b/lib/pure/browsers.nim @@ -19,6 +19,11 @@ when defined(windows): else: import os, osproc +const osOpenCmd* = + when defined(macos) or defined(windows): "open" else: "xdg-open" ## \ + ## Alias for the operating system specific *"open"* command, + ## ``"open"`` on MacOS and Windows, ``"xdg-open"`` on Linux, BSD, etc. + proc openDefaultBrowser*(url: string) = ## opens `url` with the user's default browser. This does not block. ## @@ -29,14 +34,14 @@ proc openDefaultBrowser*(url: string) = ## ## This proc doesn't raise an exception on error, beware. when defined(windows): - var o = newWideCString("open") + var o = newWideCString(osOpenCmd) var u = newWideCString(url) discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL) elif defined(macosx): - discard execShellCmd("open " & quoteShell(url)) + discard execShellCmd(osOpenCmd & " " & quoteShell(url)) else: var u = quoteShell(url) - if execShellCmd("xdg-open " & u) == 0: return + if execShellCmd(osOpenCmd & " " & u) == 0: return for b in getEnv("BROWSER").string.split(PathSep): try: # we use ``startProcess`` here because we don't want to block! |