Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relative path completion fixes #137

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion brush-core/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ impl Config {
fn get_file_completions(shell: &Shell, context: &Context, must_be_dir: bool) -> Vec<String> {
let glob = std::format!("{}*", context.token_to_complete);

let path_filter = |path: &Path| !must_be_dir || path.is_dir();
let path_filter = |path: &Path| !must_be_dir || shell.get_absolute_path(path).is_dir();

// TODO: Pass through quoting.
patterns::Pattern::from(glob)
Expand Down
2 changes: 1 addition & 1 deletion brush-core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ impl Shell {
/// # Arguments
///
/// * `path` - The path to get the absolute form of.
pub(crate) fn get_absolute_path(&self, path: &Path) -> PathBuf {
pub fn get_absolute_path(&self, path: &Path) -> PathBuf {
if path.is_absolute() {
path.to_owned()
} else {
Expand Down
16 changes: 13 additions & 3 deletions brush-interactive/src/interactive_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ impl EditorHelper {
line: &str,
pos: usize,
) -> rustyline::Result<(usize, Vec<rustyline::completion::Pair>)> {
let working_dir = self.shell.working_dir.clone();

// Intentionally ignore any errors that arise.
let completion_future = self.shell.get_completions(line, pos);
tokio::pin!(completion_future);
Expand All @@ -261,9 +263,17 @@ impl EditorHelper {
if completions.options.treat_as_filenames {
for candidate in &mut completions.candidates {
// Check if it's a directory.
if !candidate.ends_with(std::path::MAIN_SEPARATOR) && Path::new(candidate).is_dir()
{
candidate.push(std::path::MAIN_SEPARATOR);
if !candidate.ends_with(std::path::MAIN_SEPARATOR) {
let candidate_path = Path::new(candidate);
let abs_candidate_path = if candidate_path.is_absolute() {
PathBuf::from(candidate_path)
} else {
working_dir.join(candidate_path)
};

if abs_candidate_path.is_dir() {
candidate.push(std::path::MAIN_SEPARATOR);
}
}
}
}
Expand Down
Loading