Start shell

This commit is contained in:
Night Kaly 2024-11-17 15:17:41 +00:00
parent 472e3d2707
commit 46d495e610
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM

28
ccc.c
View file

@ -68,6 +68,7 @@ void goto_dir(void);
void create_dir(void);
void create_file(void);
void delete_files(void);
void start_shell(void);
void wpprintw(const char *fmt, ...);
void move_cursor(int row, int col);
int read_key(void);
@ -372,6 +373,7 @@ int main(int argc, char **argv)
break;
case '!':
start_shell();
break;
/* mark one file */
@ -1217,6 +1219,32 @@ void delete_files(void)
}
}
void start_shell(void)
{
bprintf("\033[2J\033[?25h");
move_cursor(1, 1);
char shell[PATH_MAX];
strcpy(shell, getenv("SHELL"));
if (strlen(shell) == 0) {
strcpy(shell, "sh");
} else {
pid_t pid = fork();
if (pid == 0) {
/* Child process */
execlp(shell, shell, NULL);
_exit(1); /* Exit if exec fails */
} else if (pid > 0) {
/* Parent process */
waitpid(pid, NULL, 0);
list_files();
bprintf("\033[?25l");
} else {
/* Fork failed */
wpprintw("fork failed: %s", strerror(errno));
}
}
}
/*
* Print line to the panel
*/