-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a `-m`/`--map-syntax` option that allows users to (re)map certain file extensions or file names to an existing syntax. For example: ``` bat --map-syntax .config:json ``` The option can be use multiple times. Note that you can easily make these mappings permanent by using `bat`s new configuration file. closes #169
- Loading branch information
Showing
6 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ mod output; | |
mod preprocessor; | ||
mod printer; | ||
mod style; | ||
mod syntax_mapping; | ||
mod terminal; | ||
mod util; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::borrow::Cow; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct SyntaxMapping(HashMap<String, String>); | ||
|
||
impl SyntaxMapping { | ||
pub fn new() -> SyntaxMapping { | ||
SyntaxMapping(HashMap::new()) | ||
} | ||
|
||
pub fn insert(&mut self, from: String, to: String) -> Option<String> { | ||
self.0.insert(from, to) | ||
} | ||
|
||
pub fn replace<'a>(&self, input: &'a str) -> Cow<'a, str> { | ||
let mut out = Cow::from(input); | ||
if let Some(value) = self.0.get(input) { | ||
out = Cow::from(value.clone()) | ||
} | ||
out | ||
} | ||
} | ||
|
||
#[test] | ||
fn basic() { | ||
let mut map = SyntaxMapping::new(); | ||
map.insert("Cargo.lock".into(), "toml".into()); | ||
map.insert(".ignore".into(), ".gitignore".into()); | ||
|
||
assert_eq!("toml", map.replace("Cargo.lock")); | ||
assert_eq!("other.lock", map.replace("other.lock")); | ||
|
||
assert_eq!(".gitignore", map.replace(".ignore")); | ||
} |