Skip to content

Commit 8672b21

Browse files
authored
Merge pull request #4 from Multirious/multirious
v0.3.0
2 parents 41ffcd3 + 64581b9 commit 8672b21

File tree

4 files changed

+63
-32
lines changed

4 files changed

+63
-32
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ This tool is currently made as a workaround for it.
1818

1919
- File switching
2020
- Focuses Helix window that already exists or create one if not.
21+
- Jump to errors and warnings
2122
- Supports using Helix in WSL.
2223

23-
![preview](https://github.com/Multirious/helix-win-runner/assets/77918086/3a5396ca-5a1d-40f2-900d-9557769f67b9)
24+
![demo](https://github-production-user-asset-6210df.s3.amazonaws.com/77918086/295451165-24059abe-350c-41a1-a617-7a1e1391e806.gif?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20240110%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240110T044835Z&X-Amz-Expires=300&X-Amz-Signature=24455f8f2ac93a467edd19051b3acfb74fc59bb490ede68028343062e2fa0f52&X-Amz-SignedHeaders=host&actor_id=77918086&key_id=0&repo_id=612031113)
2425

2526
You can issue a feature request!
2627

27-
# How to use
28+
# Usages
2829

2930
Run `-h`, `--help` to see availiable flags to use.
3031
Basic usages are explained in the help command.
@@ -34,9 +35,8 @@ See [Quick Start section](#quick-start).
3435
> [!NOTE]
3536
> This tool do not launch Helix on its own.
3637
37-
This tool actually don't contains any script for initializing Helix on a terminal.
38-
You can use any terminal and configuration you want by creating a launch script and provide them to the `-e`, `--execute-path` flag.
39-
In the [Quick Start section](#quick-start) I've used a batch script for this purpose.
38+
Use `--run` flag to let the CLI run a command when window is not found.
39+
The CLI will run a macro after running a command by default, to prevent this use `--no-init-macro`.
4040
The CLI also works without a launch script but then you need to launch Helix yourself (only need to be done one time per session).
4141

4242
Use `--list` flag to display windows currently opened. Use the information given for `-n`, `--window-process-name` or `-t`, `--window-title`.
@@ -45,14 +45,13 @@ Recommended to use `-r`, `--relative` and/or `--clipboard` to speed up the proce
4545

4646
# Quick Start
4747

48-
This is a batch script to launch Helix in Windows Terminal:
49-
```bat
50-
wt nt -p "Windows PowerShell" --title "Helix" hx
51-
```
48+
Launch Helix in Windows Terminal
5249

5350
Godot settings:
5451
| Property | Value |
5552
|---------- |------------------|
5653
|`exec_path` |`<path to helix-win-runner>`|
57-
|`exec_flags`|`-e <path to launch script> -w 3 -t "Helix" -n "WindowsTerminal.exe" -p {project} -f {file} -l {line} -c {col} -r --clipboard`|
54+
|`exec_flags`|`--clipboard -r --run "wt nt --title 'Helix' hx -w {project} {file}:{line}:{col}" --no-init-macro -t "Helix" -n "WindowsTerminal.exe" -p {project} -f {file} -l {line} -c {col}`|
55+
56+
5857

src/keyboard_macro.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,40 @@ fn quote(e: &mut std::sync::MutexGuard<'static, enigo::Enigo>) {
1717

1818
pub fn helix_change_directory(directory: &str, clipboard: bool) {
1919
let mut enigo = enigo();
20-
enigo.key_sequence(":cd ");
21-
quote(&mut enigo);
20+
enigo.key_click(Key::Escape);
21+
enigo.key_down(Key::Shift);
22+
enigo.key_click(Key::Layout(';'));
23+
enigo.key_up(Key::Shift);
2224
if clipboard {
23-
paste_restore(&mut enigo, directory);
25+
paste_restore(&mut enigo, &format!(r#"cd "{directory}""#));
2426
} else {
27+
enigo.key_sequence("cd ");
28+
quote(&mut enigo);
2529
enigo.key_sequence(directory);
30+
quote(&mut enigo);
2631
}
27-
quote(&mut enigo);
2832
enigo.key_click(Key::Return)
2933
}
3034

3135
pub fn helix_open_file(file: &str, line: u32, column: u32, clipboard: bool) {
3236
let mut enigo = enigo();
33-
enigo.key_sequence(":o ");
34-
quote(&mut enigo);
37+
enigo.key_click(Key::Escape);
38+
enigo.key_down(Key::Shift);
39+
enigo.key_click(Key::Layout(';'));
40+
enigo.key_up(Key::Shift);
3541
if clipboard {
36-
paste_restore(&mut enigo, file);
42+
paste_restore(&mut enigo, &format!(r#"o {file}"#));
3743
} else {
44+
enigo.key_sequence("o ");
45+
quote(&mut enigo);
3846
enigo.key_sequence(file);
47+
quote(&mut enigo);
3948
}
40-
quote(&mut enigo);
4149
enigo.key_click(Key::Return);
4250
enigo.key_sequence(&format!("{line}gg")[..]);
4351
if column > 1 {
4452
enigo.key_sequence(&format!("{column}l")[..]);
4553
}
46-
enigo.key_click(Key::Return)
4754
}
4855

4956
pub fn sleep(secs: f64) {
@@ -57,12 +64,12 @@ pub fn paste_restore(enigo: &mut enigo::Enigo, msg: &str) {
5764
clipboard_win::set(clipboard_win::formats::Unicode, msg).expect("To set clipboard")
5865
})
5966
.expect("To open clipboard");
60-
sleep(0.1);
67+
sleep(0.05);
6168
enigo.key_down(Key::Control);
6269
enigo.key_down(Key::Layout('v'));
6370
enigo.key_up(Key::Layout('v'));
6471
enigo.key_up(Key::Control);
65-
sleep(0.1);
72+
sleep(0.05);
6673
if let Some(store) = clipboard_store.take() {
6774
clipboard_win::with_clipboard_attempts(10, move || {
6875
store.restore().expect("To set clipboard")

src/main.rs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ mod test;
1414
#[derive(Parser, Debug)]
1515
#[command(author, version, about, long_about = None)]
1616
struct Args {
17-
/// Command to execute when no window found.
17+
/// [DEPRECATED] Command to execute when no window found.
1818
/// If not provided, only search will be done.
19+
///
20+
/// DEPRECATED: use `run` flag.
1921
#[arg(short = 'e', long, value_name = "PATH")]
2022
execute_path: Option<String>,
2123

22-
/// Time to wait after executing `execute_path`.
24+
/// [DEPRECATED] Time to wait after executing `execute_path`.
2325
/// Does nothing if not execute.
26+
///
27+
/// DEPRECATED: use `run_wait` flag.
2428
#[arg(short = 'w', long, value_name = "SECS")]
2529
execute_wait: Option<f64>,
2630

@@ -73,6 +77,21 @@ struct Args {
7377
/// This will not replace your current clipboard!
7478
#[arg(long)]
7579
clipboard: bool,
80+
81+
/// Use no macro when a command is ran
82+
#[arg(long)]
83+
no_init_macro: bool,
84+
85+
/// Command to run when no window is found.
86+
/// If not provided, only search will be done.
87+
#[arg(long = "run", value_name = "CMD")]
88+
run_command: Option<Vec<String>>,
89+
90+
/// After running a command, wait for a bit before running a macro.
91+
///
92+
/// `no-launch-macro` flag disable this entirely
93+
#[arg(long = "run-wait", value_name = "SECS")]
94+
run_command_and_wait: Option<f64>,
7695
}
7796

7897
fn main() -> Result<()> {
@@ -99,13 +118,19 @@ fn main() -> Result<()> {
99118

100119
let res = focus_window(args.all, &window_title, &window_process_name);
101120
let mut is_change_directory = false;
102-
match (res, args.execute_path) {
103-
(Err(Error::WindowNotFound), Some(path)) => {
104-
execute_path(path)?;
105-
if let Some(execute_wait) = args.execute_wait {
106-
sleep(execute_wait);
121+
let run_command_args = args
122+
.run_command
123+
.or_else(|| args.execute_path.map(|p| vec![p]));
124+
match (res, run_command_args) {
125+
(Err(Error::WindowNotFound), Some(run_command_args)) => {
126+
run_command(run_command_args)?;
127+
if let Some(wait) = args.run_command_and_wait.or(args.execute_wait) {
128+
sleep(wait);
107129
}
108130
focus_window(args.all, &window_title, &window_process_name)?;
131+
if args.no_init_macro {
132+
return Ok(());
133+
}
109134
if let Some(project_path) = &args.project_path {
110135
let project_path = if args.wsl {
111136
Cow::Owned(window_path_to_wsl(project_path))
@@ -120,7 +145,7 @@ fn main() -> Result<()> {
120145
_ => {}
121146
}
122147

123-
sleep(0.3);
148+
sleep(0.1);
124149

125150
if let Some(file_path) = args.file_path {
126151
if is_change_directory {
@@ -147,9 +172,9 @@ fn main() -> Result<()> {
147172
Ok(())
148173
}
149174

150-
fn execute_path<P: AsRef<std::path::Path>>(path: P) -> Result<()> {
175+
fn run_command(args: Vec<String>) -> Result<()> {
151176
use std::process::Command;
152-
Command::new("cmd").arg("/C").arg(path.as_ref()).spawn()?;
177+
Command::new("cmd").arg("/C").args(args).spawn()?;
153178
Ok(())
154179
}
155180

src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl Window {
175175
SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE,
176176
)?;
177177
self.set_foreground();
178-
// self.set_focus()?;
178+
self.set_focus()?;
179179
self.set_active()?;
180180
Ok(())
181181
}

0 commit comments

Comments
 (0)