open_file

Function open_file 

Source
pub fn open_file(path: &Path)
Expand description

What: Open a file in the default editor (cross-platform).

Inputs:

  • path: Path to the file to open.

Output:

  • No return value; spawns a background process to open the file.

Details:

  • On Windows, uses PowerShell’s Invoke-Item to open files with the default application, with fallback to cmd start.
  • On Unix-like systems (Linux/macOS), uses xdg-open (Linux) or open (macOS).
  • Spawns the command in a background thread and ignores errors.

§Examples

use pacsea::util::open_file;
use std::path::Path;

// Opening a downloaded package's PKGBUILD for inspection
let pkgbuild_path = Path::new("/tmp/linux-zen/PKGBUILD");
open_file(pkgbuild_path); // Launches the default text editor

// Opening the local Pacsea configuration file for editing
let config_path = Path::new("/home/alice/.config/pacsea/settings.conf");
open_file(config_path); // Opens in the configured editor

// Note: This function runs asynchronously and does not block.
// It's safe to call even if the file doesn't exist (the OS will show an error).