From 46d495e61013bf990bd4fe7047eae48d5df31dc5 Mon Sep 17 00:00:00 2001 From: night0721 Date: Sun, 17 Nov 2024 15:17:41 +0000 Subject: [PATCH] Start shell --- ccc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ccc.c b/ccc.c index 187398a..7aa1a81 100644 --- a/ccc.c +++ b/ccc.c @@ -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 */