Skip to content

Commit

Permalink
adding shellexpand and extend surround_chars
Browse files Browse the repository at this point in the history
  • Loading branch information
TornaxO7 committed Dec 12, 2023
1 parent 5109286 commit eab5cbd
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
22 changes: 14 additions & 8 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit eab5cbd

Please sign in to comment.