diff --git a/users/myuser/git.nix b/users/myuser/git.nix index 1fe6494..fa8068c 100644 --- a/users/myuser/git.nix +++ b/users/myuser/git.nix @@ -66,6 +66,25 @@ gca = "git commit -v -S --amend"; gcl = "git clone"; gcr = "git commit-reuse-message -v -S"; + 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" "$@" + ''; + }); gp = "git push"; gpf = "git push --force"; gs = "git s";