diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df233c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cmake-build-debug +cmake-build-release +.idea \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6ef912a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.27) +project(wslrun) + +set(CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc") + +add_executable(wslrun main.cpp) diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..d23a1aa --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# WSLRun +Allows to run bash scripts directly from windows. +It's a minimalistic wrapper around "wsl.exe bash" call with argument file path conversion via wslpath. +Usage example: +* Set wslrun.exe as default program to open ".sh" files in Windows +* Double-click on any file with .sh extension is opened automatically in WSL bash. \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fde9b07 --- /dev/null +++ b/main.cpp @@ -0,0 +1,27 @@ +#include +#include + +int main(int argc, char* argv[]) { + if (argc < 2) { + std::cout << "Missing file path" << std::endl; + return 1; + } + try { + std::string filePath = argv[1]; + char buffer[256]; + std::string wslCommand = "C:\\Windows\\System32\\wsl.exe bash -c $(wslpath '" + filePath + "')"; + FILE* wslProcess = _popen(wslCommand.c_str(), "r"); + if (!wslProcess) { + std::cerr << "Error running WSL." << std::endl; + return 1; + } + while (fgets(buffer, sizeof(buffer), wslProcess)) { + std::cout << buffer << std::endl; + } + _pclose(wslProcess); + return 0; + } catch (const std::exception& e) { + std::cerr << "Exception: " << e.what() << std::endl; + return 1; + } +} \ No newline at end of file