Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ Run the following command to open the dashboard:

## Mappings

| Key | Action |
| Key | Action |
| --- | --------- |
| `<` | prev year |
| `>` | next year |
| `<leader>gw` | Open dashboard (configurable) |
| `<` | prev year (configurable) |
| `>` | next year (configurable) |
| `q` | Close dashboard (configurable) |
| `r` | Refresh data (configurable) |

## Default Config

```lua
require("wrapped").setup({
path = vim.fn.stdpath("config"), -- path to your neovim configuration
path = "", -- auto-detects current directory (or specify custom path)
border = false,
size = {
width = 120,
Expand All @@ -73,6 +76,13 @@ require("wrapped").setup({
plugins_ever = 200,
lines = 10000,
},
keys = {
open = "<leader>gw",
close = "q",
refresh = "r",
prev_year = "<",
next_year = ">",
},
})
```

Expand Down
12 changes: 11 additions & 1 deletion lua/wrapped/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ local loading = require "wrapped.ui.loading"
---@param opts? WrappedConfig
M.setup = function(opts)
state.config = vim.tbl_deep_extend("force", state.config, opts or {})

-- Auto-detect: use current directory if no path specified
if not state.config.path or state.config.path == "" then
state.config.path = vim.fn.stdpath "config" --[[@as string]]
state.config.path = vim.fn.getcwd() -- auto-detect current directory
end

-- Set up keybindings
local keys = state.config.keys
if keys and keys.open and keys.open ~= "<leader>gw" then
-- User customized: remove default and set custom
vim.keymap.del("n", "<leader>gw")
vim.keymap.set("n", keys.open, ":WrappedNvim<CR>", { desc = "Open Wrapped dashboard" })
end
end

Expand Down
9 changes: 8 additions & 1 deletion lua/wrapped/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local api = vim.api
local M = {
-- user config
config = {
path = vim.fn.stdpath "config",
path = "", -- auto-detect current directory
border = false,
size = { width = 120, height = 40 },
exclude_filetype = { ".gitmodules" },
Expand All @@ -14,6 +14,13 @@ local M = {
plugins_ever = 200,
lines = 10000,
},
keys = {
open = "<leader>gw",
close = "q",
refresh = "r",
prev_year = "<",
next_year = ">",
},
},

-- layout
Expand Down
18 changes: 14 additions & 4 deletions lua/wrapped/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,16 @@ M.open = function(results)

volt.run(buf, { h = content_h, w = w })

-- keymaps
-- keymaps using configurable keys
local keys = state.config.keys or {}
local map_opts = { noremap = true, silent = true, callback = close }
api.nvim_buf_set_keymap(buf, "n", "q", "", map_opts)

-- close key
if keys.close then
api.nvim_buf_set_keymap(buf, "n", keys.close, "", map_opts)
else
api.nvim_buf_set_keymap(buf, "n", "q", "", map_opts)
end
api.nvim_buf_set_keymap(buf, "n", "<Esc>", "", map_opts)

-- year cycling
Expand All @@ -197,15 +204,18 @@ M.open = function(results)
heatmap.refresh(buf)
end

-- prev/next year keys
local prev_year_key = keys.prev_year or "<"
local next_year_key = keys.next_year or ">"
vim.keymap.set(
"n",
"<",
prev_year_key,
function() cycle_year(-1) end,
{ buffer = buf, silent = true }
)
vim.keymap.set(
"n",
">",
next_year_key,
function() cycle_year(1) end,
{ buffer = buf, silent = true }
)
Expand Down
3 changes: 3 additions & 0 deletions plugin/wrapped.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ if vim.g.wrapped_loaded == 1 then return end

vim.g.wrapped_loaded = 1

-- Default keybinding (can be overridden in setup())
vim.keymap.set("n", "<leader>gw", ":WrappedNvim<CR>", { desc = "Open Wrapped dashboard" })

vim.api.nvim_create_user_command(
"NvimWrapped",
function() require("wrapped").run() end,
Expand Down