Skip to content

Commit 382cd0a

Browse files
committed
feat: add options to ignore projects and filetypes to show
1 parent 2d77e50 commit 382cd0a

File tree

10 files changed

+307
-30
lines changed

10 files changed

+307
-30
lines changed

lua/codeme/init.lua

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,49 @@ local M = {}
44
local default_config = {
55
auto_track = true,
66
verbose = false,
7-
goals = {
8-
daily_hours = 4,
9-
daily_lines = 500,
7+
ignores = {
8+
-- Tracking: These never leave Neovim (not saved to DB)
9+
tracking = {
10+
languages = {
11+
"gitcommit",
12+
"gitrebase",
13+
"help",
14+
"qf",
15+
"netrw",
16+
"log",
17+
"checkhealth",
18+
"man",
19+
"TelescopePrompt",
20+
"vim", -- cmdwin
21+
},
22+
files = {
23+
"%.git/.*",
24+
"%.log$",
25+
"%.tmp$",
26+
"%.swp$",
27+
"%.swo$",
28+
"%.DS_Store$",
29+
"undo/.*",
30+
"tags$",
31+
},
32+
projects = {
33+
"temp%-.*",
34+
"test%-.*",
35+
},
36+
},
37+
-- Dashboard: These are masked or hidden in the UI
38+
dashboard = {
39+
projects = {}, -- User specific: e.g. { "secret-.*" }
40+
files = {}, -- User specific
41+
languages = {
42+
"gitignore",
43+
"gitconfig",
44+
"sshconfig",
45+
},
46+
},
1047
},
48+
daily_hours = 4,
49+
daily_lines = 500,
1150
}
1251

1352
local config = vim.deepcopy(default_config)

lua/codeme/tracking.lua

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ local last_heartbeat = {}
77
local last_git_diff = {}
88
local COOLDOWN = 120 -- Only send heartbeat every 2 minutes per file
99

10+
---Check if a string matches any pattern in a list (Smart glob support)
11+
---@param str string
12+
---@param patterns string[]
13+
---@return boolean
14+
local function matches_any(str, patterns)
15+
if not str or not patterns or #patterns == 0 then
16+
return false
17+
end
18+
for _, p in ipairs(patterns) do
19+
-- Simple glob conversion: * -> .* and escape magic chars
20+
local pattern = p
21+
if not p:match("[%^%$%%]") then
22+
pattern = "^" .. p:gsub("%.", "%%."):gsub("%*", ".*") .. "$"
23+
end
24+
25+
if str:match(pattern) then
26+
return true
27+
end
28+
end
29+
return false
30+
end
31+
1032
---Check if buffer should be tracked
1133
---@param bufnr number
1234
---@param filepath string
@@ -21,10 +43,28 @@ local function should_track(bufnr, filepath)
2143
end
2244

2345
local skip_fts = { "NvimTree", "neo-tree", "dashboard", "help", "qf", "TelescopePrompt", "oil", "noice", "notify" }
24-
if vim.tbl_contains(skip_fts, vim.bo[bufnr].filetype) then
46+
local filetype = vim.bo[bufnr].filetype
47+
if vim.tbl_contains(skip_fts, filetype) then
2548
return false
2649
end
2750

51+
-- Expert Ignore Rules: Tracking Filters
52+
local ok, codeme = pcall(require, "codeme")
53+
if ok then
54+
local ignores = codeme.get_config().ignores or {}
55+
local filters = ignores.tracking or {}
56+
57+
if matches_any(filetype, filters.languages or {}) then
58+
return false
59+
end
60+
if matches_any(filepath, filters.files or {}) then
61+
return false
62+
end
63+
if matches_any(filepath, filters.projects or {}) then
64+
return false
65+
end
66+
end
67+
2868
return true
2969
end
3070

lua/codeme/ui/dashboard.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ end
4444
local function render_dashboard(stat_data)
4545
-- Strip every vim.NIL from the backend payload once here.
4646
stat_data = util.sanitize(stat_data) or {}
47+
stat_data = util.apply_privacy_mask(stat_data)
4748

4849
local buf = stats.get_buf()
4950
local win = stats.get_win()
@@ -114,7 +115,7 @@ end
114115
---Show dashboard window
115116
---@param stat_data table
116117
function M.show_window(stat_data)
117-
-- ... (rest of the function stays same until keymaps)
118+
-- ... (rest of the function stays same until keymaps)
118119

119120
-- Create buffer
120121
local buf = vim.api.nvim_create_buf(false, true)
@@ -221,11 +222,11 @@ function M.show_window(stat_data)
221222
if current_win and vim.api.nvim_win_is_valid(current_win) then
222223
local new_width = math.min(160, math.floor(vim.o.columns * 0.95))
223224
local new_height = math.min(60, math.floor(vim.o.lines * 0.85))
224-
225+
225226
-- Ensure minimum size to prevent crash
226227
new_width = math.max(40, new_width)
227228
new_height = math.max(10, new_height)
228-
229+
229230
pcall(vim.api.nvim_win_set_config, current_win, {
230231
relative = "editor",
231232
width = new_width,

lua/codeme/ui/tabs/activity.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ local renderer = require("codeme.ui.renderer")
33

44
local M = {}
55

6-
function M.render(stats, width, height)
6+
function M.render(stats, width)
7+
stats = require("codeme.util").apply_privacy_mask(stats)
78
local lines = {}
89
local today = stats.today or {}
910
local today_sessions = today.sessions or {}
@@ -105,7 +106,11 @@ function M.render(stats, width, height)
105106
end
106107
local start_period, start_icon = get_period(start_hour)
107108
local end_period, end_icon = get_period(end_hour)
108-
local story = { { " 📖 ", "exgreen" }, { "You started in the ", "commentfg" }, { start_period .. " " .. start_icon, "normal" } }
109+
local story = {
110+
{ " 📖 ", "exgreen" },
111+
{ "You started in the ", "commentfg" },
112+
{ start_period .. " " .. start_icon, "normal" },
113+
}
109114
if start_period ~= end_period then
110115
table.insert(story, { " and continued into the ", "commentfg" })
111116
table.insert(story, { end_period .. " " .. end_icon, "normal" })

lua/codeme/ui/tabs/overview.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ local renderer = require("codeme.ui.renderer")
33

44
local M = {}
55

6-
function M.render(stats, width, height)
6+
function M.render(stats, width)
7+
stats = require("codeme.util").apply_privacy_mask(stats)
78
local lines = {}
89
local today = stats.today or {}
910
local today_time = today.total_time or 0
@@ -172,16 +173,25 @@ function M.render(stats, width, height)
172173

173174
-- Streak visualization (Restored prominence)
174175
local flame_display
175-
if current_streak >= 30 then flame_display = "🔥🔥🔥🔥🔥"
176-
elseif current_streak >= 14 then flame_display = "🔥🔥🔥"
177-
elseif current_streak >= 7 then flame_display = "🔥🔥"
178-
elseif current_streak > 0 then flame_display = "🔥"
179-
else flame_display = "💤" end
176+
if current_streak >= 30 then
177+
flame_display = "🔥🔥🔥🔥🔥"
178+
elseif current_streak >= 14 then
179+
flame_display = "🔥🔥🔥"
180+
elseif current_streak >= 7 then
181+
flame_display = "🔥🔥"
182+
elseif current_streak > 0 then
183+
flame_display = "🔥"
184+
else
185+
flame_display = "💤"
186+
end
180187

181188
table.insert(lines, {
182189
{ " " .. flame_display .. " ", "normal" },
183190
{ string.format("%d DAY STREAK", current_streak), "exyellow" },
184-
{ longest_streak > current_streak and string.format(" • Best: %d days", longest_streak) or " • NEW RECORD!", "commentfg" },
191+
{
192+
longest_streak > current_streak and string.format(" • Best: %d days", longest_streak) or " • NEW RECORD!",
193+
"commentfg",
194+
},
185195
})
186196
table.insert(lines, {})
187197

lua/codeme/ui/tabs/records.lua

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ local renderer = require("codeme.ui.renderer")
33

44
local M = {}
55

6-
function M.render(stats, width, height)
6+
function M.render(stats, width)
7+
stats = require("codeme.util").apply_privacy_mask(stats)
78
local lines = {}
89

910
-- Helper for safe padding (local to avoid nil field errors)
@@ -168,7 +169,10 @@ function M.render(stats, width, height)
168169
end
169170
local ls = records.longest_session or {}
170171
if ls.duration and ls.duration > 0 then
171-
table.insert(record_list, { "⏱️ Longest Session", util.format_duration(ls.duration), util.format_date(ls.date or "") })
172+
table.insert(
173+
record_list,
174+
{ "⏱️ Longest Session", util.format_duration(ls.duration), util.format_date(ls.date or "") }
175+
)
172176
end
173177
local hdo = records.highest_daily_output or {}
174178
if hdo.lines and hdo.lines > 0 then
@@ -196,15 +200,36 @@ function M.render(stats, width, height)
196200
table.insert(lines, { { " 📊 Fun Facts", "exgreen" } })
197201
table.insert(lines, {})
198202
if earliest_start.time then
199-
table.insert(lines, { { " 🌅 Early Bird: ", "commentfg" }, { earliest_start.time, "exgreen" }, { " (" .. (earliest_start.date or "") .. ")", "commentfg" } })
203+
table.insert(
204+
lines,
205+
{
206+
{ " 🌅 Early Bird: ", "commentfg" },
207+
{ earliest_start.time, "exgreen" },
208+
{ " (" .. (earliest_start.date or "") .. ")", "commentfg" },
209+
}
210+
)
200211
end
201212
if latest_end.time then
202-
table.insert(lines, { { " 🌙 Night Owl: ", "commentfg" }, { latest_end.time, "exgreen" }, { " (" .. (latest_end.date or "") .. ")", "commentfg" } })
213+
table.insert(
214+
lines,
215+
{
216+
{ " 🌙 Night Owl: ", "commentfg" },
217+
{ latest_end.time, "exgreen" },
218+
{ " (" .. (latest_end.date or "") .. ")", "commentfg" },
219+
}
220+
)
203221
end
204222
if most_languages_day and most_languages_day.date ~= "" then
205223
local langs_count = util.safe_length(most_languages_day.languages)
206224
if langs_count > 0 then
207-
table.insert(lines, { { " 🌍 Polyglot Day: ", "commentfg" }, { langs_count .. " languages", "exgreen" }, { " (" .. most_languages_day.date .. ")", "commentfg" } })
225+
table.insert(
226+
lines,
227+
{
228+
{ " 🌍 Polyglot Day: ", "commentfg" },
229+
{ langs_count .. " languages", "exgreen" },
230+
{ " (" .. most_languages_day.date .. ")", "commentfg" },
231+
}
232+
)
208233
end
209234
end
210235
table.insert(lines, {})
@@ -218,10 +243,16 @@ function M.render(stats, width, height)
218243
local challenges = {}
219244

220245
if mpd.time and today_time > 0 and mpd.time > today_time then
221-
table.insert(challenges, { icon = "🎯", text = util.format_duration(mpd.time - today_time) .. " to beat your best day", hl = "exyellow" })
246+
table.insert(
247+
challenges,
248+
{ icon = "🎯", text = util.format_duration(mpd.time - today_time) .. " to beat your best day", hl = "exyellow" }
249+
)
222250
end
223251
if ls.duration then
224-
table.insert(challenges, { icon = "", text = "Can you beat " .. util.format_duration(ls.duration) .. " in one session?", hl = "normal" })
252+
table.insert(
253+
challenges,
254+
{ icon = "", text = "Can you beat " .. util.format_duration(ls.duration) .. " in one session?", hl = "normal" }
255+
)
225256
end
226257
if #challenges > 0 then
227258
for _, ch in ipairs(challenges) do

lua/codeme/ui/tabs/search.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local function fetch_day(refresh_fn)
2525
if not data or (not data.date and not data.total_time) then
2626
state.error = "Failed to fetch data"
2727
else
28-
state.data = data
28+
state.data = util.apply_privacy_mask(data)
2929
end
3030
refresh_fn()
3131
end)

lua/codeme/ui/tabs/weekly.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ local function count_week_coding_days(daily_activity)
4747
return days_coded
4848
end
4949

50-
function M.render(stats, width, height)
50+
function M.render(stats, width)
51+
stats = require("codeme.util").apply_privacy_mask(stats)
5152
local lines = {}
5253

5354
local this_week = stats.this_week or {}

lua/codeme/ui/tabs/work.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ local renderer = require("codeme.ui.renderer")
33

44
local M = {}
55

6-
function M.render(stats, width, height)
6+
function M.render(stats, width)
7+
stats = require("codeme.util").apply_privacy_mask(stats)
78
local lines = {}
89

910
table.insert(lines, {})

0 commit comments

Comments
 (0)