-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.kak
72 lines (63 loc) · 2.85 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
declare-option -docstring "current branch being listed" str gitbranch
declare-option -docstring "face for the active line" str git_list_active_face "rgb:FF805C+b"
declare-option -docstring "face for inactive file names" str git_list_file_face "rgb:78C29E"
declare-option -docstring "face for inactive path preceding file name" str git_list_path_face "rgb:547980"
declare-option -hidden int git_current_line 0
hook -group grep-highlight global WinSetOption filetype=git-tree %{
add-highlighter window/git-tree group
add-highlighter window/git-tree/inactive regex '(?S)^(.+/)?([^/]+)$' \
%sh{echo "1:${kak_opt_git_list_path_face}"} %sh{echo "2:${kak_opt_git_list_file_face}"}
add-highlighter window/git-tree/active line %{%opt{git_current_line}} \
%sh{echo "$kak_opt_git_list_active_face"}
}
hook global WinSetOption filetype=git-tree %{
hook buffer -group git-hooks NormalKey <ret> git-list-jump
}
define-command git-show-branch-file -params 0..2 -docstring %{
git-show-branch-file [file=<current buffer>] [branch=master]
open a scratch buffer for file on branch
if only one argument is given, it is assumed
to be on branch master
} %{
evaluate-commands %sh{
tmp=${TMPDIR:-/tmp}
file=${1:-${kak_bufname}}
branch=${2:-master}
fifo=$(mktemp -d "${tmp}/$(echo ${file}.${branch} | tr / _).XXXXXXXX")/fifo
mkfifo ${fifo}
(git show ${branch}:${file} > ${fifo} 2>&1) > /dev/null 2>&1 < /dev/null &
printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${fifo} ${branch}:${file}
hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${fifo}) } }
}"
}
}
define-command git-list-branch-files -params 0..1 -docstring %{
git-list-branch-files [branch=master]
open a scratch buffer which lists all files in a branch
} %{
evaluate-commands %sh{
tmp=${TMPDIR:-/tmp}
fifo=$(mktemp -d "${tmp}/lstree.$(echo ${1:-master} | tr / _).XXXXXXXX")/fifo
mkfifo ${fifo}
(git ls-tree -r --name-only ${1:-master} > ${fifo} 2>&1) > /dev/null 2>&1 < /dev/null &
printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${fifo} *${1:-master}*
set-option buffer filetype git-tree
set-option buffer git_current_line 0
hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${fifo}) } }
}"
}
}
define-command -hidden git-list-jump %{
evaluate-commands %{
try %{
execute-keys "<a-x>H"
set-option buffer git_current_line %val{cursor_line}
evaluate-commands -try-client %opt{toolsclient} %sh{
branch=$(echo $kak_bufname | tr -d "*")
echo "git-show-branch-file $kak_reg_dot $branch"
}
}
}
}