2022-02-11 10:45:12 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
# Create a commit or stage files via fzf selection
|
|
|
|
|
|
|
|
fzfpipe() {
|
|
|
|
# Take nul-separated input from git-status short/porcelain
|
|
|
|
# and return a newline-separated list of selected files
|
|
|
|
cut -z -c2- |
|
|
|
|
git fzf-diff --read0 -d' ' --nth=2.. --bind='alt-enter:execute(nvim {2..})' \
|
|
|
|
--preview="test {1} != \? && git diff --color HEAD -U5 -- {2..} | $(git config interactive.diffFilter) || find {2..} -type f | xargs -I% diff --recursive --color=always -u /dev/null %" |
|
|
|
|
cut -c3-
|
|
|
|
}
|
|
|
|
|
2022-03-06 21:04:22 +00:00
|
|
|
test $(git ls-tree HEAD . | wc -l) -gt 1 && wd=$PWD
|
2022-02-11 10:45:12 +00:00
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
2022-03-06 21:04:22 +00:00
|
|
|
prefix="/tmp/git/fuzz"
|
|
|
|
mkdir -p "$prefix"
|
2022-02-11 10:45:12 +00:00
|
|
|
case "$1" in
|
|
|
|
(add) shift
|
2022-03-06 21:04:22 +00:00
|
|
|
git status -z --porcelain --no-renames --untracked-files=all $wd |
|
2022-02-11 10:45:12 +00:00
|
|
|
grep -zv '^\\w ' | fzfpipe |
|
|
|
|
git -c advice.addEmptyPathspec=false add --verbose --pathspec-from-file=- "$@";;
|
2022-03-06 21:04:22 +00:00
|
|
|
(*) git status -z --porcelain --no-renames $wd |
|
|
|
|
sed -z 's/^\\(\\w\\) / \\1/' | fzfpipe >"$prefix/files"
|
|
|
|
git -c advice.addEmptyPathspec=false add --intent-to-add --pathspec-from-file="$prefix/files"
|
|
|
|
git commit -v --only --pathspec-from-file="$prefix/files" "$@";;
|
2022-02-11 10:45:12 +00:00
|
|
|
esac
|