mirror of
https://github.com/sharkdp/bat
synced 2026-08-03 18:51:44 +00:00
Add --fallback-syntax for undetected files (#3617)
* feat(cli): add fallback syntax option Expose a new fallback syntax CLI option so users can opt into syntax highlighting only when auto-detection fails. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * feat(syntax): apply fallback only after detection fails Use the fallback syntax only when path and first-line detection fail, preserving existing behavior for detected files and explicit language selection. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * test(cli): cover fallback syntax behavior Add integration coverage for fallback syntax usage, precedence with --language, and no-op behavior when syntax is already detected; update help snapshots for the new option. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * docs(changelog): document fallback syntax option Record the new fallback syntax feature in the unreleased changelog section. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> --------- Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
committed by
GitHub
parent
ab80bd9717
commit
844bfded50
@@ -384,6 +384,10 @@ impl App {
|
||||
None
|
||||
}
|
||||
}),
|
||||
fallback_syntax: self
|
||||
.matches
|
||||
.get_one::<String>("fallback-syntax")
|
||||
.map(|s| s.as_str()),
|
||||
show_nonprintable: self.matches.get_flag("show-all"),
|
||||
nonprintable_notation: match self
|
||||
.matches
|
||||
|
||||
@@ -120,6 +120,17 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
language names and file extensions.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("fallback-syntax")
|
||||
.long("fallback-syntax")
|
||||
.visible_alias("fallback-language")
|
||||
.help("Set a fallback language for undetected syntaxes.")
|
||||
.long_help(
|
||||
"Set a fallback language for syntax highlighting when auto-detection fails. \
|
||||
Unlike '--language', this is only used when no syntax could be detected from \
|
||||
filename, custom syntax mappings, or first-line detection.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("highlight-line")
|
||||
.long("highlight-line")
|
||||
|
||||
Reference in New Issue
Block a user