commit 1a2b09577cad5e4367f1cec06accfc0316c84a90 parent eb56addd4b9de5473342ecbda72e2a2709b1e4dc Author: gearsix <gearsix@tuta.io> Date: Tue, 7 Mar 2023 11:45:55 +0000 git-pradd: new script :) Diffstat:
A | src/posix/git-pradd.sh | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 54 insertions(+), 0 deletions(-)
diff --git a/src/posix/git-pradd.sh b/src/posix/git-pradd.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env sh +# DESCRIPTION: 'git diff', prompt y/n if 'git add' +# ARGUMENTS: git-pradd file1 file2 file3 ... +# DEPENDENCIES: git + +if [ "$1" = "-h" ] || [ "$1" = "--help" ] +then + echo "usage: git-pradd FILE..." + echo "" + echo "Preview the 'git diff' of all specified paths (FILE...)" + echo "and prompt y/n if 'git add' should be run on the file." + echo "If no FILE... targets are provided, all un-added files" + echo "will be used" + exit +fi + +pradd() { + git diff "$dir/$f" + + yn="" + while [ "$yn" = "" ]; do + printf "git add '%s' (y/n)? " "$f" + read -r yn + if [ "$yn" = "y" ] + then git add "$f" + elif [ "$yn" != "n" ] + then yn=""; fi + done +} + +dir="." +if [ ! "$(git rev-parse --show-toplevel)" ] +then + echo "'git rev-parse --show-toplevel' failed to return repo root dir at '$(pwd)'" + exit 1 +else + dir="$(pwd)" +fi + +n=0 +for f in "$@" +do + n++ + pradd "$dir/$f" +done + +if [ $n -eq 0 ] +then + for f in $(git ls-files -m) + do + pradd "$f" + done +fi +