Skip to content

Commit

Permalink
Merge pull request #7 from jswh/dev
Browse files Browse the repository at this point in the history
 source .wslexerc file before run real cmd
  • Loading branch information
曹维杰 authored Oct 12, 2018
2 parents a418423 + 183d0a4 commit 13e9d06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wslexe"
version = "0.8.0"
version = "0.8.1"
authors = ["Andreas Riffnaller-Schiefer <[email protected]>"]
license = "MIT"

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## WSLEXE
## WSLEXE
The WSL system makes a great convenience of development on Windows.But the integretion to IDEs and code editors is not convenient.

The project [wslgit](https://github.com/andy-5/wslgit) makes a dummy exe that trying to receive the arguments and translating all paths from windows type to unix type, and reform these arguments to the real command in wsl .
Expand All @@ -7,9 +7,10 @@ This shows a way to use wsl application in windows enviroment for IDEs and code

## Usage

1. download the [wsl.exe](https://github.com/jswh/wslexe/releases)
1. download the [wslexe.exe](https://github.com/jswh/wslexe/releases)
2. rename it to the command you want to use, for example pyhon.exe
3. change your ide or editor config to point to the executable file
4. if you have a ".wslexerc" in the path where the executable file exists, it will be sourced before the real command

## Compatibility
* python.exe
Expand Down
24 changes: 19 additions & 5 deletions src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ fn shell_escape(arg: String) -> String {
arg.replace(";", "$';'")
}
pub fn execute(interactive: bool) {
let mut exe_path = env::current_exe().unwrap();
exe_path.pop();
let wslexerc_path = format!("{}\\.wslexerc", exe_path.display());

let mut cmd_args = Vec::new();
let mut wsl_args: Vec<String> = vec![];
let wsl_cmd: String;
Expand All @@ -63,14 +67,24 @@ pub fn execute(interactive: bool) {
.map(translate_path_to_unix)
.map(shell_escape),
);
wsl_cmd = wsl_args.join(" ");
if Path::new(&wslexerc_path).exists() {
wsl_cmd = format!(
"source {};{}",
translate_path_to_unix(wslexerc_path),
wsl_args.join(" ")
);
} else {
wsl_cmd = wsl_args.join(" ");
}
let exe_cmd: String;
if interactive {
cmd_args.push("bash".to_string());
cmd_args.push("-ic".to_string());
cmd_args.push(wsl_cmd.clone());
exe_cmd = "-ic".to_string();
} else {
cmd_args.clone_from(&wsl_args);
exe_cmd = "-c".to_string();
}
cmd_args.push("bash".to_string());
cmd_args.push(exe_cmd);
cmd_args.push(wsl_cmd.clone());

// setup stdin/stdout
let stdin_mode = if wsl_cmd.ends_with("--version") {
Expand Down

0 comments on commit 13e9d06

Please sign in to comment.