dotfiles/modules/common/shell/git.nix

196 lines
5.5 KiB
Nix
Raw Normal View History

2024-04-20 13:42:06 +00:00
{
config,
pkgs,
lib,
...
}:
2022-04-30 14:21:43 +00:00
2024-04-20 13:42:06 +00:00
let
home-packages = config.home-manager.users.${config.user}.home.packages;
in
{
2022-04-28 23:20:46 +00:00
options = {
2022-09-10 02:16:45 +00:00
gitName = lib.mkOption {
type = lib.types.str;
2022-09-10 02:16:45 +00:00
description = "Name to use for git commits";
};
gitEmail = lib.mkOption {
type = lib.types.str;
description = "Email to use for git commits";
};
};
config = {
2022-04-28 23:20:46 +00:00
home-manager.users.root.programs.git = {
enable = true;
2022-05-29 17:44:45 +00:00
extraConfig.safe.directory = config.dotfilesPath;
};
2022-04-30 14:21:43 +00:00
home-manager.users.${config.user} = {
programs.git = {
enable = true;
2022-09-10 02:16:45 +00:00
userName = config.gitName;
userEmail = config.gitEmail;
extraConfig = {
2024-04-20 13:42:06 +00:00
core.pager = "${pkgs.git}/share/git/contrib/diff-highlight/diff-highlight | less -F";
interactive.difffilter = "${pkgs.git}/share/git/contrib/diff-highlight/diff-highlight";
pager = {
branch = "false";
};
safe = {
directory = config.dotfilesPath;
};
pull = {
ff = "only";
};
push = {
autoSetupRemote = "true";
};
init = {
defaultBranch = "master";
};
rebase = {
autosquash = "true";
};
2024-03-26 17:07:26 +00:00
gpg = {
format = "ssh";
ssh.allowedSignersFile = "~/.config/git/allowed-signers";
};
# commit.gpgsign = true;
# tag.gpgsign = true;
2022-04-30 14:21:43 +00:00
};
2024-04-20 13:42:06 +00:00
ignores = [
".direnv/**"
"result"
];
includes = [
{
path = "~/.config/git/personal";
condition = "gitdir:~/dev/personal/";
}
];
2022-04-30 14:21:43 +00:00
};
2024-01-25 02:52:33 +00:00
# Personal git config
# TODO: fix with variables
xdg.configFile."git/personal".text = ''
[user]
2024-02-17 01:56:28 +00:00
name = "${config.fullName}"
2024-01-25 02:52:33 +00:00
email = "7386960+nmasur@users.noreply.github.com"
2024-03-26 17:07:26 +00:00
signingkey = ~/.ssh/id_ed25519
[commit]
gpgsign = true
[tag]
gpgsign = true
2024-03-26 17:07:26 +00:00
'';
xdg.configFile."git/allowed-signers".text = ''
7386960+nmasur@users.noreply.github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+AbmjGEwITk5CK9y7+Rg27Fokgj9QEjgc9wST6MA3s
2024-01-25 02:52:33 +00:00
'';
programs.fish.shellAbbrs = {
g = "git";
gs = "git status";
gd = "git diff";
gds = "git diff --staged";
gdp = "git diff HEAD^";
ga = "git add";
gaa = "git add -A";
gac = "git commit -am";
gc = "git commit -m";
gca = "git commit --amend --no-edit";
gcae = "git commit --amend";
gu = "git pull";
gp = "git push";
gl = "git log --graph --decorate --oneline -20";
gll = "git log --graph --decorate --oneline";
gco = "git checkout";
2024-04-20 13:42:06 +00:00
gcom = ''git switch (git symbolic-ref refs/remotes/origin/HEAD | cut -d"/" -f4)'';
gcob = "git switch -c";
gb = "git branch";
2023-12-17 00:32:14 +00:00
gpd = "git push origin -d";
gbd = "git branch -d";
gbD = "git branch -D";
gdd = {
position = "anywhere";
setCursor = true;
expansion = "BRANCH=% git push origin -d $BRANCH and git branch -d $BRANCH";
};
gr = "git reset";
grh = "git reset --hard";
gm = "git merge";
gcp = "git cherry-pick";
cdg = "cd (git rev-parse --show-toplevel)";
};
2022-09-14 03:09:03 +00:00
# Required for fish commands
2024-04-20 13:42:06 +00:00
home.packages = with pkgs; [
fish
fzf
bat
];
2022-09-14 03:09:03 +00:00
2024-04-20 13:42:06 +00:00
programs.fish.functions =
lib.mkIf (builtins.elem pkgs.fzf home-packages && builtins.elem pkgs.bat home-packages)
{
git = {
body = builtins.readFile ./fish/functions/git.fish;
};
git-add-fuzzy = {
body = builtins.readFile ./fish/functions/git-add-fuzzy.fish;
};
git-fuzzy-branch = {
argumentNames = "header";
body = builtins.readFile ./fish/functions/git-fuzzy-branch.fish;
};
git-checkout-fuzzy = {
body = ''
set branch (git-fuzzy-branch "checkout branch...")
and git checkout $branch
'';
};
git-delete-fuzzy = {
body = ''
set branch (git-fuzzy-branch "delete branch...")
and git branch -d $branch
'';
};
git-force-delete-fuzzy = {
body = ''
set branch (git-fuzzy-branch "force delete branch...")
and git branch -D $branch
'';
};
git-delete-both = {
argumentNames = "branch";
body = ''
git push origin -d $branch
git branch -d $branch
'';
};
2024-04-20 13:42:06 +00:00
git-merge-fuzzy = {
body = ''
set branch (git-fuzzy-branch "merge from...")
and git merge $branch
'';
};
git-show-fuzzy = {
body = builtins.readFile ./fish/functions/git-show-fuzzy.fish;
};
git-commits = {
body = builtins.readFile ./fish/functions/git-commits.fish;
};
git-history = {
body = builtins.readFile ./fish/functions/git-history.fish;
};
uncommitted = {
description = "Find uncommitted git repos";
body = builtins.readFile ./fish/functions/uncommitted.fish;
};
};
};
2022-04-28 23:20:46 +00:00
};
}