finished windows support
This commit is contained in:
parent
41d2d2121f
commit
5b10cc1038
|
|
@ -1,19 +1,19 @@
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(shell)
|
project(shell)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/windows)
|
|
||||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
||||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/linux)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
|
||||||
|
|
||||||
add_executable(shell src/main.cpp
|
add_executable(shell src/main.cpp
|
||||||
src/shellUtils.cpp
|
src/shellUtils.cpp
|
||||||
include/shellUtils.h)
|
include/shellUtils.h)
|
||||||
|
|
||||||
target_include_directories(shell PRIVATE include)
|
target_include_directories(shell PRIVATE include)
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT shell)
|
||||||
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake -S .. -B .
|
cmake -S .. -B .
|
||||||
cmake --build .
|
cmake --build . --config Release
|
||||||
PAUSE
|
PAUSE
|
||||||
|
|
@ -25,7 +25,7 @@ namespace sh
|
||||||
|
|
||||||
Command getCommand(std::string_view input);
|
Command getCommand(std::string_view input);
|
||||||
|
|
||||||
std::optional<std::string> isExec(const std::string& input);
|
std::optional<std::filesystem::path> isExec(const std::string& input);
|
||||||
|
|
||||||
void printType(const std::string& input);
|
void printType(const std::string& input);
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include "shellUtils.h"
|
#include "shellUtils.h"
|
||||||
|
|
||||||
|
#define WIN_EXEC .append(".exe")
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << std::unitbuf;
|
std::cout << std::unitbuf;
|
||||||
|
|
@ -17,7 +19,7 @@ int main()
|
||||||
std::string input;
|
std::string input;
|
||||||
std::cout << "$ ";
|
std::cout << "$ ";
|
||||||
std::getline(std::cin, input);
|
std::getline(std::cin, input);
|
||||||
std::optional<std::string> result;
|
std::optional<std::filesystem::path> result;
|
||||||
switch (sh::Command command = sh::getCommand(input))
|
switch (sh::Command command = sh::getCommand(input))
|
||||||
{
|
{
|
||||||
case sh::Command::exit:
|
case sh::Command::exit:
|
||||||
|
|
@ -27,7 +29,7 @@ int main()
|
||||||
std::cout << input.substr(5) << "\n";
|
std::cout << input.substr(5) << "\n";
|
||||||
break;
|
break;
|
||||||
case sh::Command::unknown:
|
case sh::Command::unknown:
|
||||||
result = sh::isExec(input.substr(0, input.find(' ')));
|
result = sh::isExec(input.substr(0, input.find(' '))WIN_EXEC);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
std::system(input.c_str());
|
std::system(input.c_str());
|
||||||
|
|
@ -38,7 +40,7 @@ int main()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case sh::Command::type:
|
case sh::Command::type:
|
||||||
sh::printType(input.substr(5));
|
sh::printType(input.substr(5)WIN_EXEC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace sh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> isExec(const std::string& input)
|
std::optional<std::filesystem::path> isExec(const std::string& input)
|
||||||
{
|
{
|
||||||
|
|
||||||
const std::string_view pathEnv {std::getenv("PATH")};
|
const std::string_view pathEnv {std::getenv("PATH")};
|
||||||
|
|
@ -34,10 +34,9 @@ namespace sh
|
||||||
size_t nextDelimIndex{pathEnv.find(delimiter)};
|
size_t nextDelimIndex{pathEnv.find(delimiter)};
|
||||||
while (nextDelimIndex != std::string::npos)
|
while (nextDelimIndex != std::string::npos)
|
||||||
{
|
{
|
||||||
std::string currentPath {pathEnv.substr(startCharIndex, nextDelimIndex - startCharIndex)};
|
std::filesystem::path currentPath {pathEnv.substr(startCharIndex, nextDelimIndex - startCharIndex)};
|
||||||
std::string fullPath;
|
std::filesystem::path fullPath;
|
||||||
fullPath.append(currentPath).append("/").append(input);
|
fullPath = currentPath / input;
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
if (!fs::exists(fullPath))
|
if (!fs::exists(fullPath))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue