dotfiles/modules/shell/git.nix

130 lines
3.9 KiB
Nix
Raw Permalink Normal View History

{ config, pkgs, lib, ... }:
2022-04-30 14:21:43 +00:00
let home-packages = config.home-manager.users.${config.user}.home.packages;
2022-04-30 14:21:43 +00:00
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 = {
pager = { branch = "false"; };
2022-05-29 17:44:45 +00:00
safe = { directory = config.dotfilesPath; };
pull = { ff = "only"; };
2022-05-16 12:29:32 +00:00
init = { defaultBranch = "master"; };
2022-04-30 14:21:43 +00:00
};
2022-06-21 03:34:24 +00:00
ignores = [ ".direnv/**" "result" ];
2022-04-30 14:21:43 +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";
gpp = "git-push-upstream";
gl = "git log --graph --decorate --oneline -20";
gll = "git log --graph --decorate --oneline";
gco = "git checkout";
2022-06-20 13:19:51 +00:00
gcom = ''
git switch (git symbolic-ref refs/remotes/origin/HEAD | cut -d"/" -f4)'';
gcob = "git switch -c";
gb = "git branch";
gbd = "git branch -d";
gbD = "git branch -D";
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
home.packages = with pkgs; [ fish fzf bat ];
programs.fish.functions = lib.mkIf (builtins.elem pkgs.fzf home-packages
&& builtins.elem pkgs.bat home-packages) {
2022-05-06 13:44:21 +00:00
git = { body = builtins.readFile ./fish/functions/git.fish; };
git-add-fuzzy = {
2022-05-06 13:44:21 +00:00
body = builtins.readFile ./fish/functions/git-add-fuzzy.fish;
};
git-fuzzy-branch = {
argumentNames = "header";
2022-05-06 13:44:21 +00:00
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-merge-fuzzy = {
body = ''
set branch (git-fuzzy-branch "merge from...")
and git merge $branch
'';
};
git-show-fuzzy = {
2022-05-06 13:44:21 +00:00
body = builtins.readFile ./fish/functions/git-show-fuzzy.fish;
};
git-commits = {
2022-05-06 13:44:21 +00:00
body = builtins.readFile ./fish/functions/git-commits.fish;
};
git-history = {
2022-05-06 13:44:21 +00:00
body = builtins.readFile ./fish/functions/git-history.fish;
};
git-push-upstream = {
description = "Create upstream branch";
2022-05-06 13:44:21 +00:00
body = builtins.readFile ./fish/functions/git-push-upstream.fish;
};
uncommitted = {
description = "Find uncommitted git repos";
2022-05-06 13:44:21 +00:00
body = builtins.readFile ./fish/functions/uncommitted.fish;
};
};
};
2022-04-28 23:20:46 +00:00
};
}