Skip to content

Commit

Permalink
Shell::readln now completes to a filename if the last word is a file (#…
Browse files Browse the repository at this point in the history
…342)

* Shell::readln now completes to a filename if the last word is a file

- This allows situations like "./foo" to complete to a local directory
"./foobar"
- I'm not sure how efficient this is compared to the old competion, I'm
guessing not very.

* Have completion be relative to the current directory

* Remove random newline
  • Loading branch information
hgoldstein authored and mmstick committed Jun 25, 2017
1 parent c7c66ee commit 4cc422e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/shell/mod.rs
Expand Up @@ -77,6 +77,7 @@ impl<'a> Shell<'a> {
sigint_handle: ctrl_c
}
}

fn readln(&mut self) -> Option<String> {
let vars_ptr = &self.variables as *const Variables;
let dirs_ptr = &self.directory_stack as *const DirectoryStack;
Expand All @@ -103,10 +104,17 @@ impl<'a> Shell<'a> {
CursorPosition::InSpace(None, _) => false,
CursorPosition::OnWordLeftEdge(index) => index >= 1,
CursorPosition::OnWordRightEdge(index) => {
index >= 1 && !words.into_iter().nth(index).map(|(start, end)| {
let buf = editor.current_buffer();
buf.range(start, end).trim().starts_with('$')
}).unwrap_or(false)
if let Some((start, end)) = words.into_iter().nth(index) {
if let Ok(mut file) = env::current_dir() {
let filename = editor.current_buffer().range(start, end);
file.push(filename);
file.exists() || file.parent().map(Path::exists).unwrap_or(false)
} else {
false
}
} else {
false
}
}
};

Expand Down

0 comments on commit 4cc422e

Please sign in to comment.