Skip to content

Commit

Permalink
feat(sources-path & configs): add opts.sources.path.preview
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Mar 3, 2024
1 parent 281260f commit b8e02b6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ vim.ui.select = require('dropbar.utils.menu').select
modified = function(sym)
return sym
end,
---@type boolean|fun(path: string): boolean?|nil
preview = function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file' and stat.size <= 524288
end,
},
treesitter = {
-- Lua pattern used to extract a short name from the node text
Expand Down Expand Up @@ -1596,6 +1601,16 @@ each sources.
})
end
```
- `opts.sources.path.preview`: `boolean|fun(path: string): boolean?|nil`
- A boolean or a function that takes a file path and returns whether to
preview the file under cursor
- Default:
```lua
function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file' and stat.size <= 524288
end
```

##### Treesitter

Expand Down
11 changes: 11 additions & 0 deletions doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,17 @@ PATH *dropbar-configuration-options-sources-path*
-- ...
})
end
- `opts.sources.path.preview`: `boolean|fun(path: string): boolean?|nil`
- A boolean or a function that takes a file path and returns whether to
preview the file under cursor
- Default: >lua

function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file'
and stat.size <= 524288
end
<

TREESITTER *dropbar-configuration-options-sources-treesitter*

Expand Down
5 changes: 5 additions & 0 deletions lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ M.opts = {
modified = function(sym)
return sym
end,
---@type boolean|fun(path: string): boolean?|nil
preview = function(path)
local stat = vim.uv.fs_stat(path)
return stat and stat.type == 'file' and stat.size <= 524288
end,
},
treesitter = {
-- Lua pattern used to extract a short name from the node text
Expand Down
3 changes: 3 additions & 0 deletions lua/dropbar/sources/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ end

---@param self dropbar_symbol_t
local function preview_open(self, path)
if not configs.eval(configs.opts.sources.path.preview, path) then
return
end
local preview_buf = preview_prepare_buf(self, path)
if not preview_buf then
return
Expand Down

0 comments on commit b8e02b6

Please sign in to comment.