-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·244 lines (214 loc) · 6.87 KB
/
install.sh
File metadata and controls
executable file
·244 lines (214 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/env bash
set -euo pipefail
# claude-code-sounds installer
# Adds audio notification hooks to Claude Code settings
#
# Statotech Systems - www.statotec.com
# Author: Blessing Siwonde - https://github.com/StaticB1/
# License: MIT (Open Source)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HELPER="$SCRIPT_DIR/lib/settings-helper.js"
SETTINGS_FILE="$HOME/.claude/settings.json"
SOUNDS_DIR="$HOME/.claude/sounds"
AUTO_YES=false
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}[info]${NC} $1"; }
ok() { echo -e "${GREEN}[ok]${NC} $1"; }
warn() { echo -e "${YELLOW}[warn]${NC} $1"; }
err() { echo -e "${RED}[error]${NC} $1"; }
# --- Detect platform and audio player ---
detect_player() {
case "$(uname -s)" in
Linux*)
if command -v paplay &>/dev/null; then
echo "paplay"
elif command -v aplay &>/dev/null; then
echo "aplay"
elif command -v ffplay &>/dev/null; then
echo "ffplay -nodisp -autoexit"
else
echo ""
fi
;;
Darwin*)
echo "afplay"
;;
MINGW*|MSYS*|CYGWIN*)
if command -v powershell.exe &>/dev/null; then
echo "powershell.exe"
else
echo ""
fi
;;
*)
echo ""
;;
esac
}
# --- Build the play command for a given sound file ---
build_play_command() {
local sound_file="$1"
local player="$2"
case "$player" in
powershell.exe*)
# Windows: use printf-style substitution
printf "powershell.exe -c '(New-Object Media.SoundPlayer \"%s\").PlaySync()' &" "$sound_file"
;;
"ffplay -nodisp -autoexit")
echo "ffplay -nodisp -autoexit \"$sound_file\" &"
;;
*)
echo "$player \"$sound_file\" &"
;;
esac
}
# --- Install sounds ---
install_sounds() {
info "Installing sound files to $SOUNDS_DIR"
mkdir -p "$SOUNDS_DIR"
if [ -d "$SCRIPT_DIR/sounds" ] && [ "$(ls -A "$SCRIPT_DIR/sounds" 2>/dev/null)" ]; then
cp "$SCRIPT_DIR/sounds/"*.wav "$SCRIPT_DIR/sounds/"*.aiff "$SCRIPT_DIR/sounds/"*.oga "$SOUNDS_DIR/" 2>/dev/null || true
ok "Custom sounds installed"
fi
# Fallback: copy system sounds if no custom sounds exist
if [ ! "$(ls -A "$SOUNDS_DIR" 2>/dev/null)" ]; then
case "$(uname -s)" in
Linux*)
for src in \
"/usr/share/sounds/sound-icons/prompt.wav" \
"/usr/share/sounds/freedesktop/stereo/bell.oga" \
"/usr/share/sounds/freedesktop/stereo/complete.oga"; do
if [ -f "$src" ]; then
cp "$src" "$SOUNDS_DIR/"
ok "Copied system sound: $(basename "$src")"
break
fi
done
;;
Darwin*)
for src in \
"/System/Library/Sounds/Ping.aiff" \
"/System/Library/Sounds/Glass.aiff" \
"/System/Library/Sounds/Pop.aiff"; do
if [ -f "$src" ]; then
cp "$src" "$SOUNDS_DIR/"
ok "Copied system sound: $(basename "$src")"
break
fi
done
;;
esac
fi
# Pick the first available sound
SOUND_FILE=""
for ext in wav aiff oga; do
for f in "$SOUNDS_DIR"/*."$ext"; do
if [ -f "$f" ]; then
SOUND_FILE="$f"
break 2
fi
done
done
if [ -z "$SOUND_FILE" ]; then
err "No sound files found. Please place a .wav file in $SOUNDS_DIR"
exit 1
fi
ok "Using sound: $SOUND_FILE"
}
# --- Merge hooks into settings.json ---
merge_settings() {
local play_cmd="$1"
info "Updating Claude Code settings at $SETTINGS_FILE"
mkdir -p "$(dirname "$SETTINGS_FILE")"
# Create settings file if it doesn't exist
if [ ! -f "$SETTINGS_FILE" ]; then
echo '{}' > "$SETTINGS_FILE"
fi
# Check if a claude-code-sounds hook specifically already exists
if node "$HELPER" has-sound-hook; then
warn "A claude-code-sounds hook already exists in settings"
if [ "$AUTO_YES" = true ]; then
answer="y"
else
read -rp "Replace existing sound hook? [y/N] " answer
fi
if [[ ! "$answer" =~ ^[Yy]$ ]]; then
info "Skipping hook installation. Your settings were not modified."
return
fi
node "$HELPER" remove-sound-hook
fi
# Add the sound hook (appends to existing PermissionRequest hooks)
node "$HELPER" add-sound-hook "$play_cmd"
ok "Hooks merged into $SETTINGS_FILE"
}
# --- Test the sound ---
test_sound() {
local player="$1"
local sound_file="$2"
info "Testing sound..."
case "$player" in
powershell.exe)
powershell.exe -c "(New-Object Media.SoundPlayer \"$sound_file\").PlaySync()" &
;;
"ffplay -nodisp -autoexit")
ffplay -nodisp -autoexit "$sound_file" &
;;
*)
$player "$sound_file" &
;;
esac
wait 2>/dev/null || true
ok "Sound played! If you didn't hear anything, check your audio settings."
}
# --- Main ---
main() {
# Parse flags
while [[ $# -gt 0 ]]; do
case "$1" in
-y|--yes) AUTO_YES=true; shift ;;
*) shift ;;
esac
done
echo ""
echo -e "${GREEN}claude-code-sounds${NC} installer"
echo "================================"
echo ""
# Detect audio player
PLAYER=$(detect_player)
if [ -z "$PLAYER" ]; then
err "No supported audio player found."
echo "Install one of: paplay, aplay, ffplay (Linux) | afplay (macOS)"
exit 1
fi
ok "Found audio player: $PLAYER"
# Install sound files
install_sounds
# Build play command
PLAY_CMD=$(build_play_command "$SOUND_FILE" "$PLAYER")
info "Play command: $PLAY_CMD"
# Test
test_sound "$PLAYER" "$SOUND_FILE"
# Merge into settings
merge_settings "$PLAY_CMD"
# Copy uninstall tooling to ~/.claude so it survives repo deletion
cp "$HELPER" "$HOME/.claude/"
cp "$SCRIPT_DIR/uninstall.sh" "$HOME/.claude/uninstall-sounds.sh"
chmod +x "$HOME/.claude/uninstall-sounds.sh"
echo ""
ok "Installation complete!"
echo ""
echo " Claude Code will now play a sound on permission prompts."
echo " Sound file: $SOUND_FILE"
echo " Settings: $SETTINGS_FILE"
echo ""
echo " To customize, edit $SETTINGS_FILE or replace sounds in $SOUNDS_DIR"
echo " To uninstall, run: ~/.claude/uninstall-sounds.sh"
echo ""
}
main "$@"