diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-16 10:54:49 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-16 10:54:49 +0200 |
| commit | 33a20ad0b33467c6980399bb618485b74d66dc04 (patch) | |
| tree | 48d20718d9dd80619125082cec90521b107eb6cb /desktop/modules/user/User.js | |
| parent | 9a2f7cce971bf2dca54794896d083fdd2f2f1110 (diff) | |
| download | quickshell-33a20ad0b33467c6980399bb618485b74d66dc04.tar.gz quickshell-33a20ad0b33467c6980399bb618485b74d66dc04.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/user/User.js')
| -rw-r--r-- | desktop/modules/user/User.js | 18 |
1 files changed, 18 insertions, 0 deletions
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); +} |
