From 33a20ad0b33467c6980399bb618485b74d66dc04 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 10:54:49 +0200 Subject: feat(user): a random greeting on each drawer open The greeting row picks one at random from ~/.config/quickshell/greetings, one per line with {user} for the login name, # comments and blank lines skipped; without the file, five built-in ones. The row is rebuilt on every drawer open, so the file is read then with no watch, and the last pick is kept in User.js, a shared .pragma library, so the same greeting never shows twice running. Co-Authored-By: Claude Opus 5.5 --- desktop/modules/user/User.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'desktop/modules/user/User.js') diff --git a/desktop/modules/user/User.js b/desktop/modules/user/User.js index 5c3d5a2..dc48209 100644 --- a/desktop/modules/user/User.js +++ b/desktop/modules/user/User.js @@ -62,3 +62,21 @@ function places(text) { } return out; } + +// The drawer's greeting, from ~/.config/quickshell/greetings: one per line, +// {user} for the login name, blank lines and # comments skipped. A missing or +// empty file is the built-in set. The row is rebuilt on every drawer open, so +// the last pick lives here, in the shared library, to never show the same one +// twice running. +const defaultGreetings = ["Hello {user}", "Hi {user}", "Welcome back, {user}", + "Hey there, {user}", "Good to see you, {user}"]; +let lastGreeting = -1; +function greeting(text, user, random) { + const lines = text.split("\n").map(l => l.trim()).filter(l => l && !l.startsWith("#")); + const all = lines.length ? lines : defaultGreetings; + const skip = all.length > 1 && lastGreeting >= 0 && lastGreeting < all.length; + let i = Math.floor((random ?? Math.random()) * (all.length - skip)); + if (skip && i >= lastGreeting) i++; + lastGreeting = i; + return all[i].replace(/\{user\}/g, user); +} -- cgit v1.2.3