Skip to content

[BUG]: Unable to open Editor in ps #15

@krishna4040

Description

@krishna4040

It is unable to open the editor of choice as set in the EDITOR env var in Windows on Powershell while it runs fine in bash, attached is a reproducible error

Image

possible workaround:

use std::env;
use std::path::PathBuf;
use std::process::Command;

fn open_in_editor(file_path: PathBuf) {
    if let Some(editor) = env::var("EDITOR").ok() {
        // Check if running on Windows
        if cfg!(target_os = "windows") {
            // Use PowerShell on Windows
            Command::new("powershell")
                .arg("-Command")
                .arg(format!(r#"{} "{}""#, editor, file_path.display()))
                .spawn()
                .unwrap()
                .wait()
                .unwrap();
        } else {
            // Use "sh" for Unix-like systems
            Command::new("sh")
                .arg("-c")
                .arg(format!(r#"{} "{}""#, editor, file_path.display()))
                .spawn()
                .unwrap()
                .wait()
                .unwrap();
        }
    } else {
        eprintln!("Error: EDITOR environment variable not set.");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions