feat(user/git): add interactive fixup
This commit is contained in:
parent
377239650e
commit
1048dbcb77
|
@ -1,4 +1,30 @@
|
|||
{ pkgs, ... }:
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
gf = lib.getExe (
|
||||
pkgs.writeShellApplication {
|
||||
name = "git-fixup-fzf";
|
||||
runtimeInputs = [
|
||||
pkgs.fzf
|
||||
pkgs.gnugrep
|
||||
];
|
||||
text = ''
|
||||
if ! commit=$(git log --graph --color=always --format="%C(auto)%h%d %s %C(reset)%C(bold)%cr" "$@" \
|
||||
| fzf --ansi --multi --no-sort --reverse --print-query --expect=ctrl-d --toggle-sort=\`); then
|
||||
echo aborted
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sha=$(grep -o '^[^a-z0-9]*[a-z0-9]\{7\}[a-z0-9]*' <<< "$commit" | grep -o '[a-z0-9]\{7\}[a-z0-9]*')
|
||||
if [[ -z "$sha" ]]; then
|
||||
echo "Found no checksum for selected commit. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git fixup "$sha" "$@"
|
||||
'';
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
programs.git = {
|
||||
enable = true;
|
||||
|
@ -11,6 +37,7 @@
|
|||
p = "push";
|
||||
rebase = "rebase --gpg-sign";
|
||||
fixup = ''!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ''${@:2} && EDITOR=true git rebase -i --gpg-sign --autostash --autosquash $TARGET^; }; f'';
|
||||
f = "!${gf}";
|
||||
crm = ''!git commit -v -S --edit --file "$(git rev-parse --git-dir)"/COMMIT_EDITMSG'';
|
||||
};
|
||||
extraConfig = {
|
||||
|
|
Loading…
Reference in a new issue