#include #include #include #include #include #include #include #include #define clear() printf("\033[H\033[J") void init_shell() { clear(); printf("\n\n\n\n******************************************"); printf("\n\n\n\t****MY SHELL****"); printf("\n\n\t-USE AT YOUR OWN RISK-"); printf("\n\n\n******************************************"); char *username = getenv("USER"); printf("\n\nUSER is: @%s\n", username); sleep(1); clear(); } int take_input(char *str) { char *buf; buf = readline("\n>>> "); if (strlen(buf) != 0) { add_history(buf); strcpy(str, buf); return 0; } else { return 1; } } void print_dir() { char cwd[1024]; getcwd(cwd, sizeof(cwd)); printf("\nDir: %s", cwd); } void execute_args(char **parsed) { pid_t pid = fork(); if (pid == -1) { printf("\nFailed forking child.."); return; } else if (pid == 0) { if (execvp(parsed[0], parsed) < 0) { printf("\nCould not execute command.."); } exit(0); } else { wait(NULL); return; } } void open_help() { puts("\n***Welcome to my shell help" "\n-Use the shell at your own risk..." "\nList of commands support:" "\n>cd" "\n>ls" "\n>exit" "\n>all other general commands available in UNIX shell"); } int own_cmd_handler(char** parsed) { } int main() { init_shell(); }