2017-11-03 08:34:41 +01:00
|
|
|
declare-option -docstring "name of the client in which documentation is to be displayed" \
|
2017-05-16 13:35:43 +02:00
|
|
|
str docsclient
|
2013-03-29 19:37:35 +01:00
|
|
|
|
2023-09-16 15:54:26 +02:00
|
|
|
declare-option -docstring "git diff added character" \
|
|
|
|
str git_diff_add_char "▏"
|
2023-09-08 01:01:38 +02:00
|
|
|
|
2023-09-16 15:54:26 +02:00
|
|
|
declare-option -docstring "git diff modified character" \
|
|
|
|
str git_diff_mod_char "▏"
|
2023-09-08 01:01:38 +02:00
|
|
|
|
2023-09-16 15:54:26 +02:00
|
|
|
declare-option -docstring "git diff deleted character" \
|
|
|
|
str git_diff_del_char "_"
|
2023-09-08 01:01:38 +02:00
|
|
|
|
2023-09-16 15:54:26 +02:00
|
|
|
declare-option -docstring "git diff top deleted character" \
|
|
|
|
str git_diff_top_char "‾"
|
2023-09-08 01:01:38 +02:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group git-log-highlight global WinSetOption filetype=git-log %{
|
2022-01-24 17:09:44 +01:00
|
|
|
require-module diff
|
2018-08-08 19:11:55 +02:00
|
|
|
add-highlighter window/git-log group
|
2020-02-06 04:59:59 +01:00
|
|
|
add-highlighter window/git-log/ regex '^([*|\\ /_.-])*' 0:keyword
|
|
|
|
add-highlighter window/git-log/ regex '^( ?[*|\\ /_.-])*\h{,3}(commit )?(\b[0-9a-f]{4,40}\b)' 2:keyword 3:comment
|
|
|
|
add-highlighter window/git-log/ regex '^( ?[*|\\ /_.-])*\h{,3}([a-zA-Z_-]+:) (.*?)$' 2:variable 3:value
|
2018-07-07 01:51:18 +02:00
|
|
|
add-highlighter window/git-log/ ref diff # highlight potential diffs from the -p option
|
2018-11-28 10:39:18 +01:00
|
|
|
|
2018-12-11 00:11:35 +01:00
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-log }
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
2013-03-29 19:37:35 +01:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group git-status-highlight global WinSetOption filetype=git-status %{
|
2022-01-24 17:09:44 +01:00
|
|
|
require-module diff
|
2018-08-08 19:11:55 +02:00
|
|
|
add-highlighter window/git-status group
|
2020-01-29 18:19:23 +01:00
|
|
|
add-highlighter window/git-status/ regex '^## ' 0:comment
|
|
|
|
add-highlighter window/git-status/ regex '^## (\S*[^\s\.@])' 1:green
|
|
|
|
add-highlighter window/git-status/ regex '^## (\S*[^\s\.@])(\.\.+)(\S*[^\s\.@])' 1:green 2:comment 3:red
|
|
|
|
add-highlighter window/git-status/ regex '^(##) (No commits yet on) (\S*[^\s\.@])' 1:comment 2:Default 3:green
|
|
|
|
add-highlighter window/git-status/ regex '^## \S+ \[[^\n]*ahead (\d+)[^\n]*\]' 1:green
|
|
|
|
add-highlighter window/git-status/ regex '^## \S+ \[[^\n]*behind (\d+)[^\n]*\]' 1:red
|
|
|
|
add-highlighter window/git-status/ regex '^(?:([Aa])|([Cc])|([Dd!?])|([MUmu])|([Rr])|([Tt]))[ !\?ACDMRTUacdmrtu]\h' 1:green 2:blue 3:red 4:yellow 5:cyan 6:cyan
|
|
|
|
add-highlighter window/git-status/ regex '^[ !\?ACDMRTUacdmrtu](?:([Aa])|([Cc])|([Dd!?])|([MUmu])|([Rr])|([Tt]))\h' 1:green 2:blue 3:red 4:yellow 5:cyan 6:cyan
|
|
|
|
add-highlighter window/git-status/ regex '^R[ !\?ACDMRTUacdmrtu] [^\n]+( -> )' 1:cyan
|
2018-07-07 01:51:18 +02:00
|
|
|
add-highlighter window/git-status/ regex '^\h+(?:((?:both )?modified:)|(added:|new file:)|(deleted(?: by \w+)?:)|(renamed:)|(copied:))(?:.*?)$' 1:yellow 2:green 3:red 4:cyan 5:blue 6:magenta
|
2018-11-28 10:39:18 +01:00
|
|
|
|
2018-12-11 00:11:35 +01:00
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-status }
|
2014-04-23 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
2022-06-17 09:08:46 +02:00
|
|
|
hook -group git-show-branch-highlight global WinSetOption filetype=git-show-branch %{
|
|
|
|
require-module diff
|
|
|
|
add-highlighter window/git-show-branch group
|
|
|
|
add-highlighter window/git-show-branch/ regex '(\*)|(\+)|(!)' 1:red 2:green 3:green
|
|
|
|
add-highlighter window/git-show-branch/ regex '(!\D+\{0\}\])|(!\D+\{1\}\])|(!\D+\{2\}\])|(!\D+\{3\}\])' 1:red 2:green 3:yellow 4:blue
|
|
|
|
add-highlighter window/git-show-branch/ regex '(\B\+\D+\{0\}\])|(\B\+\D+\{1\}\])|(\B\+\D+\{2\}\])|(\B\+\D+\{3\}\])|(\B\+\D+\{1\}\^\])' 1:red 2:green 3:yellow 4:blue 5:magenta
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/git-show-branch}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
declare-option -hidden line-specs git_blame_flags
|
|
|
|
declare-option -hidden line-specs git_diff_flags
|
2019-11-13 16:52:29 +01:00
|
|
|
declare-option -hidden int-list git_hunk_list
|
2013-04-22 19:35:22 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -params 1.. \
|
2020-02-03 20:53:28 +01:00
|
|
|
-docstring %{
|
|
|
|
git [<arguments>]: git wrapping helper
|
|
|
|
All the optional arguments are forwarded to the git utility
|
|
|
|
Available commands:
|
|
|
|
add
|
2023-10-22 22:03:32 +02:00
|
|
|
apply (alias for "patch git apply")
|
2024-01-21 11:49:47 +01:00
|
|
|
blame (toggle blame annotations)
|
2020-02-03 20:53:28 +01:00
|
|
|
checkout
|
2023-11-18 09:12:05 +01:00
|
|
|
commit
|
2020-02-03 20:53:28 +01:00
|
|
|
diff
|
2023-11-18 09:12:05 +01:00
|
|
|
edit
|
|
|
|
grep
|
2020-02-03 20:53:28 +01:00
|
|
|
hide-diff
|
|
|
|
init
|
|
|
|
log
|
|
|
|
next-hunk
|
2023-10-04 01:52:15 +02:00
|
|
|
prev-hunk
|
2023-11-18 09:12:05 +01:00
|
|
|
reset
|
|
|
|
rm
|
2020-02-03 20:53:28 +01:00
|
|
|
show
|
2022-06-17 09:08:46 +02:00
|
|
|
show-branch
|
2020-02-03 20:53:28 +01:00
|
|
|
show-diff
|
|
|
|
status
|
|
|
|
update-diff
|
|
|
|
} -shell-script-candidates %{
|
2018-04-21 04:43:59 +02:00
|
|
|
if [ $kak_token_to_complete -eq 0 ]; then
|
2023-11-18 09:12:05 +01:00
|
|
|
printf %s\\n \
|
|
|
|
apply \
|
|
|
|
blame \
|
|
|
|
checkout \
|
|
|
|
commit \
|
|
|
|
diff \
|
|
|
|
edit \
|
|
|
|
grep \
|
|
|
|
hide-diff \
|
|
|
|
init \
|
|
|
|
log \
|
|
|
|
next-hunk \
|
|
|
|
prev-hunk \
|
|
|
|
reset \
|
|
|
|
rm \
|
|
|
|
show \
|
|
|
|
show-branch \
|
|
|
|
show-diff \
|
|
|
|
status \
|
|
|
|
update-diff \
|
|
|
|
;
|
2018-04-21 04:43:59 +02:00
|
|
|
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 ;;
|
2024-01-25 00:51:41 +01:00
|
|
|
apply) printf -- "--reverse\n--cached\n--index\n--3way\n" ;;
|
2023-11-03 16:27:00 +01:00
|
|
|
grep|edit) git ls-files -c --recurse-submodules ;;
|
2018-04-21 04:43:59 +02:00
|
|
|
esac
|
|
|
|
fi
|
2014-08-14 20:42:24 +02:00
|
|
|
} \
|
2018-05-06 23:29:52 +02:00
|
|
|
git %{ evaluate-commands %sh{
|
2018-08-12 08:41:45 +02:00
|
|
|
cd_bufdir() {
|
|
|
|
dirname_buffer="${kak_buffile%/*}"
|
|
|
|
cd "${dirname_buffer}" 2>/dev/null || {
|
2019-11-14 08:32:55 +01:00
|
|
|
printf 'fail Unable to change the current working directory to: %s\n' "${dirname_buffer}"
|
2018-08-12 08:41:45 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
show_git_cmd_output() {
|
|
|
|
local filetype
|
2021-07-13 22:48:56 +02:00
|
|
|
local map_diff_goto_source
|
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
case "$1" in
|
2021-07-13 22:48:56 +02:00
|
|
|
diff) map_diff_goto_source=true; filetype=diff ;;
|
|
|
|
show) map_diff_goto_source=true; filetype=git-log ;;
|
2022-06-17 09:08:46 +02:00
|
|
|
show-branch) filetype=git-show-branch ;;
|
2023-09-12 10:15:33 +02:00
|
|
|
log) map_diff_goto_source=true; filetype=git-log ;;
|
2014-04-23 23:21:40 +02:00
|
|
|
status) filetype=git-status ;;
|
2020-09-01 21:38:04 +02:00
|
|
|
*) return 1 ;;
|
2013-04-22 19:35:22 +02:00
|
|
|
esac
|
2017-06-09 13:05:31 +02:00
|
|
|
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-git.XXXXXXXX)/fifo
|
2014-05-06 20:39:24 +02:00
|
|
|
mkfifo ${output}
|
2019-06-10 18:00:11 +02:00
|
|
|
( git "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
|
2014-05-06 20:39:24 +02:00
|
|
|
|
2021-07-13 22:48:56 +02:00
|
|
|
# We need to unmap in case an existing buffer changes type,
|
|
|
|
# for example if the user runs "git show" and "git status".
|
|
|
|
map_diff_goto_source=$([ -n "${map_diff_goto_source}" ] \
|
2022-07-30 22:28:02 +02:00
|
|
|
&& printf %s "map buffer normal <ret> :git-diff-goto-source<ret> -docstring 'Jump to source from git diff'" \
|
|
|
|
|| printf %s "unmap buffer normal <ret> :git-diff-goto-source<ret>")
|
2021-07-13 22:48:56 +02:00
|
|
|
|
2018-04-27 11:44:21 +02:00
|
|
|
printf %s "evaluate-commands -try-client '$kak_opt_docsclient' %{
|
2014-05-06 20:39:24 +02:00
|
|
|
edit! -fifo ${output} *git*
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype '${filetype}'
|
2018-08-19 00:04:31 +02:00
|
|
|
hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
2021-07-13 22:48:56 +02:00
|
|
|
${map_diff_goto_source}
|
2014-05-06 20:39:24 +02:00
|
|
|
}"
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
|
|
|
|
2024-01-21 11:49:47 +01:00
|
|
|
hide_blame() {
|
|
|
|
printf %s "
|
|
|
|
set-option buffer=$kak_bufname git_blame_flags $kak_timestamp
|
|
|
|
remove-highlighter window/git-blame
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
run_git_blame() {
|
2024-01-22 15:39:50 +01:00
|
|
|
echo >${kak_command_fifo} "try %{
|
|
|
|
add-highlighter window/git-blame flag-lines Information git_blame_flags
|
|
|
|
echo -to-file ${kak_response_fifo}
|
|
|
|
} catch %{
|
|
|
|
echo -to-file ${kak_response_fifo} 'hide_blame; exit'
|
|
|
|
}"
|
|
|
|
eval $(cat ${kak_response_fifo})
|
2013-04-22 19:35:22 +02:00
|
|
|
(
|
2019-09-22 01:29:19 +02:00
|
|
|
cd_bufdir
|
2017-11-03 09:09:45 +01:00
|
|
|
printf %s "evaluate-commands -client '$kak_client' %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer=$kak_bufname git_blame_flags '$kak_timestamp'
|
2014-03-02 03:05:38 +01:00
|
|
|
}" | kak -p ${kak_session}
|
2023-11-12 10:41:37 +01:00
|
|
|
git blame "$@" --incremental ${kak_buffile} | perl -wne '
|
|
|
|
use POSIX qw(strftime);
|
|
|
|
sub send_flags {
|
|
|
|
my $flush = shift;
|
|
|
|
if (not defined $line) { return; }
|
2024-01-07 20:47:48 +01:00
|
|
|
my $text = substr($sha,0,7) . " " . $dates{$sha} . " " . $authors{$sha};
|
2023-11-12 10:41:37 +01:00
|
|
|
$text =~ s/~/~~/g;
|
|
|
|
for ( my $i = 0; $i < $count; $i++ ) {
|
|
|
|
$flags .= " %~" . ($line+$i) . "|$text~";
|
2022-01-28 00:06:00 +01:00
|
|
|
}
|
2023-11-12 10:41:37 +01:00
|
|
|
$now = time();
|
2022-01-28 00:06:00 +01:00
|
|
|
# Send roughly one update per second, to avoid creating too many kak processes.
|
2023-11-12 10:41:37 +01:00
|
|
|
if (!$flush && defined $last_sent && $now - $last_sent < 1) {
|
2022-01-28 00:06:00 +01:00
|
|
|
return
|
2014-03-25 10:25:37 +01:00
|
|
|
}
|
2023-11-12 10:41:37 +01:00
|
|
|
open CMD, "|-", "kak -p $ENV{kak_session}";
|
|
|
|
print CMD "set-option -add buffer=$ENV{kak_bufname} git_blame_flags $flags";
|
|
|
|
close(CMD);
|
|
|
|
$flags = "";
|
|
|
|
$last_sent = $now;
|
2014-03-25 10:25:37 +01:00
|
|
|
}
|
2023-11-12 10:41:37 +01:00
|
|
|
if (m/^([0-9a-f]+) ([0-9]+) ([0-9]+) ([0-9]+)/) {
|
|
|
|
send_flags(0);
|
|
|
|
$sha = $1;
|
|
|
|
$line = $3;
|
|
|
|
$count = $4;
|
2014-03-25 10:25:37 +01:00
|
|
|
}
|
2023-11-12 10:41:37 +01:00
|
|
|
if (m/^author /) { $authors{$sha} = substr($_,7) }
|
|
|
|
if (m/^author-time ([0-9]*)/) { $dates{$sha} = strftime("%F %T", localtime $1) }
|
2022-01-28 00:06:00 +01:00
|
|
|
END { send_flags(1); }'
|
2014-03-25 10:25:37 +01:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
2013-04-11 23:09:42 +02:00
|
|
|
|
2019-10-09 08:39:58 +02:00
|
|
|
run_git_cmd() {
|
|
|
|
if git "${@}" > /dev/null 2>&1; then
|
|
|
|
printf %s "echo -markup '{Information}git $1 succeeded'"
|
|
|
|
else
|
2019-11-14 08:32:55 +01:00
|
|
|
printf 'fail git %s failed\n' "$1"
|
2019-10-09 08:39:58 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
update_diff() {
|
2019-09-22 01:29:19 +02:00
|
|
|
(
|
|
|
|
cd_bufdir
|
2022-04-12 17:26:38 +02:00
|
|
|
git --no-pager diff --no-ext-diff -U0 "$kak_buffile" | perl -e '
|
2023-09-08 01:01:38 +02:00
|
|
|
use utf8;
|
2018-07-01 02:06:47 +02:00
|
|
|
$flags = $ENV{"kak_timestamp"};
|
2023-09-16 15:54:26 +02:00
|
|
|
$add_char = $ENV{"kak_opt_git_diff_add_char"};
|
|
|
|
$del_char = $ENV{"kak_opt_git_diff_del_char"};
|
|
|
|
$top_char = $ENV{"kak_opt_git_diff_top_char"};
|
|
|
|
$mod_char = $ENV{"kak_opt_git_diff_mod_char"};
|
2018-07-01 02:06:47 +02:00
|
|
|
foreach $line (<STDIN>) {
|
|
|
|
if ($line =~ /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/) {
|
|
|
|
$from_line = $1;
|
|
|
|
$from_count = ($2 eq "" ? 1 : $2);
|
|
|
|
$to_line = $3;
|
|
|
|
$to_count = ($4 eq "" ? 1 : $4);
|
|
|
|
|
|
|
|
if ($from_count == 0 and $to_count > 0) {
|
|
|
|
for $i (0..$to_count - 1) {
|
|
|
|
$line = $to_line + $i;
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $line|\{green\}$add_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($from_count > 0 and $to_count == 0) {
|
|
|
|
if ($to_line == 0) {
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " 1|\{red\}$top_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
} else {
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $to_line|\{red\}$del_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($from_count > 0 and $from_count == $to_count) {
|
|
|
|
for $i (0..$to_count - 1) {
|
|
|
|
$line = $to_line + $i;
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $line|\{blue\}$mod_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($from_count > 0 and $from_count < $to_count) {
|
|
|
|
for $i (0..$from_count - 1) {
|
|
|
|
$line = $to_line + $i;
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $line|\{blue\}$mod_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
for $i ($from_count..$to_count - 1) {
|
|
|
|
$line = $to_line + $i;
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $line|\{green\}$add_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($to_count > 0 and $from_count > $to_count) {
|
|
|
|
for $i (0..$to_count - 2) {
|
|
|
|
$line = $to_line + $i;
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $line|\{blue\}$mod_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
$last = $to_line + $to_count - 1;
|
2023-09-08 01:01:38 +02:00
|
|
|
$flags .= " $last|\{blue+u\}$mod_char";
|
2018-07-01 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-25 10:25:37 +01:00
|
|
|
}
|
2018-07-01 02:06:47 +02:00
|
|
|
print "set-option buffer git_diff_flags $flags"
|
2019-09-15 21:29:33 +02:00
|
|
|
' )
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
2013-04-17 19:15:15 +02:00
|
|
|
|
2019-11-13 16:52:29 +01:00
|
|
|
jump_hunk() {
|
|
|
|
direction=$1
|
|
|
|
set -- ${kak_opt_git_diff_flags}
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
2023-10-04 01:53:20 +02:00
|
|
|
echo "fail 'no git hunks found, try \":git show-diff\" first'"
|
2019-11-13 16:52:29 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update hunk list if required
|
|
|
|
if [ "$kak_timestamp" != "${kak_opt_git_hunk_list%% *}" ]; then
|
|
|
|
hunks=$kak_timestamp
|
|
|
|
|
|
|
|
prev_line="-1"
|
|
|
|
for line in "$@"; do
|
|
|
|
line="${line%%|*}"
|
|
|
|
if [ "$((line - prev_line))" -gt 1 ]; then
|
|
|
|
hunks="$hunks $line"
|
|
|
|
fi
|
|
|
|
prev_line="$line"
|
|
|
|
done
|
|
|
|
echo "set-option buffer git_hunk_list $hunks"
|
2020-03-11 07:56:28 +01:00
|
|
|
hunks=${hunks#* }
|
2019-11-13 16:52:29 +01:00
|
|
|
else
|
|
|
|
hunks=${kak_opt_git_hunk_list#* }
|
|
|
|
fi
|
|
|
|
|
|
|
|
prev_hunk=""
|
|
|
|
next_hunk=""
|
|
|
|
for hunk in ${hunks}; do
|
|
|
|
if [ "$hunk" -lt "$kak_cursor_line" ]; then
|
|
|
|
prev_hunk=$hunk
|
|
|
|
elif [ "$hunk" -gt "$kak_cursor_line" ]; then
|
|
|
|
next_hunk=$hunk
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-08-23 18:55:50 +02:00
|
|
|
wrapped=false
|
2020-03-11 07:56:28 +01:00
|
|
|
if [ "$direction" = "next" ]; then
|
|
|
|
if [ -z "$next_hunk" ]; then
|
|
|
|
next_hunk=${hunks%% *}
|
|
|
|
wrapped=true
|
|
|
|
fi
|
|
|
|
if [ -n "$next_hunk" ]; then
|
|
|
|
echo "select $next_hunk.1,$next_hunk.1"
|
|
|
|
fi
|
|
|
|
elif [ "$direction" = "prev" ]; then
|
|
|
|
if [ -z "$prev_hunk" ]; then
|
|
|
|
wrapped=true
|
|
|
|
prev_hunk=${hunks##* }
|
|
|
|
fi
|
|
|
|
if [ -n "$prev_hunk" ]; then
|
|
|
|
echo "select $prev_hunk.1,$prev_hunk.1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$wrapped" = true ]; then
|
|
|
|
echo "echo -markup '{Information}git hunk search wrapped around buffer'"
|
2019-11-13 16:52:29 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-01-15 20:58:43 +01:00
|
|
|
commit() {
|
2015-01-21 14:43:00 +01:00
|
|
|
# Handle case where message needs not to be edited
|
2018-04-21 04:43:59 +02:00
|
|
|
if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit|--fixup.*|--squash.*"; then
|
2015-01-21 14:43:00 +01:00
|
|
|
if git commit "$@" > /dev/null 2>&1; then
|
2017-07-19 17:18:52 +02:00
|
|
|
echo 'echo -markup "{Information}Commit succeeded"'
|
2015-01-21 14:43:00 +01:00
|
|
|
else
|
2019-11-14 08:32:55 +01:00
|
|
|
echo 'fail Commit failed'
|
2015-01-21 14:43:00 +01:00
|
|
|
fi
|
|
|
|
exit
|
|
|
|
fi <<-EOF
|
|
|
|
$@
|
|
|
|
EOF
|
|
|
|
|
2015-01-15 20:58:43 +01:00
|
|
|
# fails, and generate COMMIT_EDITMSG
|
2016-10-24 21:45:57 +02:00
|
|
|
GIT_EDITOR='' EDITOR='' git commit "$@" > /dev/null 2>&1
|
2015-01-15 20:58:43 +01:00
|
|
|
msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG"
|
2016-05-09 14:52:54 +02:00
|
|
|
printf %s "edit '$msgfile'
|
2018-05-06 23:29:52 +02:00
|
|
|
hook buffer BufWritePost '.*\Q$msgfile\E' %{ evaluate-commands %sh{
|
2018-07-04 11:42:03 +02:00
|
|
|
if git commit -F '$msgfile' --cleanup=strip $* > /dev/null; then
|
2017-11-03 09:09:45 +01:00
|
|
|
printf %s 'evaluate-commands -client $kak_client echo -markup %{{Information}Commit succeeded}; delete-buffer'
|
2015-01-15 20:58:43 +01:00
|
|
|
else
|
2019-11-14 08:32:55 +01:00
|
|
|
printf 'evaluate-commands -client %s fail Commit failed\n' "$kak_client"
|
2015-01-15 20:58:43 +01:00
|
|
|
fi
|
|
|
|
} }"
|
|
|
|
}
|
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
case "$1" in
|
2023-10-22 22:03:32 +02:00
|
|
|
apply)
|
|
|
|
shift
|
|
|
|
enquoted="$(printf '"%s" ' "$@")"
|
|
|
|
echo "require-module patch"
|
|
|
|
echo "patch git apply $enquoted"
|
|
|
|
;;
|
2022-06-17 09:08:46 +02:00
|
|
|
show|show-branch|log|diff|status)
|
2019-10-09 08:39:58 +02:00
|
|
|
show_git_cmd_output "$@"
|
|
|
|
;;
|
|
|
|
blame)
|
|
|
|
shift
|
|
|
|
run_git_blame "$@"
|
|
|
|
;;
|
|
|
|
hide-blame)
|
2024-01-21 11:49:47 +01:00
|
|
|
hide_blame
|
2015-05-10 18:20:42 +02:00
|
|
|
;;
|
2019-10-09 08:39:58 +02:00
|
|
|
show-diff)
|
|
|
|
echo 'try %{ add-highlighter window/git-diff flag-lines Default git_diff_flags }'
|
|
|
|
update_diff
|
|
|
|
;;
|
|
|
|
hide-diff)
|
|
|
|
echo 'try %{ remove-highlighter window/git-diff }'
|
|
|
|
;;
|
|
|
|
update-diff) update_diff ;;
|
2019-11-13 16:52:29 +01:00
|
|
|
next-hunk) jump_hunk next ;;
|
|
|
|
prev-hunk) jump_hunk prev ;;
|
2019-10-09 08:39:58 +02:00
|
|
|
commit)
|
|
|
|
shift
|
|
|
|
commit "$@"
|
|
|
|
;;
|
|
|
|
init)
|
|
|
|
shift
|
|
|
|
git init "$@" > /dev/null 2>&1
|
|
|
|
;;
|
|
|
|
add|rm)
|
|
|
|
cmd="$1"
|
|
|
|
shift
|
|
|
|
run_git_cmd $cmd "${@:-${kak_buffile}}"
|
|
|
|
;;
|
|
|
|
reset|checkout)
|
|
|
|
run_git_cmd "$@"
|
|
|
|
;;
|
2023-09-10 11:30:05 +02:00
|
|
|
grep)
|
|
|
|
shift
|
|
|
|
enquoted="$(printf '"%s" ' "$@")"
|
|
|
|
printf %s "try %{
|
2023-09-18 10:18:32 +02:00
|
|
|
set-option current grepcmd 'git grep -n --column'
|
2023-09-10 11:30:05 +02:00
|
|
|
grep $enquoted
|
|
|
|
set-option current grepcmd '$kak_opt_grepcmd'
|
|
|
|
}"
|
|
|
|
;;
|
2023-11-03 16:27:00 +01:00
|
|
|
edit)
|
|
|
|
shift
|
|
|
|
enquoted="$(printf '"%s" ' "$@")"
|
|
|
|
printf %s "edit -existing -- $enquoted"
|
|
|
|
;;
|
2019-10-09 08:39:58 +02:00
|
|
|
*)
|
2019-11-14 08:32:55 +01:00
|
|
|
printf "fail unknown git command '%s'\n" "$1"
|
2019-10-09 08:39:58 +02:00
|
|
|
exit
|
|
|
|
;;
|
2013-04-22 19:35:22 +02:00
|
|
|
esac
|
2013-04-11 23:09:42 +02:00
|
|
|
}}
|
2021-07-13 22:48:56 +02:00
|
|
|
|
|
|
|
# Works within :git diff and :git show
|
|
|
|
define-command git-diff-goto-source \
|
|
|
|
-docstring 'Navigate to source by pressing the enter key in hunks when git diff is displayed. Works within :git diff and :git show' %{
|
2022-01-24 18:10:39 +01:00
|
|
|
require-module diff
|
|
|
|
diff-jump %sh{ git rev-parse --show-toplevel }
|
2021-07-13 22:48:56 +02:00
|
|
|
}
|