diff --git a/Cargo.lock b/Cargo.lock index ea007bd4d3b5..6033a6f7aed1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,6 +350,27 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dunce" version = "1.0.4" @@ -1180,6 +1201,7 @@ dependencies = [ "pulldown-cmark", "serde", "serde_json", + "shellexpand", "signal-hook", "signal-hook-tokio", "smallvec", @@ -1400,6 +1422,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.1", + "libc", + "redox_syscall 0.4.1", +] + [[package]] name = "link-cplusplus" version = "1.0.8" @@ -1574,6 +1607,12 @@ dependencies = [ "pathdiff", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1723,6 +1762,17 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.2" @@ -1865,6 +1915,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +[[package]] +name = "shellexpand" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da03fa3b94cc19e3ebfc88c4229c49d8f08cdbd1228870a45f0ffdf84988e14b" +dependencies = [ + "dirs", +] + [[package]] name = "signal-hook" version = "0.3.17" diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index ac5a8475d080..c07e5d5e0dfd 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -71,7 +71,10 @@ serde = { version = "1.0", features = ["derive"] } grep-regex = "0.1.12" grep-searcher = "0.1.13" -[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 +# expand env-variables in paths +shellexpand = "3.1" + +[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } libc = "0.2.150" diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e557977adf88..75291abc79ce 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1176,6 +1176,8 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let primary = selections.primary(); // Checks whether there is only one selection with a width of 1 if selections.len() == 1 && primary.len() == 1 { + paths.clear(); + let count = cx.count(); let text_slice = text.slice(..); // In this case it selects the WORD under the cursor @@ -1187,14 +1189,18 @@ fn goto_file_impl(cx: &mut Context, action: Action) { true, ); // Trims some surrounding chars so that the actual file is opened. - let surrounding_chars: &[_] = &['\'', '"', '(', ')']; - paths.clear(); - paths.push( - current_word - .fragment(text_slice) - .trim_matches(surrounding_chars) - .to_string(), - ); + let surrounding_chars: &[_] = &['\'', '"', '(', ')', ',', ';', '{', '}', '[', ']']; + let path = current_word + .fragment(text_slice) + .trim_matches(surrounding_chars) + .to_string(); + + match shellexpand::full(&path) { + Ok(path) => paths.push(path.to_string()), + Err(e) => { + cx.editor.set_error(format!("{}", e)); + } + } } for sel in paths {