doc: add recipe to show current directory in the winbar

This commit is contained in:
Steven Arcangeli 2024-09-11 08:44:45 -07:00
parent 1eb9fb35a4
commit eadc3ed42e

View file

@ -30,6 +30,27 @@ require("oil").setup({
})
```
## Show CWD in the winbar
```lua
-- Declare a global function to retrieve the current directory
function _G.get_oil_winbar()
local dir = require("oil").get_current_dir()
if dir then
return vim.fn.fnamemodify(dir, ":~")
else
-- If there is no current directory (e.g. over ssh), just show the buffer name
return vim.api.nvim_buf_get_name(0)
end
end
require("oil").setup({
win_options = {
winbar = "%!v:lua.get_oil_winbar()",
},
})
```
## Hide gitignored files and show git tracked hidden files
```lua
@ -88,7 +109,9 @@ require("oil").setup({
local dir = require("oil").get_current_dir(bufnr)
local is_dotfile = vim.startswith(name, ".") and name ~= ".."
-- if no local directory (e.g. for ssh connections), just hide dotfiles
if not dir then return is_dotfile end
if not dir then
return is_dotfile
end
-- dotfiles are considered hidden unless tracked
if is_dotfile then
return not git_status[dir].tracked[name]