mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-03 03:19:20 +01:00
Support XDG_CONFIG_HOME git config files
This commit is contained in:
parent
fd52c01e78
commit
31acbe20d3
@ -103,6 +103,43 @@ impl<'a> SyntaxMapping<'a> {
|
|||||||
.insert("*.hook", MappingTarget::MapTo("INI"))
|
.insert("*.hook", MappingTarget::MapTo("INI"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
if let Some(xdg_config_home) = std::env::var_os("XDG_CONFIG_HOME") {
|
||||||
|
let git_config_path = Path::new(&xdg_config_home).join("git");
|
||||||
|
|
||||||
|
mapping
|
||||||
|
.insert(
|
||||||
|
&git_config_path
|
||||||
|
.join("config")
|
||||||
|
.into_os_string()
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
MappingTarget::MapTo("Git Config"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
mapping
|
||||||
|
.insert(
|
||||||
|
&git_config_path
|
||||||
|
.join("ignore")
|
||||||
|
.into_os_string()
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
MappingTarget::MapTo("Git Ignore"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
mapping
|
||||||
|
.insert(
|
||||||
|
&git_config_path
|
||||||
|
.join("attributes")
|
||||||
|
.into_os_string()
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
MappingTarget::MapTo("Git Attributes"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
mapping
|
mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +192,23 @@ fn basic() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn git_xdg_config_home() {
|
||||||
|
use assert_cmd::Command;
|
||||||
|
let mut cmd = Command::cargo_bin("bat").unwrap();
|
||||||
|
let mut map = SyntaxMapping::builtin();
|
||||||
|
|
||||||
|
cmd.env("XDG_CONFIG_HOME", "/foo/bar");
|
||||||
|
|
||||||
|
map.insert("/foo/bar/git/config", MappingTarget::MapTo("Git Config"))
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
map.get_syntax_for("/foo/bar/git/config"),
|
||||||
|
Some(MappingTarget::MapTo("Git Config"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn user_can_override_builtin_mappings() {
|
fn user_can_override_builtin_mappings() {
|
||||||
let mut map = SyntaxMapping::builtin();
|
let mut map = SyntaxMapping::builtin();
|
||||||
|
Loading…
Reference in New Issue
Block a user