Last active
March 29, 2019 03:56
-
-
Save Sam-Belliveau/b0d1dacc8fd86e1139bc17d3fa4898d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> // std::cout, std::cin, std::getline | |
| #include <string> // std::string | |
| #include <unistd.h> // std::chdir, get_current_dir_name() | |
| #include <cstdlib> // std::system | |
| int main(int argc, char** argv) { | |
| // Buffer and Return Value | |
| std::string command_str; | |
| int return_value = 0; | |
| // Crap Shell Header | |
| std::cout << "---= Crap Shell V1.0 =---\n\n"; | |
| while(true) { | |
| // Print Out Header | |
| if(return_value != 0) { std::cout << '(' << return_value << ") "; } | |
| std::cout << get_current_dir_name() << " - crsh> "; | |
| // Get Command | |
| std::getline(std::cin, command_str); | |
| // CD command | |
| if(command_str[0] == 'c' && command_str[1] == 'd' && command_str[2] == ' ') | |
| { chdir(&command_str.front() + 3); } | |
| // Run System Command | |
| else { return_value = std::system(command_str.c_str()); } | |
| std::cout << std::endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment