From 3204fa60f33463da57a64c35a9dc5f036d214b96 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 5 Jun 2026 16:21:43 +0900 Subject: [PATCH] home/git: add `addr` command --- home/programs/git/default.nix | 5 +++++ home/programs/git/scripts/git-addr.sh | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 home/programs/git/scripts/git-addr.sh diff --git a/home/programs/git/default.nix b/home/programs/git/default.nix index 511c388..7b6e534 100644 --- a/home/programs/git/default.nix +++ b/home/programs/git/default.nix @@ -360,6 +360,11 @@ lib.mkIf cfg.enable { runtimeInputs = with pkgs; [ cfg.package gnused gnugrep gawk uutils-coreutils-noprefix ]; text = lib.fileContents ./scripts/git-author-lines.sh; }) + (pkgs.writeShellApplication { + name = "git-addr"; + runtimeInputs = with pkgs; [ cfg.package ]; + text = lib.fileContents ./scripts/git-addr.sh; + }) (pkgs.writeShellApplication { name = "git-all-commits"; runtimeInputs = with pkgs; [ cfg.package gnugrep gawk findutils uutils-coreutils-noprefix ]; diff --git a/home/programs/git/scripts/git-addr.sh b/home/programs/git/scripts/git-addr.sh new file mode 100644 index 0000000..a7ce78b --- /dev/null +++ b/home/programs/git/scripts/git-addr.sh @@ -0,0 +1,19 @@ +GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" + +if [ "$GIT_ROOT_DIR" = "" ]; then + echo "Not a git repository" + exit 1 +fi + +# Transform all file args to prepend the git root dir +declare -a FINAL_ARGS + +for i in "$@"; do + if [ -f "$GIT_ROOT_DIR/$i" ]; then + FINAL_ARGS+=("$GIT_ROOT_DIR/$i") + else + FINAL_ARGS+=("$i") + fi +done + +exec git add "${FINAL_ARGS[@]}"