diff --git a/fish-rust/src/wildcard.rs b/fish-rust/src/wildcard.rs index 49bf94e02..8704770f6 100644 --- a/fish-rust/src/wildcard.rs +++ b/fish-rust/src/wildcard.rs @@ -315,17 +315,20 @@ fn file_get_desc( filename: &wstr, lstat: Option, stat: Option>, + definitely_executable: bool, ) -> &'static wstr { let Some(lstat) = lstat else { return *COMPLETE_FILE_DESC; }; - fn is_executable(buf: &fs::Metadata, filename: &wstr) -> bool { + let is_executable = |buf: &fs::Metadata, filename: &wstr| -> bool { // Weird group permissions and other such issues make it non-trivial to find out if // we can actually execute a file using the result from stat. It is much safer to // use the access function, since it tells us exactly what we want to know. - (buf.mode() as mode_t & (S_IXUSR | S_IXGRP | S_IXOTH) != 0) && waccess(filename, X_OK) == 0 - } + definitely_executable + || (buf.mode() as mode_t & (S_IXUSR | S_IXGRP | S_IXOTH) != 0) + && waccess(filename, X_OK) == 0 + }; // stat was only queried if lstat succeeded let stat = stat.unwrap(); @@ -444,7 +447,7 @@ fn wildcard_test_flags_then_complete( // Compute the description. let desc = if expand_flags.contains(ExpandFlags::GEN_DESCRIPTIONS) { - let mut desc = file_get_desc(filename, lstat, stat).to_owned(); + let mut desc = file_get_desc(filename, lstat, stat, executables_only).to_owned(); if !is_directory && !is_executable { if !desc.is_empty() {