diff --git a/home/misterio/features/cli/git.nix b/home/misterio/features/cli/git.nix index 9132b0b7..ab64fbf4 100644 --- a/home/misterio/features/cli/git.nix +++ b/home/misterio/features/cli/git.nix @@ -3,40 +3,43 @@ let ssh = "${pkgs.openssh}/bin/ssh"; git-m7 = pkgs.writeShellScriptBin "git-m7" '' - repo="$(git remote -v | grep git@m7.rs | head -1 | cut -d ':' -f2 | cut -d ' ' -f1)" - # Add a .git suffix if it's missing - if [[ "$repo" != *".git" ]]; then - repo="$repo.git" - fi - - if [ "$1" == "init" ]; then - if [ "$2" == "" ]; then - echo "You must specify a name for the repo" - exit 1 - fi - ${ssh} -A git@m7.rs << EOF - git init --bare "$2.git" - git -C "$2.git" branch -m main + case "''${1:-ls}" in + ls) + ${ssh} -TA git@m7.rs ls | grep '\.git$' + ;; + init) + name="''${2:-$(basename "$PWD")}" + ${ssh} -TA git@m7.rs << EOF + git init --bare "$name.git" + git -C "$name.git" branch -m main EOF - git remote add origin git@m7.rs:"$2.git" - elif [ "$1" == "ls" ]; then - ${ssh} -A git@m7.rs ls - else - ${ssh} -A git@m7.rs git -C "/srv/git/$repo" $@ - fi + git remote add origin git@m7.rs:"$name.git" + ;; + *) + repo="$(git remote -v | grep git@m7.rs | head -1 | cut -d ':' -f2 | cut -d ' ' -f1)" + if [[ "$repo" != *".git" ]]; then repo="$repo.git"; fi + ${ssh} -TA git@m7.rs git -C "/srv/git/$repo" "$@" + ;; + esac + ''; + # git commit --amend, but for older commits + git-fixup = pkgs.writeShellScriptBin "git-fixup" '' + rev="$(git rev-parse "$1")" + git commit --fixup "$@" + GIT_SEQUENCE_EDITOR=true git rebase -i --autostash --autosquash $rev^ ''; in { - home.packages = [ git-m7 ]; + home.packages = [ git-m7 git-fixup ]; programs.git = { enable = true; package = pkgs.gitAndTools.gitFull; aliases = { + p = "pull --ff-only"; ff = "merge --ff-only"; - pushall = "!git remote | xargs -L1 git push --all"; graph = "log --decorate --oneline --graph"; + pushall = "!git remote | xargs -L1 git push --all"; add-nowhitespace = "!git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -"; - fast-forward = "merge --ff-only"; }; userName = "Gabriel Fontes"; userEmail = "hi@m7.rs";