From da195e8e775e981f86cbbb5e7a7d59aee403615a Mon Sep 17 00:00:00 2001 From: smarttommyau Date: Sun, 22 May 2022 00:14:25 +0800 Subject: [PATCH] initial repo --- README.md | 28 ++++++++++++++++++++++++++++ tmux.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 README.md create mode 100644 tmux.cpp diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc8d521 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Tmux for windows using wsl support + +# Pre-request +- WSL + +# Setup WSL + +Install a new distro, alpine is recommended.\ +Follow the basic instruction on installing it.\ +Then install tmux.\ +Alpine : apk update&&apk add tmux\ +Debian/ubuntu: apt install tmux + +Add new file ~/.profile with this code to automatically run powershell in tmux sessions +``` +if [ -n "$TMUX" ]; then + pwsh.exe +fi +``` +# Install our program +Add the path you download our program to environment path. + +# Setup our program +Add or edit file tmux.conf on the same folder of our program. +``` +distro: alpine //your distro name +``` +# Enjoy \ No newline at end of file diff --git a/tmux.cpp b/tmux.cpp new file mode 100644 index 0000000..694215c --- /dev/null +++ b/tmux.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +std::string get_exe_loaction(){ + wchar_t szPath[MAX_PATH]; + std::string path; + GetModuleFileNameW( NULL, szPath, MAX_PATH ); + return std::filesystem::path{ szPath }.parent_path().u8string() + "\\" ; +} +int main(int argc,char *argv[]){ + std::ifstream config; + config.open(get_exe_loaction() + "tmux.conf"); + if(!config.good()){ + std::cerr << "config file not found" << std::endl; + return -1; + } + std::string distro; + bool dis = false; + while(!config.eof()){ + std::string input; + config >> input; + if(dis && distro.empty()){ + distro = input; + } + if(input == "distro:"){ + dis = true; + } + } + if(!dis){ + std::cerr << "ERROR: distro name is not set" << std::endl; + return -2; + } + std::string cmd = "wsl.exe -d " + distro + " tmux"; + for(int i = 1;i < argc;i++){ + cmd.append(" "); + cmd.append(argv[i]); + } + system(cmd.c_str()); + return 0; +} \ No newline at end of file