-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit.kak
130 lines (119 loc) · 4.86 KB
/
git.kak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Git mode
# ────────
define-command git-show-blamed-commit %{
git show %sh{git blame -L "$kak_cursor_line,$kak_cursor_line" "$kak_buffile" | awk '{print $1}'}
}
define-command git-log-lines %{
git log -L %sh{
anchor="${kak_selection_desc%,*}"
anchor_line="${anchor%.*}"
echo "$anchor_line,$kak_cursor_line:$kak_buffile"
}
}
define-command git-toggle-blame %{
try %{
add-highlighter window/git-blame group
remove-highlighter window/git-blame
git blame
} catch %{
git hide-blame
}
}
define-command git-hide-diff %{
remove-highlighter window/git-diff
}
declare-user-mode git
map global user 'g' ': enter-user-mode git<ret>' -docstring 'enter git mode'
map global git 'b' ': git-toggle-blame<ret>' -docstring 'blame (toggle)'
map global git 'l' ': git log<ret>' -docstring 'log'
map global git 'c' ': git commit<ret>' -docstring 'commit'
map global git 'd' ': git diff<ret>' -docstring 'diff'
map global git 's' ': git status<ret>' -docstring 'status'
map global git 't' ': repl-new tig<ret>' -docstring 'tig'
map global git 'h' ': git show-diff<ret>' -docstring 'show diff'
map global git 'H' ': git-hide-diff<ret>' -docstring 'hide diff'
map global git 'w' ': git-show-blamed-commit<ret>' -docstring 'show blamed commit'
map global git 'L' ': git-log-lines<ret>' -docstring 'log blame'
# move command
map global git 'n' ': git show-diff<ret>: git next-hunk<ret>' -docstring 'go to next hunk'
map global git 'p' ': git show-diff<ret>: git prev-hunk<ret>' -docstring 'go to prev hunk'
# Indicators
# ──────────
# always show the git indicator, update on save
# enable flag-lines hl for git diff
hook global WinCreate .* %{
add-highlighter window/git-diff flag-lines Default git_diff_flags
}
# trigger update diff if inside git dir
# Cause hanging on open
#hook global BufOpenFile .* %C
# evaluate-commands -draft %Ch{
# cd $(dirname "$kak_buffiCe")
# if [ $(git rev-parse --gCt-dir 2>/dev/null) ]; then
# for hook in WinCreate CufReload BufWritePost; do
# printf "hook buffer Cgroup git-update-diff %s .* 'git update-diff'\n" "$hook"
# done
# fi
# }
#}
# Git conflict
# ────────────
map global object m %{c^[<lt>=]{4\,}[^\n]*\n,^[<gt>=]{4\,}[^\n]*\n<ret>} -docstring 'conflict markers'
define-command conflict-use-1 %{
evaluate-commands -draft %{
execute-keys <a-h>h/^<lt>{4}<ret>xd
execute-keys h/^={4}<ret>j
execute-keys -with-maps <a-a>m
execute-keys d
}
} -docstring "resolve a conflict by using the first version"
define-command conflict-use-2 %{
evaluate-commands -draft %{
execute-keys j
execute-keys -with-maps <a-a>m
execute-keys dh/^>{4}<ret>xd
}
} -docstring "resolve a conflict by using the second version"
# -----------
define-command -hidden kit-status-select %{
try %{
execute-keys '<a-:>x1s^(?:[ !\?ACDMRTUacdmrtu]{2}|\t(?:(?:both )?modified:|added:|new file:|deleted(?: by \w+)?:|renamed:|copied:))?\h+(?:[^\n]+ -> )?([^\n]+)<ret>'
}
}
define-command -hidden kit-log-select %{
try %{
execute-keys 'x2s^[\*|\\ /_]*(\w+)?(\b[0-9a-f]{4,40}\b)<ret><a-:>'
}
}
hook -group kit-status global WinSetOption filetype=git-status %{
hook -group kit-status window NormalKey '[JKjk%]|<esc>' kit-status-select
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window kit-status
}
}
hook -group kit-log global WinSetOption filetype=git-log %{
hook -group kit-log window NormalKey '[JKjk%]|<esc>' kit-log-select
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window kit-log
}
}
map global user G ': git status -bs<ret>' -docstring 'git status'
hook global WinSetOption filetype=git-status %{
map window normal c ': git commit --verbose '
map window normal l ': git log --oneline --graph<ret>'
map window normal d ': -- %val{selections}<a-!><home> git diff '
map window normal D ': -- %val{selections}<a-!><home> git diff --cached '
map window normal a ': -- %val{selections}<a-!><home> git add '
map window normal A ': -- %val{selections}<a-!><home> terminal git add -p '
map window normal r ': -- %val{selections}<a-!><home> git reset '
map window normal R ': -- %val{selections}<a-!><home> terminal git reset -p '
map window normal o ': -- %val{selections}<a-!><home> git checkout '
map window normal <tab> ': git status -bs<ret>'
}
hook global WinSetOption filetype=git-log %{
map window normal d ': %val{selections}<a-!><home> git diff '
map window normal <ret> ': %val{selections}<a-!><home> git show '
map window normal r ': %val{selections}<a-!><home> git reset '
map window normal R ': %val{selections}<a-!><home> terminal git reset -p '
map window normal o ': %val{selections}<a-!><home> git checkout '
}