From 43b6a2d254cd823bf02a12bb8086bece16ec965b Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Wed, 28 May 2025 16:51:40 -0500 Subject: [PATCH 1/2] Add Codespaces setup. --- .devcontainer/devcontainer.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..a48a43b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/rust +{ + "name": "Rust", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye", + // Configure tool-specific properties. + "customizations": { + "codespaces": { + "openFiles": [ + "README.md" + ] + }, + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer" + ] + } + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file From 63c82ee2c7afbb30972626022b86eb7f10fe582f Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Wed, 28 May 2025 16:37:33 -0500 Subject: [PATCH 2/2] feat: on Linux, use $BROWSER per #108. --- src/lib.rs | 4 +--- src/unix.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 533e33b..ab4a5a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,9 +77,7 @@ //! // On a console, without a window manager, results will likely be poor. The openers expect to be able to open in a new or existing window, something that consoles lack. //! -//! On Windows WSL, `wslview` is tried first, then `xdg-open`. In other UNIX environments, `xdg-open` is tried first. If this fails, a sequence of other openers is tried. -//! -//! Currently the `BROWSER` environment variable is ignored even for `http:` and `https:` URLs unless the opener being used happens to respect it. +//! First, `$BROWSER` is tried (if defined). On Windows WSL, `wslview` is tried next, then `xdg-open`. In other UNIX environments, `xdg-open` is tried next. If this fails, a sequence of other openers is tried. //! //! It cannot be overemphasized how fragile this all is in UNIX environments. It is common for the various MIME tables to incorrectly specify the application "owning" a given filetype. //! It is common for openers to behave strangely. Use with caution, as this crate merely inherits a particular platforms shortcomings. diff --git a/src/unix.rs b/src/unix.rs index 0e1fdb7..4f47bfb 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -7,18 +7,23 @@ use std::{ pub fn commands>(path: T) -> Vec { let path = path.as_ref(); - let mut commands: Vec<(&str, Vec<&OsStr>)> = vec![]; + let mut commands: Vec<(String, Vec<&OsStr>)> = vec![]; + + // Make the `$BROWSER` environment variable (if it's defined) the highest priority. + if let Ok(browser) = env::var("BROWSER") { + commands.push((browser, vec![path])); + } let wsl_path = wsl_path(path); if is_wsl::is_wsl() { - commands.push(("wslview", vec![&wsl_path])); + commands.push(("wslview".to_string(), vec![&wsl_path])); } commands.extend_from_slice(&[ - ("xdg-open", vec![&path]), - ("gio", vec![OsStr::new("open"), path]), - ("gnome-open", vec![path]), - ("kde-open", vec![path]), + ("xdg-open".to_string(), vec![&path]), + ("gio".to_string(), vec![OsStr::new("open"), path]), + ("gnome-open".to_string(), vec![path]), + ("kde-open".to_string(), vec![path]), ]); commands