feat(profile): add caffeinate alias#360
Conversation
Systemd-inhibit's sleep-blocking functionality is powerful but obscure. Adding a alias makes it discoverable, mimicking the familiar macOS command name. Closes #350
📝 WalkthroughWalkthroughA new shell profile script adds a ChangesCaffeinate Shell Alias
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@system_files/bluefin/etc/profile.d/caffeinate.sh`:
- Around line 3-4: The caffeinate alias runs systemd-inhibit ... sleep and fails
when no seconds are provided; replace the alias named "caffeinate" with a shell
function that invokes systemd-inhibit --what=idle --who=caffeinate --why="User
requested" --mode=block sleep, but if no argument(s) are passed call sleep with
an infinite duration (e.g., sleep infinity or a very large number) and otherwise
forward the provided seconds/arguments to sleep; implement the function named
caffeinate so it accepts and forwards "$@" to sleep and handles the
empty-argument case to keep the system awake until Ctrl+C.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bbee7f72-6bad-43a6-b715-bdc3aa39b41f
📒 Files selected for processing (1)
system_files/bluefin/etc/profile.d/caffeinate.sh
| # Usage: caffeinate [seconds] | ||
| alias caffeinate='systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block sleep' |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="system_files/bluefin/etc/profile.d/caffeinate.sh"
echo "== Contents with line numbers: $FILE =="
if [ -f "$FILE" ]; then
nl -ba "$FILE" | sed -n '1,120p'
else
echo "File not found: $FILE"
fi
echo
echo "== Grep for caffeinate usage/comment and alias/function =="
rg -n "caffeinate|Usage:|Ctrl\+C|sleep" -S "$FILE" || trueRepository: projectbluefin/common
Length of output: 209
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="system_files/bluefin/etc/profile.d/caffeinate.sh"
echo "== Contents with line numbers (cat -n): $FILE =="
if [ -f "$FILE" ]; then
cat -n "$FILE" | sed -n '1,120p'
else
echo "File not found: $FILE"
fi
echo
echo "== Grep for caffeinate usage/comment and alias/function =="
rg -n "caffeinate|Usage:|Ctrl\+C|sleep" -S "$FILE" || trueRepository: projectbluefin/common
Length of output: 723
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Running: sleep (no args)"
sleep 2>/tmp/sleep_err.txt || true
echo "exit code: $?"
echo "--- stderr ---"
cat /tmp/sleep_err.txt || trueRepository: projectbluefin/common
Length of output: 182
Fix caffeinate to avoid immediate exit when called without [seconds]
caffeinate is currently an alias that runs systemd-inhibit ... sleep; invoking caffeinate without arguments causes sleep to error (“missing operand”) and exit immediately, so it does not keep the system awake “until Ctrl+C” as documented.
Proposed fix
-# Usage: caffeinate [seconds]
-alias caffeinate='systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block sleep'
+# Usage: caffeinate [seconds]
+caffeinate() {
+ if [ -n "${1:-}" ]; then
+ systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block sleep "$1"
+ else
+ systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block bash -c 'while :; do sleep 3600; done'
+ fi
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Usage: caffeinate [seconds] | |
| alias caffeinate='systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block sleep' | |
| # Usage: caffeinate [seconds] | |
| caffeinate() { | |
| if [ -n "${1:-}" ]; then | |
| systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block sleep "$1" | |
| else | |
| systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block bash -c 'while :; do sleep 3600; done' | |
| fi | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@system_files/bluefin/etc/profile.d/caffeinate.sh` around lines 3 - 4, The
caffeinate alias runs systemd-inhibit ... sleep and fails when no seconds are
provided; replace the alias named "caffeinate" with a shell function that
invokes systemd-inhibit --what=idle --who=caffeinate --why="User requested"
--mode=block sleep, but if no argument(s) are passed call sleep with an infinite
duration (e.g., sleep infinity or a very large number) and otherwise forward the
provided seconds/arguments to sleep; implement the function named caffeinate so
it accepts and forwards "$@" to sleep and handles the empty-argument case to
keep the system awake until Ctrl+C.
🤖 Copilot Test ReportBranch: Test Results
ChangeAdds alias caffeinate='systemd-inhibit --what=idle --who=caffeinate --why="User requested" --mode=block sleep'
|
| PR | Approach | File |
|---|---|---|
| #360 (this PR) | Shell alias via profile.d (adds sleep suffix) |
etc/profile.d/caffeinate.sh |
| #361 | Shell alias via profile.d (no sleep suffix, takes args directly) |
Same file — would conflict |
| #351 | ujust caffeinate recipe in default.just |
default.just |
#360 and #361 create the same file and cannot both be merged. #351 is additive (ujust recipe) and could co-exist with either alias PR.
castrojo
left a comment
There was a problem hiding this comment.
✅ Approving to satisfy merge queue requirement. Tested via just check — passes. See test report comment for details.
|
🔔 Needs 1 more approval to enter the merge queue. Ruleset requires 2 reviewers with write access. @castrojo has approved — one more maintainer needed. |
Summary
Adds a
caffeinateshell alias that wrapssystemd-inhibitto temporarily prevent sleep/suspend. This mirrors the familiar macOS command name and makes the sleep-blocking feature discoverable.Closes #350
Changes
system_files/bluefin/etc/profile.d/caffeinate.sh: new alias filecaffeinate 300blocks sleep for 5 minutesSummary by CodeRabbit
caffeinatecommand to keep your system awake by preventing idle sleep until interrupted.