home/git: bundle homebrewn external git commands
This commit is contained in:
parent
aed71f1d7b
commit
f053a0f70a
@ -14,7 +14,7 @@ in {
|
||||
./programs/direnv.nix
|
||||
./programs/gdb.nix
|
||||
./programs/gh.nix
|
||||
./programs/git.nix
|
||||
./programs/git
|
||||
./programs/gpg.nix
|
||||
./programs/less.nix
|
||||
./programs/neovim.nix
|
||||
|
@ -1,4 +1,7 @@
|
||||
{ pkgs, ... }:
|
||||
{ config, pkgs, lib, ... }:
|
||||
let
|
||||
cfg = config.programs.git;
|
||||
in
|
||||
{
|
||||
programs.git = {
|
||||
enable = true;
|
||||
@ -30,7 +33,6 @@
|
||||
graphv = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all";
|
||||
forcepush = "push --force-with-lease --force-if-includes";
|
||||
authors = "shortlog --summary --numbered --email";
|
||||
switch-interactive = "!cat <(git branch) <(git branch -r) | grep -v '^\\*\\|HEAD ->' | ${pkgs.fzf}/bin/fzf --reverse --info=inline --preview 'echo {} | xargs git show --color' | sed 's|\\s*.*/||' | xargs git switch";
|
||||
si = "switch-interactive";
|
||||
rebase-author = "rebase -i -x \"git commit --amend --reset-author -CHEAD\"";
|
||||
};
|
||||
@ -147,4 +149,20 @@
|
||||
"shell.nix"
|
||||
];
|
||||
};
|
||||
|
||||
home.packages = [
|
||||
(pkgs.writeShellApplication {
|
||||
name = "git-tcommit";
|
||||
runtimeInputs = with pkgs; [ cfg.package coreutils ];
|
||||
text = lib.fileContents ./scripts/git-tcommit.sh;
|
||||
})
|
||||
(pkgs.writeShellApplication {
|
||||
name = "git-switch-interactive";
|
||||
runtimeInputs = with pkgs; [ cfg.package fzf gnused coreutils ];
|
||||
text = lib.fileContents ./scripts/git-switch-interactive.sh;
|
||||
excludeShellChecks = [
|
||||
"SC2001" # (style): See if you can use ${variable//search/replace} instead. (sed invocation)
|
||||
];
|
||||
})
|
||||
];
|
||||
}
|
11
home/programs/git/scripts/git-switch-interactive.sh
Normal file
11
home/programs/git/scripts/git-switch-interactive.sh
Normal file
@ -0,0 +1,11 @@
|
||||
set -euo pipefail
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
git switch "$1"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
BRANCHES=$(cat <(git branch) <(git branch --remotes) | grep --invert-match '^\*\|HEAD ->' | sed 's|^\s*||')
|
||||
CHOSEN_BRANCH=$(fzf --reverse --info=inline --preview 'git show --color {}' <<<"$BRANCHES")
|
||||
CLEAN_BRANCH_NAME=$(sed 's|^\s*.*/||' <<<"$CHOSEN_BRANCH")
|
||||
git switch "$CLEAN_BRANCH_NAME"
|
31
home/programs/git/scripts/git-tcommit.sh
Executable file
31
home/programs/git/scripts/git-tcommit.sh
Executable file
@ -0,0 +1,31 @@
|
||||
set -euo pipefail
|
||||
|
||||
HOUR_SHIFT="$1"
|
||||
shift
|
||||
|
||||
if [[ $HOUR_SHIFT == -* ]]; then
|
||||
HOUR_SHIFT="${HOUR_SHIFT#*-}"
|
||||
OPERATOR="-"
|
||||
else
|
||||
OPERATOR="+"
|
||||
fi
|
||||
|
||||
DATE=$(date -d "now ${OPERATOR} ${HOUR_SHIFT} hours")
|
||||
|
||||
while true; do
|
||||
echo "Commiting with date: ${DATE} (${OPERATOR}${HOUR_SHIFT}h)"
|
||||
read -rp "Do you want to proceed? (y/n) " yn
|
||||
|
||||
case $yn in
|
||||
[yY] )
|
||||
break;;
|
||||
[nN] )
|
||||
exit;;
|
||||
* ) echo invalid response;;
|
||||
esac
|
||||
done
|
||||
|
||||
export GIT_COMMITTER_DATE="${DATE}"
|
||||
export GIT_AUTHOR_DATE="${DATE}"
|
||||
|
||||
git commit "$@"
|
Loading…
Reference in New Issue
Block a user