From 286dab11d4571e9b63ff56c270d42dc6b126a0d0 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 22 Oct 2023 22:03:32 +0200 Subject: [PATCH] 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. --- rc/tools/git.kak | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rc/tools/git.kak b/rc/tools/git.kak index 8b26cd4c..d84d90b7 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -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 "$@" ;;