Repository navigation
feat: add fish wrapper functions for local scripts and move yek to cargo globals #1358
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 all commits
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||
| #!/usr/bin/env bash | ||||||||||
| # Auto-switch Claude account on rate limit via claude-swap (cswap). | ||||||||||
| # Triggered by the StopFailure hook when Claude Code hits a rate limit. | ||||||||||
| # | ||||||||||
| # Reads hook input from stdin: { error, error_details, ... } | ||||||||||
| # Only switches if the error indicates a rate limit. | ||||||||||
|
|
||||||||||
| set -euo pipefail | ||||||||||
|
|
||||||||||
| # Require cswap | ||||||||||
| if ! command -v cswap &>/dev/null; then | ||||||||||
| exit 0 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| # Require at least 2 managed accounts | ||||||||||
| ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^\s*[0-9]' || echo 0) | ||||||||||
|
||||||||||
| ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^\s*[0-9]' || echo 0) | |
| ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^[[:space:]]*[0-9]' || true) |
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.
Using herestrings (<<< "$INPUT") is generally preferred over echo "$INPUT" | jq as it avoids a subshell and is safer if the input starts with a hyphen (which echo might interpret as a flag).
| ERROR=$(echo "$INPUT" | jq -r '.error // empty' 2>/dev/null) || true | |
| ERROR_DETAILS=$(echo "$INPUT" | jq -r '.error_details // empty' 2>/dev/null) || true | |
| ERROR=$(jq -r '.error // empty' 2>/dev/null <<< "$INPUT") || true | |
| ERROR_DETAILS=$(jq -r '.error_details // empty' 2>/dev/null <<< "$INPUT") || true |
Copilot
AI
Apr 5, 2026
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.
With set -euo pipefail, a failing cswap --switch (or a broken pipe from head) can cause this hook itself to exit non-zero, which is risky for a “best effort” remediation hook triggered during failures. Consider making the switch attempt explicitly non-fatal (e.g., append || true, or temporarily disable -e/pipefail around the pipeline) so the hook doesn’t introduce additional failure modes.
| cswap --switch 2>&1 | head -5 >&2 | |
| cswap --switch 2>&1 | head -5 >&2 || true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,4 @@ | |
| ./tailscale | ||
| ./uv-globals | ||
| ./xremap | ||
| ./yek | ||
| ] | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function _install_cargo_globals_function --description "Install global Cargo packages" | ||
| set -l script "$HOME/dotfiles/home-manager/modules/cargo-globals/install-cargo-globals.sh" | ||
| if not test -f "$script" | ||
| echo "install-cargo-globals.sh not found at $script" | ||
|
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. |
||
| return 1 | ||
| end | ||
| bash "$script" $argv | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function _install_npm_globals_function --description "Install global npm packages" | ||
| set -l script "$HOME/dotfiles/home-manager/modules/npm-globals/install-npm-globals.sh" | ||
| if not test -f "$script" | ||
| echo "install-npm-globals.sh not found at $script" | ||
| return 1 | ||
| end | ||
| bash "$script" $argv | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function _install_uv_globals_function --description "Install global uv packages" | ||
| set -l script "$HOME/dotfiles/home-manager/modules/uv-globals/install-uv-globals.sh" | ||
| if not test -f "$script" | ||
| echo "install-uv-globals.sh not found at $script" | ||
| return 1 | ||
| end | ||
| bash "$script" $argv | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function _llm_update_function --description "Propagate LLM model configs via template substitution" | ||
| set -l script "$HOME/dotfiles/scripts/llm-update.sh" | ||
| if not test -f "$script" | ||
| echo "llm-update.sh not found at $script" | ||
| return 1 | ||
| end | ||
| bash "$script" $argv | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function _sync_local_binaries_function --description "Sync local binaries from ~/.local-binaries.txt to ~/.local/bin" | ||
| set -l script "$HOME/dotfiles/home-manager/modules/local-binaries/sync-local-binaries.sh" | ||
| if not test -f "$script" | ||
| echo "sync-local-binaries.sh not found at $script" | ||
| return 1 | ||
| end | ||
| bash "$script" $argv | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function _update_local_binaries_function --description "Update and build local binaries from .local-binaries.txt" | ||
| set -l script "$HOME/dotfiles/scripts/update-local-binaries.sh" | ||
| if not test -f "$script" | ||
| echo "update-local-binaries.sh not found at $script" | ||
| return 1 | ||
| end | ||
| bash "$script" $argv | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||
| #!/usr/bin/env bash | ||||||
| # shellcheck disable=SC2329 | ||||||
|
|
||||||
| Describe 'auto-switch.sh' | ||||||
| SCRIPT="$PWD/config/claude/hooks/auto-switch.sh" | ||||||
|
|
||||||
| It 'exits 0 when cswap is not available' | ||||||
| # Mock command so cswap is not found | ||||||
| command() { return 1; } | ||||||
|
Comment on lines
+8
to
+9
|
||||||
| # Mock command so cswap is not found | |
| command() { return 1; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| set fn (status dirname)/../../home-manager/programs/fish/functions | ||
| source $fn/_install_cargo_globals_function.fish | ||
|
|
||
| set tmpdir (mktemp -d) | ||
|
|
||
| set -x HOME $tmpdir | ||
| _install_cargo_globals_function >/dev/null 2>&1 | ||
| @test "returns 1 when script missing" $status = 1 | ||
|
|
||
| rm -rf $tmpdir |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| set fn (status dirname)/../../home-manager/programs/fish/functions | ||
| source $fn/_install_npm_globals_function.fish | ||
|
|
||
| set tmpdir (mktemp -d) | ||
|
|
||
| set -x HOME $tmpdir | ||
| _install_npm_globals_function >/dev/null 2>&1 | ||
| @test "returns 1 when script missing" $status = 1 | ||
|
|
||
| rm -rf $tmpdir |
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 script relies on jq to parse the hook input. It is safer to check for its availability alongside cswap to avoid silent failures if jq is missing in the environment.