shellcheck / shellcheck (push) Successful in 18s
The hooks ran notify-send from inside Claude, so GNOME couldn't tell which app the notification came from and clicking it did nothing. system/claude-notify finds the terminal or editor among Claude's parent processes (or tmux's client, or the Flatpak) and names it in the desktop-entry hint. The title shows the project folder and the body Claude's own message. claude.sh swaps the old notify-send hooks for it, only where they're still the ones CoreDesktop wrote, and 70-claude.sh now runs claude.sh on every update so existing machines get it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.5 KiB
Bash
Executable File
83 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Purpose : Install Claude Code using the official native installer
|
|
|
|
set -euo pipefail
|
|
|
|
# Check if Claude Code is already installed
|
|
if command -v claude &>/dev/null; then
|
|
echo "Claude Code is already installed: $(claude --version)"
|
|
else
|
|
echo "Installing Claude Code..."
|
|
curl -fsSL https://claude.ai/install.sh | bash
|
|
fi
|
|
|
|
# The native installer places the binary in ~/.local/bin
|
|
LINE='export PATH="$HOME/.local/bin:$PATH"'
|
|
if grep -qF "$LINE" ~/.bashrc; then
|
|
echo "\~/.local/bin already on PATH in .bashrc"
|
|
else
|
|
echo "$LINE" >> ~/.bashrc
|
|
echo "\~/.local/bin added to PATH in .bashrc"
|
|
fi
|
|
|
|
# Desktop notifications, through system/claude-notify so that clicking one
|
|
# brings back the app Claude is running in
|
|
SETTINGS_FILE="$HOME/.claude/settings.json"
|
|
# The hook runs in a shell, which expands ~
|
|
# shellcheck disable=SC2088
|
|
NOTIFY="~/.local/share/coredesktop/system/claude-notify"
|
|
if [ -f "$SETTINGS_FILE" ]; then
|
|
echo "Claude Code settings already exist at $SETTINGS_FILE"
|
|
# Settings written before claude-notify ran notify-send itself, so clicking
|
|
# did nothing. Change those two hooks, and only those: any others are yours.
|
|
tmp="$(mktemp "$SETTINGS_FILE.XXXXXX")"
|
|
if jq --arg notify "$NOTIFY" \
|
|
--arg old_input "notify-send 'Claude Code' 'Needs your input'" \
|
|
--arg old_done "notify-send 'Claude Code' 'Task completed'" '
|
|
def swap(old; new):
|
|
if type == "object" and .command == old then .command = new else . end;
|
|
(.hooks.Notification[]?.hooks[]?) |= swap($old_input; "\($notify) '"'Needs your input'"'")
|
|
| (.hooks.Stop[]?.hooks[]?) |= swap($old_done; "\($notify) '"'Task completed'"'")
|
|
' "$SETTINGS_FILE" > "$tmp" \
|
|
&& ! jq -e --slurpfile new "$tmp" '. == $new[0]' "$SETTINGS_FILE" > /dev/null; then
|
|
echo "Making Claude Code's notifications clickable..."
|
|
mv -f "$tmp" "$SETTINGS_FILE"
|
|
else
|
|
rm -f "$tmp"
|
|
fi
|
|
else
|
|
echo "Writing Claude Code settings to $SETTINGS_FILE..."
|
|
mkdir -p "$(dirname "$SETTINGS_FILE")"
|
|
cat > "$SETTINGS_FILE" <<EOF
|
|
{
|
|
"hooks": {
|
|
"Notification": [
|
|
{
|
|
"matcher": "",
|
|
"hooks": [
|
|
{
|
|
"type": "command",
|
|
"command": "$NOTIFY 'Needs your input'"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"Stop": [
|
|
{
|
|
"matcher": "",
|
|
"hooks": [
|
|
{
|
|
"type": "command",
|
|
"command": "$NOTIFY 'Task completed'"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
echo "Done. Run 'claude' to log in and get started."
|