shell/src/main.cpp

48 lines
1.2 KiB
C++

#include <iostream>
#include <string>
#include <map>
#include <cstdlib>
#include <filesystem>
#include "shellUtils.h"
#define WIN_EXEC .append(".exe") // executables on windows need .exe to run
int main()
{
std::cout << std::unitbuf;
std::cerr << std::unitbuf;
bool exit {false};
while (!exit)
{
std::string input;
std::cout << "$ ";
std::getline(std::cin, input);
std::optional<std::filesystem::path> result;
switch (sh::Command command = sh::getCommand(input))
{
case sh::Command::exit:
exit = true;
break;
case sh::Command::echo:
std::cout << input.substr(5) << "\n";
break;
case sh::Command::unknown:
result = sh::isExec(input.substr(0, input.find(' '))WIN_EXEC);
if (result)
{
std::system(input.c_str());
}
else
{
std::cout << input << ": command not found\n";
}
break;
case sh::Command::type:
sh::printType(input.substr(5)WIN_EXEC);
break;
}
}
}