1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 19:32:25 +01:00

Make --map-syntax and --ignored-suffix work together (#2260)

* Make --map-syntax and --ignored-suffix work together

* Minor refactor
This commit is contained in:
Christopher Acosta
2022-08-16 22:42:15 +02:00
committed by GitHub
parent c14ce4f7ca
commit 9a924b445b
5 changed files with 41 additions and 1 deletions

View File

@@ -191,6 +191,7 @@ impl<'a> SyntaxMapping<'a> {
}
pub(crate) fn get_syntax_for(&self, path: impl AsRef<Path>) -> Option<MappingTarget<'a>> {
// Try matching on the file name as-is.
let candidate = Candidate::new(&path);
let candidate_filename = path.as_ref().file_name().map(Candidate::new);
for (ref glob, ref syntax) in self.mappings.iter().rev() {
@@ -202,7 +203,13 @@ impl<'a> SyntaxMapping<'a> {
return Some(*syntax);
}
}
None
// Try matching on the file name after removing an ignored suffix.
let file_name = path.as_ref().file_name()?;
self.ignored_suffixes
.try_with_stripped_suffix(file_name, |stripped_file_name| {
Ok(self.get_syntax_for(stripped_file_name))
})
.ok()?
}
pub fn insert_ignored_suffix(&mut self, suffix: &'a str) {