repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix tabline to only consider tabs

5c3b661f16d2f803543119e445fe9fc9ba82bc68

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

- adds svn to vcs tools when looking for a branch name
- fix statusline bug, where global setting was used instead of
  window-local

Changed files (4)

TODO.md

Modified
36 36 - [ ] rewrite bootstripper and java commmands with zig. how to run them? precompile? zig run?
37 37 - [ ] encrypt box key
38 +- [ ] disable syntax highlighting (treesitter) for inactive buffers and dim color
39 40 ## Done

neovim/lua/general_editor_settings.lua

Modified
66 66 vim.opt.showcmd = false
67 67 vim.opt.wildmode = "list:longest"
68 68 -- Set the current working directory to the parent of the active buffer
69 - vim.opt.autochdir = false
69 + vim.opt.autochdir = true
70 70 -- Keep track of file changes outside of vim
71 71 vim.opt.autoread = true
72 72 -- Make backups of all touched files in a special directory

neovim/lua/statusline.lua

Modified
5 5 NvimTree = { "Files", "" },
6 6 packer = { "Plugins", "" },
7 7 help = { "Help", "龎" },
8 + [""] = { "no name", "" },
9 10 local lsp_symbols = { Error = "", Information = "", Warning = "", Hint = "" }
25 26 update_statuslines = function()
26 27 for _, window_number in pairs(vim.api.nvim_list_wins()) do
27 28 if vim.api.nvim_get_current_win() == window_number then
28 - vim.opt.statusline = [[%!v:lua.require'statusline'.render("current")]]
29 - elseif vim.api.nvim_buf_get_name(0) ~= "" then
30 - vim.opt.statusline = [[%!v:lua.require'statusline'.render()]]
29 + vim.wo[window_number].statusline = [[%!v:lua.require'statusline'.render("current")]]
30 + else
31 + vim.wo[window_number].statusline = [[%!v:lua.require'statusline'.render()]]
33 34 end,
34 35 -- update the vcs branch name, if vcs is available
35 36 update_vcs_branch_name = function()
36 37 if not pcall(require, "plenary") then
37 - return ""
38 + return
39 + end
40 + local Job = require("plenary.job")
41 + local git = Job:new({
42 + command = "git",
43 + args = { "branch", "--show-current" },
44 + cwd = vim.fn.expand("%:p:h"), -- parent directory of current buffer
45 + on_exit = function(output)
46 + local result = output:result()[1]
47 + if result then
48 + vcs_branch_name = result
49 + end
50 + end,
51 + })
52 + local svn = Job:new({
53 + command = "svn",
54 + args = { "info" },
55 + cwd = vim.fn.expand("%:p:h"), -- parent directory of current buffer
56 + on_exit = function(output)
57 + local result = output:result()[4] -- Relative URL is on the 4th line
58 + result = result and result:match("Relative URL:%s%^/([%w/]+).*") or nil
59 + if result then
60 + vcs_branch_name = result
61 + end
62 + end,
63 + })
64 + -- simply try all vcs tools at once, and trust that only one returns an answer successfully
65 + local all = { git, svn }
66 + for _, tool in pairs(all) do
67 + tool:start()
39 - require("plenary.job")
40 - :new({
41 - command = "git",
42 - args = { "branch", "--show-current" },
43 - cwd = vim.fn.expand("%:p:h"), -- parent directory of current buffer
44 - on_exit = function(output)
45 - local result = output:result()[1]
46 - if result then
47 - vcs_branch_name = "%#LineNr#%=" .. branch_icon .. " " .. result
48 - else
49 - vcs_branch_name = ""
50 - end
51 - end,
52 - })
53 - :start()
54 69 end,
55 70 -- generate the statusline string
56 71 render = function(active)
57 72 local filetype = vim.bo.filetype
58 73 local special_window = special_windows[filetype]
59 - if active and special_window then
60 - return "%#LineNr#%=" .. special_window[2] .. " " .. special_window[1] .. "%="
74 + if special_window then
75 + return "%#Statusline"
76 + .. (active and "" or "NC")
77 + .. "#%="
78 + .. special_window[2]
79 + .. " "
80 + .. special_window[1]
81 + .. "%="
62 - local edited = vim.bo.mod and "" or ""
63 - local modifiable = vim.bo.modifiable and "" or ""
83 + local edited = vim.bo.mod and "" or " "
84 + local modifiable = vim.bo.modifiable and " " or ""
64 85 local diagnostics = get_lsp_diagnostics_count()
87 + local vcs_info = vcs_branch_name and ("%#LineNr#%=" .. branch_icon .. " " .. vcs_branch_name) or nil
66 89 local statusline = "%#Statusline"
67 90 .. (active and "" or "NC")
68 91 .. "#"
71 94 .. modifiable
72 95 .. " "
73 96 .. "%F" -- full file path
74 - .. (diagnostics ~= "" and "  " .. diagnostics .. "  " or " ")
75 - .. (active and vcs_branch_name or "")
97 + .. (active and (diagnostics ~= "" and "  " .. diagnostics .. "  " or " ") or " ")
98 + .. (active and vcs_info or "")
77 100 return statusline
79 102 -- setup a custom statusline
80 103 setup = function(autocommand)
81 104 autocommand({
82 - update_statusline = "CursorHold,CursorHoldI * lua require'statusline'.update_statuslines()",
83 - update_vcs_branch_name = "BufEnter,BufWinEnter,WinEnter,BufReadPost * lua require'statusline'.update_vcs_branch_name()",
105 + update_statuslines = "BufEnter,WinEnter,BufWinEnter,BufReadPost * lua require'statusline'.update_statuslines()",
106 + -- TODO: is there a more clever way to synchronize getting the branch name and updating the statusline?
107 + update_vcs_branch_name = "BufEnter,WinEnter,BufWinEnter,BufReadPost * lua require'statusline'.update_vcs_branch_name()",

neovim/lua/tabline.lua

Modified
17 17 render = function()
18 18 local buffer_names_to_ignore = {'NvimTree'}
19 19 local tabline = ""
20 - -- FIXME change this to tabpage instead of buf
21 - for _, buffer_number in pairs(vim.api.nvim_list_bufs()) do
22 - if vim.api.nvim_buf_is_valid(buffer_number) and vim.api.nvim_buf_is_loaded(buffer_number) then
20 + for _, current_tab in pairs(vim.api.nvim_list_tabpages()) do
21 + if vim.api.nvim_tabpage_is_valid(current_tab) then
22 + local current_window = vim.api.nvim_tabpage_get_win(current_tab)
23 + if not vim.api.nvim_win_is_valid(current_window) then goto continue end
24 + local current_buffer = vim.api.nvim_win_get_buf(current_window)
25 + if not (vim.api.nvim_buf_is_valid(current_buffer) and vim.api.nvim_buf_is_loaded(current_buffer)) then goto continue end
23 26 local modified = vim.bo.modified and "" or " "
24 27 -- we only care about the last part of the path
25 - local stylish_buffer_name = vim.api.nvim_buf_get_name(buffer_number):match(".-([^\\/]-)$") or ""
26 - if vim.tbl_contains(buffer_names_to_ignore, stylish_buffer_name) or stylish_buffer_name == "" then goto continue end
28 + local current_buffer_name = vim.api.nvim_buf_get_name(current_buffer)
29 + local stylish_buffer_name = current_buffer_name:match(".-([^\\/]-)$") or ""
30 + if vim.tbl_contains(buffer_names_to_ignore, stylish_buffer_name) then goto continue end
27 31 local icon = ""
28 ---FIXME this is the wrong way to handle new empty buffers: how to do it whithout showing tabs for all kinds of auxillary buffers (checkhealt for example)
29 ---[[ if stylish_buffer_name == "" then
30 -stylish_buffer_name = "no name"
31 - icon = "" ]]
32 - if stylish_buffer_name == "cheatsheet" then
32 + if stylish_buffer_name == "" then
33 + stylish_buffer_name = "no name"
34 + icon = ""
35 + elseif stylish_buffer_name == "cheatsheet" then
33 36 icon = ""
34 37 else
35 38 local extension = stylish_buffer_name:match("%w+%.(.+)")
36 39 icon = get_icon(stylish_buffer_name, extension)
38 41 stylish_buffer_name = " " .. stylish_buffer_name .. " "
39 - local is_current_buffer = vim.api.nvim_get_current_buf() == buffer_number
42 + local is_current_buffer = vim.api.nvim_get_current_buf() == current_buffer
40 43 tabline = tabline .. "%#TabLine" ..
41 44 (is_current_buffer and "Sel" or "") .. "#" ..
42 45 " " .. icon .. stylish_buffer_name .. (is_current_buffer and modified or " ")