forked from basbebe/modeline-extras.kak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodeline-extras.kak
195 lines (188 loc) · 7.22 KB
/
modeline-extras.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
provide-module modeline-extras %{
# Nerd Fonts
# https://www.nerdfonts.com/#home
declare-option bool modeline_nerdfont false
# Position in local buffer as Symbol
# enable
define-command modeline-buffer-position-enable \
-docstring 'Enable buffer position option for mode line' %{
declare-option str modeline_buffer_position
hook -group modeline-buffer-position global WinCreate .* %{
hook -group modeline-buffer-position window NormalIdle .* modeline-buffer-position-update
hook -group modeline-buffer-position window InsertIdle .* modeline-buffer-position-update
}
}
# disable
define-command modeline-buffer-position-disable \
-docstring 'Disable buffer position option for mode line' %{
set-option current modeline_buffer_position ''
remove-hooks global modeline-buffer-position
}
# update
define-command -hidden modeline-buffer-position-update %{
set-option window modeline_buffer_position %sh{
position="$(($kak_cursor_line * 100 / $kak_buf_line_count))%"
if [ ${position%%%} -ge 90 ]; then
position="⣀"
elif [ ${position%%%} -ge 75 ] && [ ${position%%%} -lt 90 ]; then
position="⣤"
elif [ ${position%%%} -ge 60 ] && [ ${position%%%} -lt 75 ]; then
position="⠤"
elif [ ${position%%%} -ge 45 ] && [ ${position%%%} -lt 60 ]; then
position="⠶"
elif [ ${position%%%} -ge 30 ] && [ ${position%%%} -lt 45 ]; then
position="⠒"
elif [ ${position%%%} -ge 15 ] && [ ${position%%%} -lt 30 ]; then
position="⠛"
elif [ ${position%%%} -lt 15 ]; then
position="⠉"
fi
printf $position
}
}
# Unicode code point
# https://en.wikipedia.org/wiki/Unicode
# https://en.wikipedia.org/wiki/Code_point
# enable
define-command modeline-codepoint-enable \
-docstring 'Enable codepoint option for mode line' %{
declare-option str modeline_codepoint
hook -group modeline-codepoint global WinCreate .* %{
hook -group modeline-codepoint window NormalIdle .* modeline-codepoint-update
hook -group modeline-codepoint window InsertIdle .* modeline-codepoint-update
}
}
# disable
define-command modeline-codepoint-disable \
-docstring 'Disable codepoint option for mode line' %{
set-option current modeline_codepoint ''
remove-hooks global modeline-codepoint
}
# update
define-command -hidden modeline-codepoint-update %{
set-option window modeline_codepoint 'U+%sh{printf ''%04x'' "$kak_cursor_char_value"}'
}
# Git branch
# enable
define-command modeline-git-branch-enable \
-docstring 'Enable Git branch option for mode line' %{
declare-option str modeline_git_branch
declare-option str modeline_git_dirty
declare-option str modeline_git_staged
hook -group modeline-git-branch global WinDisplay .* modeline-git-branch-update
hook -group modeline-git-branch global FocusIn .* modeline-git-branch-update
}
# disable
define-command modeline-git-branch-disable \
-docstring 'Disable Git branch option for mode line' %{
set-option current modeline_git_branch ''
remove-hooks global modeline-git-branch
}
# update
define-command -hidden modeline-git-branch-update %{
nop %sh{
symbol=''
cd "${kak_buffile%/*}" 2>/dev/null
branch=$(git symbolic-ref --short HEAD 2>/dev/null)
if [ -n "$branch" ]; then
echo "set-option buffer modeline_git_branch $branch" > $kak_command_fifo
if git diff --exit-code --quiet $kak_buffile ; then
echo "set-option buffer modeline_git_dirty ''" > $kak_command_fifo
else
echo "set-option buffer modeline_git_dirty '•'" > $kak_command_fifo
fi
if git diff --cached --exit-code --quiet $kak_buffile ; then
echo "set-option buffer modeline_git_staged ''" > $kak_command_fifo
else
echo "set-option buffer modeline_git_staged '+'" > $kak_command_fifo
fi
fi
}
}
# Better pathh
# enable
define-command modeline-path-name-enable \
-docstring 'Enable path and name option for mode line' %{
declare-option str modeline_file_path
declare-option str modeline_file_name
hook -group modeline-path-name global WinDisplay .* modeline-path-name-update
hook -group modeline-path-name global FocusIn .* modeline-path-name-update
hook -group modeline-path-name global BufWritePost .* modeline-path-name-update
}
# disable
define-command modeline-path-name-disable \
-docstring 'Disable Git branch option for mode line' %{
set-option current modeline_file_path ''
set-option current modeline_file_name ''
remove-hooks global modeline-path-name
}
# update
define-command -hidden modeline-path-name-update %{
set-option buffer modeline_file_path %sh{
# to change how many characters are displayed in the shortened path for each folder, modify the .{0,x} part of the regex, where x is 1 less than the number of characters to display
printf "${kak_buffile%/*}" | perl -pe 's|^$ENV{HOME}|~|'| perl -F/ -lane 'for (@F) { if (length($_) > 5) { $_ = substr($_, 0, 5) . ""; } } print join("/", @F) . "/"'
}
set-option buffer modeline_file_name %sh{
printf "${kak_buffile##*/}"
}
}
# Indentwidth
# enable
define-command modeline-indent-enable \
-docstring 'Enable indent option for mode line' %{
declare-option str modeline_indent
hook -group modeline-indent global WinSetOption indentwidth=.* modeline-indent-update
}
# disable
define-command modeline-indent-disable \
-docstring 'Disable indent option for mode line' %{
set-option current modeline_indent ''
remove-hooks global modeline-indent
}
# update
define-command -hidden modeline-indent-update %{
set-option window modeline_indent %sh{
if [ $kak_opt_indentwidth -eq 0 ]; then
printf ' '
else
printf '%s␣' $kak_opt_indentwidth
fi
}
}
# kak-lsp diagnostics
# https://github.com/kak-lsp/kak-lsp/
define-command modeline-lsp-enable \
-docstring 'Enable lsp option for mode line' %{
declare-option str modeline_lsp_warn
declare-option str modeline_lsp_err
hook -group modeline-lsp global WinSetOption lsp_diagnostic_error_count=.* modeline-lsp-update-err
hook -group modeline-lsp global WinSetOption lsp_diagnostic_warning_count=.* modeline-lsp-update-warn
}
# disable
define-command modeline-lsp-disable \
-docstring 'Disable lsp option for mode line' %{
set-option current modeline_lsp_warn ''
set-option current modeline_lsp_err ''
remove-hooks global modeline-lsp
}
# update lsp diagnostic error
define-command -hidden modeline-lsp-update-err %{
set-option buffer modeline_lsp_err %sh{
symbol_err='W:'
$kak_opt_nerdfont && symbol_err=''
if [ $kak_opt_lsp_diagnostic_error_count -gt 0 ]; then
printf '%s' "$symbol_err" "$kak_opt_lsp_diagnostic_error_count"
fi
}
}
# update lsp diagnostic warning
define-command -hidden modeline-lsp-update-warn %{
set-option buffer modeline_lsp_warn %sh{
symbol_warn='W:'
$kak_opt_nerdfont && symbol_warn=''
if [ $kak_opt_lsp_diagnostic_warning_count -gt 0 ]; then
printf '%s' "$symbol_warn" "$kak_opt_lsp_diagnostic_warning_count"
fi
}
}
}