From f6c7004bdd062a7e99aa7f325ffcd182d35c370d Mon Sep 17 00:00:00 2001 From: bigsketti Date: Sun, 9 Feb 2025 16:56:34 -0500 Subject: [PATCH] added hacker mode and evil mode --- README.md | 21 ++++-- cshell | Bin 16904 -> 16920 bytes handleJSON.c | 18 +++-- main.c | 189 ++++++++++++++++++++++++++++++++------------------- 4 files changed, 150 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index f6cb23e..e6287d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ -This is a basic terminal written in plain ol' C. I'm writing this to dip my toes into C and learn a little about systems development. -This will never reach the level of bash or zsh, I'm a college student without that kind of time or knowledge. +# Welcome to cShell -THIS ONLY WORKS ON LINUX, IF FOR WHATEVER REASON YOU WANT TO PLAY WITH THIS AND YOURE ON WINDOWS YOU MUST USE WSL (Windows subsystem for Linux) +**cShell** is a compact terminal written in **C**. -No need to compile the source code to run, simply download the binary from the repository. It always contains the most recently compiled version of cShell. +This cutting-edge shell for Linux includes powerful features such as: + +- Native ASCII clam +- Easy navigation, creation, and deletion of files and directories +- **Hacker mode** +- **Evil mode** +- And so much more… + +--- + +**cShell** is actively being developed at a **very slow** pace. College and work take up a lot of time, and this project is just my way of dipping my toes into **C** and learning about shells and **syscalls**. + +While **cShell** is clearly **better** than other shells like **Bash** or **ZShell**, it's not quite as feature-rich. I wouldn’t recommend replacing your current shell program with it—unless, of course, you *really* hate yourself. In that case, I am not liable for any damage to your psyche incurred during the use of this program. + +--- \ No newline at end of file diff --git a/cshell b/cshell index 4c218715c9f36d7a0073557b320f06403e5b0bfb..9f7eeb1a0c82b651d0ae3ce840f7a1dab7b5c017 100755 GIT binary patch delta 2930 zcmZuzeN0nV6o2oP4(RwstVNUu0gB94Kwv5eRAfGMF__3^Hm6qlpq*`j+A@~KRE6p~ z)&+C-0h#mTAG4t@V&|g9G1NJ5nMShAF!zT#qXS`x+jML?-_E`70;TRH?|z)$@BGfW z=ic}6b_?6y!nS3y?R(~3SIvoF$T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7MDqdNN zBR@dvlSX<4XoisvFl!=spaLn695f4xaHHTnGRJW{1?Utbt>)|Jz=`X{eC_4-4Q_Wa zYkD8m^2s<7t9?+do1oUbsNjQFEeAmNLEKLAP=W*-GwX`~J?RbD{I9xO5m--u4M=wpM6fRfohojY2(|p{^e&8_;zq(MLU0u*x zZHr#6u9u`#7F5+ZH0g;QG(%g>Txm!R$7&qVh8ERN4wRT(\n" + "\tmkdir

\n" + "\trmdir \n" + "\tmkfile \n" + "\trmfile \n" + "\tls \n" + "\tmode <-arg>\n" + "\t\tnormal mode: -n\n" + "\t\tevil mode: -e\n" + "\t\thacker mode: -h\n\n" + ); + return; + } + + if (strcmp("version", args[0]) == 0) { + printf("cShell version: %f\n", VERSION); + return; + } + + if (strcmp("cd", args[0]) == 0) { + if (args[1] == NULL) { + fprintf(stderr, "Missing argument for command \"cd\"\n"); + } else { + if (chdir(args[1]) != 0) { + perror("chdir failed\n"); + } else { + free(*cwd); + *cwd = getCWD(); + *trimmedCWD = trimCWD(*cwd); + } + } + return; + } + + if (strcmp("mkfile", args[0]) == 0) { + FILE *file = fopen(args[1], "w"); + if (file == NULL) { + perror("Error making file"); + } else { + printf("success\n"); + } + return; + } + + if (strcmp("mkdir", args[0]) == 0) { + if (mkdir(args[1], 0777) != 0) { + perror("Error making directory"); + } else { + printf("success\n"); + } + return; + } + + if (strcmp("rmfile", args[0]) == 0) { + if (remove(args[1]) != 0) { + perror("Error removing file"); + } else { + printf("success\n"); + } + return; + } + + if (strcmp("rmdir", args[0]) == 0) { + if (rmdir(args[1]) != 0) { + perror("Error removing directory"); + } else { + printf("success\n"); + } + return; + } + + if (strcmp("ls", args[0]) == 0) { + const char *path = args[1] ? args[1] : "."; + listDirectorys(path); + return; + } + + if (strcmp("mode", args[0]) == 0) { + if (strcmp("-h", args[1]) == 0) { + printf("\033[32m"); + printf("Hacker mode activated\n"); + return; + } else if (strcmp("-e", args[1]) == 0) { + printf("\033[31m"); + printf("Evil mode activated\n"); + return; + } else if (strcmp("-n", args[1]) == 0) { + printf("\033[0m"); + printf("Normal mode activated\n"); + return; + } else { + printf("Invalid arguement, type \"help\" for help\n"); + return; + } + } + + // execute the external command + execute(args); +} + int main() { char input[INPUT_SIZE]; char *args[100]; @@ -120,75 +239,7 @@ int main() { parse_input(input, args); - // built in command checks - - // TODO: add commands to handle creating and deleting users - // also modify permissions for admin users and regular users - // This will have to come after i finish the JSON parser - - // TODO: refactor this to a switch case one day im bored - // these else ifs are getting ugly and its just gonna get worse - if (strcmp("exit", args[0]) == 0) { - exit(0); - - } else if (strcmp("help", args[0]) == 0) { - printf("Welcome to cShell, my shitty terminal written in C\n\n"); - printClamShell(); - printf("\nBuilt-in commands:\n\texit\n\thelp\n\tcd [dir name]\n\tversion\n\tmkdir [dir name]\n\trmdir [dir name]\n\tmkfile [file name]\n\trmfile [file name]\n\tls [path optional]\n\n"); - continue; - - } else if (strcmp("version", args[0]) == 0) { - printf("cShell version: %f\n", VERSION); - continue; - - } else if (strcmp("cd", args[0]) == 0) { - if (args[1] == NULL) { - fprintf(stderr, "Missing argument for command \"cd\"\n"); - } else { - if (chdir(args[1]) != 0) { - perror("chdir failed\n"); - } else { - free(cwd); - cwd = getCWD(); - trimmedCWD = trimCWD(cwd); - } - } - continue; - - } else if (strcmp("mkfile", args[0]) == 0) { - FILE *file = fopen(args[1], "w"); - if (file == NULL) { - perror("Error making file"); - } else { printf("success\n"); } - continue; - - } else if (strcmp("mkdir", args[0]) == 0) { - if (mkdir(args[1], 0777) != 0) { - perror("Error making directory"); - } else { printf("success\n"); } - continue; - - } else if (strcmp("rmfile", args[0]) == 0) { - if (remove(args[1]) != 0) { - perror("Error removing file"); - } else { printf("success\n"); } - continue; - - } else if (strcmp("rmdir", args[0]) == 0) { - if (rmdir(args[1]) != 0) { - perror("Error removing directory"); - } else { printf("success\n"); } - continue; - - } else if (strcmp("ls", args[0]) == 0) { - const char *path = args[1] ? args[1] : "."; - listDirectorys(path); - continue; - - } - - // execute the external command - execute(args); + handle_command(args, &cwd, &trimmedCWD); } free(cwd); return 0;