Repository: nushell/nushell
File: crates/nu-cli/src/completions/completion_common.rs (Rust)

Code before:
                    .ok()
                    .as_ref(),
            )
            .map(lscolors::Style::to_nu_ansi_term_style)
            .unwrap_or_default()
        });
        FileSuggestion {
            span,
            path: escape_path(path),
            style,
            is_dir,
        }
    })
    .collect()
}

// Fix files or folders with quotes or hashes
pub fn escape_path(path: String) -> String {
    // make glob pattern have the highest priority.
    if nu_glob::is_glob(path.as_str()) || path.contains('`') {
        // expand home `~` for https://github.com/nushell/nushell/issues/13905
        let pathbuf = nu_path::expand_tilde(path);
        let path = pathbuf.to_string_lossy();
        if path.contains('\'') {
            // decide to use double quotes
            // std::path::Path::display will do the escaping for `"`, `\`
            format!("{:?}", path)
        } else {
            format!("'{path}'")
        }
    } else {
        let contaminated =
            path.contains(['\'', '"', ' ', '#', '(', ')', '{', '}', '[', ']', '|', ';']);
        let maybe_flag = path.starts_with('-');
        let maybe_variable = path.starts_with('$');
        let maybe_number = path.parse::<f64>().is_ok();
        if contaminated || maybe_flag || maybe_variable || maybe_number {
            format!("`{path}`")
        } else {
            path
        }
    }
}

pub struct AdjustView {
    pub prefix: String,
    pub span: Span,
    pub readjusted: bool,
}

pub fn adjust_if_intermediate(

Review comment (bug):
Should be `Path as Debug`. Not sure if there is any divergence between our `"` strings and Rusts that could appear.

Code after:
                    .ok()
                    .as_ref(),
            )
            .map(lscolors::Style::to_nu_ansi_term_style)
            .unwrap_or_default()
        });
        FileSuggestion {
            span,
            path: escape_path(path),
            style,
            is_dir,
        }
    })
    .collect()
}

// Fix files or folders with quotes or hashes
pub fn escape_path(path: String) -> String {
    // make glob pattern have the highest priority.
    if nu_glob::is_glob(path.as_str()) || path.contains('`') {
        // expand home `~` for https://github.com/nushell/nushell/issues/13905
        let pathbuf = nu_path::expand_tilde(path);
        let path = pathbuf.to_string_lossy();
        if path.contains('\'') {
            // decide to use double quotes
            // Path as Debug will do the escaping for `"`, `\`
            format!("{:?}", path)
        } else {
            format!("'{path}'")
        }
    } else {
        let contaminated =
            path.contains(['\'', '"', ' ', '#', '(', ')', '{', '}', '[', ']', '|', ';']);
        let maybe_flag = path.starts_with('-');
        let maybe_variable = path.starts_with('$');
        let maybe_number = path.parse::<f64>().is_ok();
        if contaminated || maybe_flag || maybe_variable || maybe_number {
            format!("`{path}`")
        } else {
            path
        }
    }
}

pub struct AdjustView {
    pub prefix: String,
    pub span: Span,
    pub readjusted: bool,
}

pub fn adjust_if_intermediate(