Support XDG_CONFIG_HOME git config files
@@ -103,6 +103,43 @@ impl<'a> SyntaxMapping<'a> {
.insert("*.hook", MappingTarget::MapTo("INI"))
.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
}
@@ -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]
fn user_can_override_builtin_mappings() {
let mut map = SyntaxMapping::builtin();
