summaryrefslogtreecommitdiffstats
path: root/git
diff options
context:
space:
mode:
Diffstat (limited to 'git')
-rwxr-xr-xgit/.bin/git/git-amend13
-rwxr-xr-xgit/.bin/git/git-blame-stats37
-rwxr-xr-xgit/.bin/git/git-default-branch4
-rwxr-xr-xgit/.bin/git/git-file-size5
-rwxr-xr-xgit/.bin/git/git-pr5
-rwxr-xr-xgit/.bin/git/git-record13
-rwxr-xr-xgit/.bin/git/git-root9
-rw-r--r--git/.config/git/config73
-rw-r--r--git/.config/git/ignore1
-rw-r--r--git/.config/sh/rc.d/git1
10 files changed, 161 insertions, 0 deletions
diff --git a/git/.bin/git/git-amend b/git/.bin/git/git-amend
new file mode 100755
index 0000000..3b937ec
--- /dev/null
+++ b/git/.bin/git/git-amend
@@ -0,0 +1,13 @@
+#!/bin/sh
+set -eu
+
+if [ -e "$(git root)/.git/branchless" ]; then
+ exec git branchless amend "$@"
+else
+ if [ "${1:-}" = "-i" ]; then
+ git add -p
+ else
+ git add -u
+ fi
+ git commit --amend
+fi
diff --git a/git/.bin/git/git-blame-stats b/git/.bin/git/git-blame-stats
new file mode 100755
index 0000000..320d755
--- /dev/null
+++ b/git/.bin/git/git-blame-stats
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use Getopt::Long;
+use POSIX qw(ceil);
+use strict;
+Getopt::Long::Configure(qw(bundling));
+my %authors;
+my $total;
+my $files;
+my $rev = shift(@ARGV) || "HEAD";
+
+foreach my $file (`git ls-tree --name-only -r $rev`) {
+ chomp($file);
+ print STDERR "Processing $file\n";
+ foreach my $line (`git blame -M -w $rev -- "$file"`) {
+ chomp($line);
+ if (substr($line, 0, 1) eq "^") {
+ ++$authors{"*initial checkin"};
+ } else {
+ $line =~ s[^.*?\((.*?)\s*\d{4}-\d{2}-\d{2}.*][$1];
+ ++$authors{$line};
+ }
+ ++$total;
+ }
+}
+
+print "Total lines: $total\n";
+my $i = 0;
+my $author_ind = ceil(log(scalar(keys %authors)) / log(10));
+my $lines_ind = ceil(log($total) / log(10));
+foreach my $author (sort { $authors{$b} <=> $authors{$a} } keys %authors) {
+ printf "%${author_ind}s %${lines_ind}u %5.2f%% %s\n",
+ sprintf("#%u", ++$i),
+ $authors{$author},
+ $authors{$author} * 100 / $total,
+ $author;
+}
diff --git a/git/.bin/git/git-default-branch b/git/.bin/git/git-default-branch
new file mode 100755
index 0000000..90e225f
--- /dev/null
+++ b/git/.bin/git/git-default-branch
@@ -0,0 +1,4 @@
+#!/bin/sh
+set -eu
+
+git symbolic-ref refs/remotes/origin/HEAD | sed 's/.*\///'
diff --git a/git/.bin/git/git-file-size b/git/.bin/git/git-file-size
new file mode 100755
index 0000000..0e7d00d
--- /dev/null
+++ b/git/.bin/git/git-file-size
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -eu
+set -o pipefail
+
+git ls-files -z | xargs -0 du -b | sum
diff --git a/git/.bin/git/git-pr b/git/.bin/git/git-pr
new file mode 100755
index 0000000..61346bc
--- /dev/null
+++ b/git/.bin/git/git-pr
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+pr_num="$1"
+upstream="${2-origin}"
+git fetch "$upstream" "pull/${pr_num}/head:pull-${pr_num}"
diff --git a/git/.bin/git/git-record b/git/.bin/git/git-record
new file mode 100755
index 0000000..eaa36c9
--- /dev/null
+++ b/git/.bin/git/git-record
@@ -0,0 +1,13 @@
+#!/bin/sh
+set -eu
+
+if [ -e "$(git root)/.git/branchless" ]; then
+ exec git branchless record "$@"
+else
+ if [ "${1:-}" = "-i" ]; then
+ git add -p
+ else
+ git add -u
+ fi
+ git commit
+fi
diff --git a/git/.bin/git/git-root b/git/.bin/git/git-root
new file mode 100755
index 0000000..96fb395
--- /dev/null
+++ b/git/.bin/git/git-root
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -eu
+
+root="$(git rev-parse --show-superproject-working-tree 2>/dev/null)"
+if [ -n "$root" ]; then
+ echo "$root"
+else
+ git rev-parse --show-toplevel
+fi
diff --git a/git/.config/git/config b/git/.config/git/config
new file mode 100644
index 0000000..54b054e
--- /dev/null
+++ b/git/.config/git/config
@@ -0,0 +1,73 @@
+[user]
+ email = doy@tozt.net
+ name = Jesse Luehrs
+[alias]
+ aliases = !git config --get-regexp 'alias.*' | perl -nle'/^alias\\.([^ ]*) (.*)/ && printf \"%-15s = %s\\n\", $1, $2'
+ alias = "!f() { local name=$1; shift; git config --global alias.$name \"$*\"; }; f"
+ amend = !~/.bin/git/git-amend
+ bda = "!f() { git branch --merged $(git default-branch) --format='%(refname:short)' | grep -v \"^$(git default-branch)$\" | xargs -r git branch -d; }; f"
+ blame-stats = !~/.bin/git/git-blame-stats
+ br = for-each-ref --sort=committerdate refs/heads/ --format='%(align:30,left)%(HEAD) %(refname:short)%(end) %(color:magenta)(%(committerdate:relative))'
+ cc = cherry-pick
+ co = checkout
+ default-branch = !~/.bin/git/git-default-branch
+ diff-branch = "!f() { local branch=${1:-HEAD}; git diff $(git merge-base $(git default-branch) $branch) $branch; }; f"
+ ff = merge --ff-only
+ file-size = !~/.bin/git/git-file-size
+ fixup = "!f() { git record --fixup \"$@\"; }; f"
+ gc-aggressive = "!f() { git repack -Abd --window=250 --depth=250 --window-memory=1g && git prune --expire \"1 day ago\" && rm -f .git/gc.log && git gc; }; f"
+ lg = log --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %C(bold blue)%aN%Creset %C(magenta)(%ar)%Creset%n%s%n' --abbrev-commit --date=relative --stat=72
+ pr = !~/.bin/git/git-pr
+ record = !~/.bin/git/git-record
+ refix = "!f() { env EDITOR=true git rebase -i \"$@\"; }; f"
+ re = rebase -i @{u}
+ ri = rebase -i
+ root = !~/.bin/git/git-root
+ rv = checkout -p
+ st = status -sb
+ start = "!f() { git commit --allow-empty -m 'initial commit' && git add . && git commit -m 'project skeleton'; }; f"
+ track = "!f() { local name=$(git name-rev --name-only --exclude='branchless/*' @); git branch --set-upstream-to=origin/$name $name; }; f"
+ git = !git
+[github]
+ user = doy
+[core]
+ pager = delta
+[merge]
+ conflictstyle = zdiff3
+[rebase]
+ autosquash = true
+ autostash = true
+[help]
+ autocorrect = 5
+[diff]
+ mnemonicprefix = true
+ algorithm = histogram
+[advice]
+ pushUpdateRejected = false
+ statusHints = false
+ commitBeforeMerge = false
+ resolveConflict = false
+ detachedHead = false
+[rerere]
+ enabled = true
+[fetch]
+ prune = true
+[pull]
+ rebase = true
+[include]
+ path = config.private
+[interactive]
+ diffFilter = delta --color-only
+[delta]
+ navigate = true
+[init]
+ defaultBranch = main
+[submodule]
+ recurse = true
+[push]
+ autosetupremote = true
+ recurseSubmodules = check
+[commit]
+ verbose = true
+
+; vim:ft=gitconfig:
diff --git a/git/.config/git/ignore b/git/.config/git/ignore
new file mode 100644
index 0000000..dd33554
--- /dev/null
+++ b/git/.config/git/ignore
@@ -0,0 +1 @@
+.obsidian
diff --git a/git/.config/sh/rc.d/git b/git/.config/sh/rc.d/git
new file mode 100644
index 0000000..52d6b5e
--- /dev/null
+++ b/git/.config/sh/rc.d/git
@@ -0,0 +1 @@
+alias cdu="cd \"\$(git root)\""