diff --git a/a.out b/a.out index 1402e55..0a2f402 100755 Binary files a/a.out and b/a.out differ diff --git a/startup.c b/startup.c index fa6f9c0..3fe1946 100644 --- a/startup.c +++ b/startup.c @@ -5,6 +5,7 @@ #include #include #include +#include // for waitpid #include // for PATH_MAX #include #include @@ -155,13 +156,25 @@ char* ncursesSelect(char **options, char *optionsType, size_t optionsNumber, int int openNvim(char *path, int debug) { - if (debug) {printf("\e[0;32m[DEBUG]\e[0m Opening with command:\nnvim +:NvimTreeOpen %s\n", path);} - execlp("nvim", + pid_t pid = fork(); // this forking allows the programs to return when nvim is closed + if (pid < 0) { + perror("\e[0;31mERROR: fork failed\e[0m\n"); + return 1; + } else if (pid == 0) { + // Child process: replace with nvim + if (debug) {printf("\e[0;32m[DEBUG]\e[0m Opening with command:\nnvim +:NvimTreeOpen %s\n", path);} + execlp("nvim", "nvim", // we can specify each argument for nvim by passing more args to execlp path, NULL); - perror("\e[0;31mERROR: execlp failed. Nvim might be not installed or not in path.\e[0m\n"); - return 1; + perror("\e[0;31mERROR: execlp failed. Nvim might be not installed or not in path.\e[0m\n"); + exit(1); + } else { + // Parent process: wait for child to finish + int status; + waitpid(pid, &status, 0); + } + return 0; }