rc tools git: "git apply" to apply selections in diffs

This adds a somewhat discoverable frontend for common uses of the
patch command.

Here are some frequently used commands

	# apply selected changes
	git apply 
	# revert selected changes
	git apply -R
	# stage selected changes
	git apply --cached
	# unstage selected changes
	git apply --cached -R
	# apply selected changes and stage them
	git apply --index

For everyday use that's a lot of typing so I recommend adding mappings.
This commit is contained in:
Johannes Altmanninger 2023-10-22 22:03:32 +02:00
parent 8c0424b521
commit 286dab11d4

View File

@ -49,6 +49,7 @@ define-command -params 1.. \
All the optional arguments are forwarded to the git utility
Available commands:
add
apply (alias for "patch git apply")
rm
reset
blame
@ -69,11 +70,12 @@ define-command -params 1.. \
grep
} -shell-script-candidates %{
if [ $kak_token_to_complete -eq 0 ]; then
printf "add\nrm\nreset\nblame\ncommit\ncheckout\ndiff\nhide-blame\nhide-diff\nlog\nnext-hunk\nprev-hunk\nshow\nshow-branch\nshow-diff\ninit\nstatus\nupdate-diff\ngrep\n"
printf "add\napply\nrm\nreset\nblame\ncommit\ncheckout\ndiff\nhide-blame\nhide-diff\nlog\nnext-hunk\nprev-hunk\nshow\nshow-branch\nshow-diff\ninit\nstatus\nupdate-diff\ngrep\n"
else
case "$1" in
commit) printf -- "--amend\n--no-edit\n--all\n--reset-author\n--fixup\n--squash\n"; git ls-files -m ;;
add) git ls-files -dmo --exclude-standard ;;
apply) printf -- "--reverse\n--cached\n--index\n" ;;
rm|grep) git ls-files -c ;;
esac
fi
@ -309,6 +311,12 @@ define-command -params 1.. \
}
case "$1" in
apply)
shift
enquoted="$(printf '"%s" ' "$@")"
echo "require-module patch"
echo "patch git apply $enquoted"
;;
show|show-branch|log|diff|status)
show_git_cmd_output "$@"
;;