-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgitcommit.lua
64 lines (47 loc) · 1.48 KB
/
gitcommit.lua
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
local termcode = require('j.utils').termcode
-- Settings
-- No line numbers
vim.opt_local.relativenumber = false
vim.opt_local.number = false
vim.opt_local.signcolumn = 'no'
vim.opt_local.textwidth = 72
vim.opt_local.colorcolumn = { 73, 51 }
-- Autoformatting
-- Enable formatting everywhere, not just comments
vim.opt_local.formatoptions:append 'ca'
vim.opt_local.spell = true
vim.opt_local.iskeyword:remove '-'
-- Plugin settings
vim.b.EditorConfig_disable = 1
-- Mappings
-- Navigate between changed files
vim.keymap.set('n', '{', '?^@@<cr>', { silent = true, buffer = true })
vim.keymap.set('n', '}', '/^@@<cr>', { silent = true, buffer = true })
---@return string | nil
local function parse_issue_key()
local branch = vim.fn.system 'git branch --show-current'
if not branch then
return nil
end
local pattern = '^/(%a+%-%d+).*$'
local branch_without_prefix = branch:gsub('^feature', ''):gsub('^fix', '')
local issue_key = branch_without_prefix:match(pattern)
if not issue_key then
return nil
end
return string.upper(issue_key)
end
local function insert_issue_key()
local lines = vim.fn.getline(1, '$')
local is_empty_file = #lines == 0
local is_empty_line = not is_empty_file and #lines[1] == 0
if is_empty_file or not is_empty_line then
return
end
local issue_key = parse_issue_key()
if issue_key then
vim.api.nvim_buf_set_text(0, 0, 0, 0, 0, { '', 'Ref ' .. issue_key, '' })
end
vim.api.nvim_feedkeys('ggO', 'n', false)
end
insert_issue_key()