Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning (disable : 4996)
- #include <iostream>
- #include <direct.h>
- #include <fstream>
- #include <stdio.h>
- #include <string>
- #include <io.h>
- #include <map>
- #define clear cout << "\033[H\033[J"
- using namespace std;
- const string CurrentDateAndTime() {
- time_t now = time(0);
- struct tm tstruct;
- char buf[128];
- tstruct = *localtime(&now);
- strftime(buf, sizeof(buf), "%d/%m/%Y, %X", &tstruct);
- return buf;
- }
- void help() {
- cout << "Enhanced Z shell, build 0 from November, 2021.\n"
- << "Available commands:\n"
- << "help - shows this message\n"
- << "ls - list contents of current or specified directory\n"
- << "cd - changes current directory\n"
- << "exit - exit the shell\n"
- << "clear - erases all contents of the screen\n";
- }
- void add_history(string cmd) {
- fstream history;
- history.open("history.zsh", ios::in | ios::out | ios::app);
- history << cmd;
- }
- int main() {
- ios::sync_with_stdio(false);
- cout.tie(0);
- cin.tie(0);
- register string cmd;
- register string prompt = ": ";
- register char cwd[1024];
- register char path[1024];
- getcwd(cwd, sizeof(cwd));
- register char* username = getenv("USERNAME");
- map<string, int> cmds = {
- {"help", 1},
- {"ls", 2},
- {"cd", 3},
- {"exit", 4},
- {"clear", 5},
- {"echo", 6}
- };
- cout << "Welcome to the Enhanced Z shell, " << username << ".\n";
- cout << CurrentDateAndTime() << "\n";
- while (1) {
- cout << cwd << prompt;
- cin >> cmd;
- add_history(cmd);
- switch (cmds[cmd]) {
- case 1:
- help();
- break;
- case 2:
- system("dir");
- break;
- case 3:
- cin >> path;
- chdir(path);
- break;
- case 4:
- exit(0);
- break;
- case 5:
- clear;
- break;
- case 6:
- break;
- }
- }
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement