Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] neovide process disown from terminal? #402

Closed
mitnk opened this issue Dec 8, 2020 · 9 comments
Closed

[macOS] neovide process disown from terminal? #402

mitnk opened this issue Dec 8, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@mitnk
Copy link

mitnk commented Dec 8, 2020

I'm new to neovide. When I build neovide with cargo build --release, and running it (ie. ./target/release/neovide) from the shell (terminal), it does not disown with the terminal. The neovide spawned the window, but the command in shell does not return until neovide terminate. Meaning closing the terminal window (or Ctrl-C) also closes the neovide window.

For now I have to define a shell function like this:

function nvim() {
    nohup neovide $@ > /dev/null &
}

So that when I type nvim foo.txt and closing the terminal tab does not closing the window of enovide too.

Maybe we need a script like mvim in MacVim?

@tarunzoot
Copy link

tarunzoot commented Dec 16, 2020

a quick way to do that is to put the following code in src -> main.rs after #[cfg(target_os = "macos")] {, and creating an alias alias nvim="neovide --disown"

#[cfg(not(debug_assertions))]
        if std::env::args().find(|f| f == "--disown").is_some() {
            if let Ok(curr_exe) = std::env::current_exe() {
                assert!(std::process::Command::new(curr_exe)
                    .args(std::env::args().skip(1).filter(|f| f != "--disown"))
                    .spawn()
                    .is_ok());
                std::process::exit(0);
            }
            else {
                eprintln!("error in disowning process, cannot obtain the path for the current executable, continuing without disowning...");
            }
        }

and then build with cargo build --release && strip ./target/release/neovide

@j4qfrost
Copy link
Collaborator

This looks good to me. Feel free to make a pull request. I have been a bit tied up recently, but I can merge the changes this weekend.

@mitnk
Copy link
Author

mitnk commented Dec 17, 2020

Consider to make this --disown option default? Since neovide is an GUI app, not depends on the shell/terminal, right?

@Kethku
Copy link
Member

Kethku commented Dec 17, 2020

Yeah I agree. On mac machines we should just do this by default. On windows this is the normal behavior. Not sure about linux

@Kethku Kethku added the enhancement New feature or request label Dec 17, 2020
@tarunzoot
Copy link

tarunzoot commented Dec 17, 2020

okay, so to do that the modified code is
file -> main.rs

#[cfg(not(debug_assertions))]
        if std::env::args().find(|f| f == "--disowned").is_none() {
            if let Ok(curr_exe) = std::env::current_exe() {
                assert!(std::process::Command::new(curr_exe)
                    .args(std::env::args().skip(1))
                    .arg("--disowned")
                    .spawn()
                    .is_ok());
                std::process::exit(0);
            } else {
                eprintln!("error in disowning process, cannot obtain the path for the current executable, continuing without disowning...");
            }
        }

file -> src -> settings -> mod.rs, in the impl Settings block on line 66 replace fn new block with

fn new() -> Self {
        let mut log_to_file = false;
        let neovim_arguments = std::env::args()
            .filter(|arg| {
                if arg == "--log" {
                    log_to_file = true;
                    false
                } else if arg == "--version" || arg == "-v" {
                    println!("Neovide version: {}", env!("CARGO_PKG_VERSION"));
                    std::process::exit(0);
                } else if arg == "--help" || arg == "-h" {
                    println!("neovide : {}", env!("CARGO_PKG_DESCRIPTION"));
                    std::process::exit(0);
                } else if arg == "--disowned" {
                    false
                } else {
                    !(arg.starts_with("--geometry=") || arg == "--wsl")
                }
            })
            .collect::<Vec<String>>();

        #[cfg(not(test))]
        Settings::init_logger(log_to_file);

        Self {
            neovim_arguments,
            settings: RwLock::new(HashMap::new()),
            listeners: RwLock::new(HashMap::new()),
            readers: RwLock::new(HashMap::new()),
        }
    }

@Kethku
Copy link
Member

Kethku commented Dec 18, 2020

@tarunzoot looks not bad from a cursory glance. Could you make a PR?

Kethku pushed a commit that referenced this issue Dec 21, 2020
* macos neovide disown from terminal #402

* macos neovide disown from terminal #402, used any instead of find

Co-authored-by: Tarun Sharma <maverick@maverick.local>
@j4qfrost
Copy link
Collaborator

@Kethku @tarunzoot looks like this was merged #411. Is it done?

@Kethku
Copy link
Member

Kethku commented Dec 26, 2020

Correct

@mitnk
Copy link
Author

mitnk commented Dec 28, 2020

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants