browserCommand

tcmts.atproto.browserCommand · #idaihqqq · term · runs anywhere

How to open a URL in a browser: $BROWSER if it's set (the URL its last argument), else the platform's.

export function browserCommand(
  url: string,
  platform: string,
  browser: string | undefined,
): [string, string[]] {
  return browser
    ? ["sh", ["-c", `${browser} "$0"`, url]]
    : platform === "darwin"
      ? ["open", [url]]
      : platform === "win32"
        ? // (cmd reads & ^ | < > as its own: escaped, so the whole URL is opened)
          ["cmd", ["/c", "start", "", url.replace(/[&^|<>]/g, "^$&")]]
        : ["xdg-open", [url]];
}

used by