nix-config/home/git/default.nix

168 lines
3.8 KiB
Nix
Raw Normal View History

2021-03-13 01:01:20 +01:00
{ config, pkgs, lib, ... }:
let
cfg = config.my.home.git;
2021-10-12 17:55:48 +02:00
inherit (lib.my) mkMailAddress;
diff-highlight = "${pkgs.gitAndTools.gitFull}/share/git/contrib/diff-highlight/diff-highlight";
2021-03-13 01:01:20 +01:00
in
2021-02-19 22:48:25 +01:00
{
2021-03-13 01:01:20 +01:00
options.my.home.git = with lib.my; {
enable = mkDisableOption "git configuration";
};
config.home.packages = with pkgs.gitAndTools; lib.mkIf cfg.enable [
gitAndTools.git-absorb
gitAndTools.git-revise
gitAndTools.tig
];
2021-03-13 01:01:20 +01:00
config.programs.git = lib.mkIf cfg.enable {
2021-02-19 22:48:25 +01:00
enable = true;
# Who am I?
2021-10-12 17:55:48 +02:00
userEmail = mkMailAddress "bruno" "belanyi.fr";
2021-02-19 22:48:25 +01:00
userName = "Bruno BELANYI";
# I want the full experience
package = pkgs.gitAndTools.gitFull;
aliases = {
2021-10-12 16:33:33 +02:00
git = "!git";
lol = "log --graph --decorate --pretty=oneline --abbrev-commit --topo-order";
2021-02-19 22:48:25 +01:00
lola = "lol --all";
assume = "update-index --assume-unchanged";
unassume = "update-index --no-assume-unchanged";
assumed = "!git ls-files -v | grep ^h | cut -c 3-";
pick = "log -p -G";
2021-02-19 22:48:25 +01:00
push-new = "!git push -u origin "
+ ''"$(git branch | grep '^* ' | cut -f2- -d' ')"'';
};
lfs.enable = true;
# There's more
extraConfig = {
# Makes it a bit more readable
blame = {
coloring = "repeatedLines";
markIgnoredLines = true;
markUnblamables = true;
2021-02-19 22:48:25 +01:00
};
# I want `pull --rebase` as a default
branch = {
autosetubrebase = "always";
};
# Shiny colors
color = {
branch = "auto";
diff = "auto";
interactive = "auto";
status = "auto";
ui = "auto";
2021-02-19 22:48:25 +01:00
};
# Pretty much the usual diff colors
"color.diff" = {
commit = "yellow";
frag = "cyan";
meta = "yellow";
2021-02-19 22:48:25 +01:00
new = "green";
old = "red";
2021-02-19 22:48:25 +01:00
whitespace = "red reverse";
};
"color.diff-highlight" = {
oldNormal = "red bold";
oldHighlight = "red bold 52";
newNormal = "green bold";
newHighlight = "green bold 22";
};
2021-02-19 22:48:25 +01:00
commit = {
# Show my changes when writing the message
verbose = true;
};
diff = {
# Usually leads to better results
algorithm = "patience";
};
fetch = {
# I don't want hanging references
prune = true;
pruneTags = true;
};
init = {
defaultBranch = "main";
};
interactive = {
diffFilter = "${diff-highlight}";
};
pager = {
diff = "${diff-highlight} | less";
log = "${diff-highlight} | less";
show = "${diff-highlight} | less";
};
2021-02-20 14:30:09 +01:00
2021-02-19 22:48:25 +01:00
pull = {
# Avoid useless merge commits
rebase = true;
};
push = {
# Just yell at me instead of trying to be smart
default = "simple";
};
rebase = {
# Why isn't it the default?...
autoSquash = true;
autoStash = true;
};
url = {
"git@gitea.belanyi.fr:" = {
insteadOf = "https://gitea.belanyi.fr/";
};
"git@github.com:" = {
insteadOf = "https://github.com/";
};
"git@gitlab.com:" = {
insteadOf = "https://gitlab.com/";
};
};
2021-02-19 22:48:25 +01:00
};
# Multiple identities
includes = [
{
condition = "gitdir:~/git/EPITA/";
contents = {
user = {
name = "Bruno BELANYI";
email = mkMailAddress "bruno.belanyi" "epita.fr";
};
};
}
];
2021-02-19 23:16:22 +01:00
ignores =
let
inherit (builtins) readFile;
inherit (lib) filter hasPrefix splitString;
readLines = file: splitString "\n" (readFile file);
removeComments = filter (line: line != "" && !(hasPrefix "#" line));
2021-02-19 23:16:22 +01:00
getPaths = file: removeComments (readLines file);
in
getPaths ./default.ignore;
2021-02-19 22:48:25 +01:00
};
}