Set Git identity per directory

This commit is contained in:
Jakob Lechner 2024-08-13 11:24:28 +02:00
parent 23688c96d5
commit eec9bc3c71
2 changed files with 22 additions and 1 deletions

View file

@ -98,6 +98,10 @@
# fix too dark color on solarized theme
set -g fish_color_autosuggestion brgreen
if type -q fish_set_git_author_by_pwd
fish_set_git_author_by_pwd
end
'';
functions = {

View file

@ -1,5 +1,10 @@
{ nixosConfig, pkgs, ... }:
let
identity.DigitalerDienst = {
name = "Jakob Lechner";
email = "j.lechner@digitaler-dienst.gmbh";
};
in
{
programs = {
git = {
@ -157,6 +162,18 @@
end
'';
};
"fish_set_git_author_by_pwd" = {
description = "Set Git identity by PWD";
body = ''
if string match -n $HOME'/digitaler-dienst/*' $PWD/ > /dev/null
if git rev-parse --git-dir >/dev/null 2>&1
git config --local user.name >/dev/null || git config --local user.name "${identity.DigitalerDienst.name}"
git config --local user.email >/dev/null || git config --local user.email "${identity.DigitalerDienst.email}"
end
end
'';
onVariable = "PWD";
};
};
};
};