forked from Parli/node-simple-server-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-notifications.sh
More file actions
61 lines (52 loc) · 1.79 KB
/
setup-notifications.sh
File metadata and controls
61 lines (52 loc) · 1.79 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
#!/bin/bash
# Setup automatic notifications for Claude Code
# This adds a function to your shell that triggers notifications when commands finish
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Function to add to shell profile
NOTIFICATION_FUNCTION='
# Claude Code notification function
claude_notify() {
local exit_code=$?
if [[ -x "'$SCRIPT_DIR'/notify.sh" ]]; then
bash "'$SCRIPT_DIR'/notify.sh" "Command finished. Ready for input!"
fi
return $exit_code
}
# Automatically notify when any command finishes (if it takes more than 2 seconds)
claude_auto_notify() {
local start_time=$(date +%s)
"$@"
local exit_code=$?
local end_time=$(date +%s)
local duration=$((end_time - start_time))
if [[ $duration -gt 2 ]]; then
claude_notify
fi
return $exit_code
}
# Alias for claude command with auto-notification
alias claude-with-notify="claude_auto_notify claude"
'
# Detect shell and add to appropriate profile
if [[ "$SHELL" == */bash ]]; then
PROFILE_FILE="$HOME/.bashrc"
elif [[ "$SHELL" == */zsh ]]; then
PROFILE_FILE="$HOME/.zshrc"
else
PROFILE_FILE="$HOME/.profile"
fi
echo "Adding notification functions to $PROFILE_FILE"
# Check if already added
if ! grep -q "claude_notify()" "$PROFILE_FILE" 2>/dev/null; then
echo "" >> "$PROFILE_FILE"
echo "# Claude Code notifications" >> "$PROFILE_FILE"
echo "$NOTIFICATION_FUNCTION" >> "$PROFILE_FILE"
echo "Notification functions added to $PROFILE_FILE"
echo "Run 'source $PROFILE_FILE' or restart your terminal to enable."
echo ""
echo "Usage:"
echo " claude-with-notify # Run claude with auto-notifications"
echo " claude_notify # Manual notification trigger"
else
echo "Notification functions already present in $PROFILE_FILE"
fi