Repository navigation
chore(fish): Update fish functions and configuration #1907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,7 @@ | |
| v = "nvim"; | ||
|
|
||
| # Function-based abbreviations | ||
| caf = "_caf_function"; | ||
| cawxe = "_cawxe_function"; | ||
| cawxeh = "_cawxeh_function"; | ||
| caxe = "_caxe_function"; | ||
|
|
@@ -226,6 +227,7 @@ | |
| }) | ||
| [ | ||
| "__tmux_bootstrap_default_session" | ||
| "_caf_function" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The repository has a test coverage spec ( Prompt for AI agents |
||
| "_cawxe_function" | ||
| "_cawxeh_function" | ||
| "_caxe_function" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| function _caf_function --description "Keep the machine awake lid-closed (caffeinate / systemd-inhibit)" | ||
| set -l pid_file "$HOME/.local/state/caf.pid" | ||
|
|
||
| switch "$argv[1]" | ||
| case on | ||
| mkdir -p (dirname "$pid_file") | ||
| if test (uname) = Darwin | ||
| sudo pmset -a disablesleep 1 | ||
| caffeinate -dimsu & | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| else | ||
| systemd-inhibit --what=handle-lid-switch:sleep:idle \ | ||
| --who=caf --why=caf --mode=block sleep infinity & | ||
| end | ||
| echo $last_pid >"$pid_file" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-running Consider short-circuiting if test -f "$pid_file"; and kill -0 (cat "$pid_file") 2>/dev/null
echo "caf already on (pid "(cat "$pid_file")")"
return 0
end |
||
| disown | ||
| echo "caf on: awake lid-closed (pid "(cat "$pid_file")")" | ||
|
Comment on lines
+5
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On Line 5 and Line 42, repeated starts create additional background inhibitors while Line 14 overwrites the PID file, so Suggested fix function _caf_function --description "Keep the machine awake lid-closed (caffeinate / systemd-inhibit)"
set -l pid_file "$HOME/.local/state/caf.pid"
switch "$argv[1]"
case on
mkdir -p (dirname "$pid_file")
+ if test -f "$pid_file"
+ set -l existing_pid (cat "$pid_file")
+ if test -n "$existing_pid"; and kill -0 "$existing_pid" 2>/dev/null
+ echo "caf already active (pid $existing_pid)"
+ return 0
+ end
+ rm -f "$pid_file"
+ end
if test (uname) = Darwin
sudo pmset -a disablesleep 1
caffeinate -dimsu &
else
systemd-inhibit --what=handle-lid-switch:sleep:idle \
--who=caf --why=caf --mode=block sleep infinity &
end
echo $last_pid >"$pid_file"
disown
echo "caf on: awake lid-closed (pid "(cat "$pid_file")")"Also applies to: 37-43 🤖 Prompt for AI Agents |
||
| case off | ||
| if test (uname) = Darwin | ||
| sudo pmset -a disablesleep 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unconditional if test -f "$pid_file"
if test (uname) = Darwin
sudo pmset -a disablesleep 0
end
kill (cat "$pid_file") 2>/dev/null
rm -f "$pid_file"
end
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| end | ||
| if test -f "$pid_file" | ||
| kill (cat "$pid_file") 2>/dev/null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: The PID file is trusted without validation, so Prompt for AI agents |
||
| rm -f "$pid_file" | ||
|
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PID-file kill is unsafe without process identity validation. On Line 22, killing an unvalidated PID from disk can terminate an unrelated process after PID reuse. Validate that the PID still belongs to the expected keep-awake command before sending Suggested fix case off
if test (uname) = Darwin
sudo pmset -a disablesleep 0
end
if test -f "$pid_file"
- kill (cat "$pid_file") 2>/dev/null
+ set -l pid (cat "$pid_file")
+ set -l cmd (ps -p "$pid" -o command= 2>/dev/null)
+ if string match -rq 'caffeinate|systemd-inhibit|sleep infinity' -- "$cmd"
+ kill "$pid" 2>/dev/null
+ else
+ echo "caf off: refusing to kill unrecognized pid $pid"
+ end
rm -f "$pid_file"
end
echo "caf off: normal sleep restored"🤖 Prompt for AI Agents |
||
| end | ||
| echo "caf off: normal sleep restored" | ||
| case status | ||
| if test (uname) = Darwin | ||
| pmset -g | string match -e disablesleep | ||
| else | ||
| systemd-inhibit --list 2>/dev/null | string match -e caf | ||
| end | ||
| if test -f "$pid_file"; and kill -0 (cat "$pid_file") 2>/dev/null | ||
| echo "caf active (pid "(cat "$pid_file")")" | ||
| else | ||
| echo "caf inactive" | ||
| end | ||
| case '' | ||
| # Toggle: active if the keeper pid is alive | ||
| if test -f "$pid_file"; and kill -0 (cat "$pid_file") 2>/dev/null | ||
| _caf_function off | ||
| else | ||
| _caf_function on | ||
| end | ||
| case '*' | ||
| echo "Usage: caf [on|off|status]" | ||
| return 1 | ||
| end | ||
| end | ||
|
Comment on lines
+1
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using We can optimize this by reading the PID into a local variable using |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repository has a test coverage spec (
spec/fish_functions_coverage_spec.sh) that dynamically checks if every fish function has a corresponding test file underspec/fish/. Since you added_caf_function.fish, you must also add a corresponding test filespec/fish/_caf_function_test.fishto prevent the test suite from failing.