Skip to content

Commit 13e9d06

Browse files
author
曹维杰
authored
Merge pull request #7 from jswh/dev
source .wslexerc file before run real cmd
2 parents a418423 + 183d0a4 commit 13e9d06

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wslexe"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
authors = ["Andreas Riffnaller-Schiefer <[email protected]>"]
55
license = "MIT"
66

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## WSLEXE
1+
## WSLEXE
22
The WSL system makes a great convenience of development on Windows.But the integretion to IDEs and code editors is not convenient.
33

44
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 .
@@ -7,9 +7,10 @@ This shows a way to use wsl application in windows enviroment for IDEs and code
77

88
## Usage
99

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

1415
## Compatibility
1516
* python.exe

src/processor.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ fn shell_escape(arg: String) -> String {
4848
arg.replace(";", "$';'")
4949
}
5050
pub fn execute(interactive: bool) {
51+
let mut exe_path = env::current_exe().unwrap();
52+
exe_path.pop();
53+
let wslexerc_path = format!("{}\\.wslexerc", exe_path.display());
54+
5155
let mut cmd_args = Vec::new();
5256
let mut wsl_args: Vec<String> = vec![];
5357
let wsl_cmd: String;
@@ -63,14 +67,24 @@ pub fn execute(interactive: bool) {
6367
.map(translate_path_to_unix)
6468
.map(shell_escape),
6569
);
66-
wsl_cmd = wsl_args.join(" ");
70+
if Path::new(&wslexerc_path).exists() {
71+
wsl_cmd = format!(
72+
"source {};{}",
73+
translate_path_to_unix(wslexerc_path),
74+
wsl_args.join(" ")
75+
);
76+
} else {
77+
wsl_cmd = wsl_args.join(" ");
78+
}
79+
let exe_cmd: String;
6780
if interactive {
68-
cmd_args.push("bash".to_string());
69-
cmd_args.push("-ic".to_string());
70-
cmd_args.push(wsl_cmd.clone());
81+
exe_cmd = "-ic".to_string();
7182
} else {
72-
cmd_args.clone_from(&wsl_args);
83+
exe_cmd = "-c".to_string();
7384
}
85+
cmd_args.push("bash".to_string());
86+
cmd_args.push(exe_cmd);
87+
cmd_args.push(wsl_cmd.clone());
7488

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

0 commit comments

Comments
 (0)