-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclauder.sh
More file actions
executable file
·184 lines (156 loc) · 5.42 KB
/
Copy pathclauder.sh
File metadata and controls
executable file
·184 lines (156 loc) · 5.42 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
#!/bin/bash
# Script to run Claude with all security checks and customizations
# This ensures cross-shell compatibility and proper argument handling
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check if CLAUDER_DIR is set, otherwise use script directory
if [[ -z "$CLAUDER_DIR" ]]; then
CLAUDER_DIR="$SCRIPT_DIR"
fi
# Paths to various scripts and files
BANNER_SCRIPT="$CLAUDER_DIR/clauder_banner.sh"
BANNER_FILE="$CLAUDER_DIR/assets/clauder_banner.txt"
UPDATE_SCRIPT="$CLAUDER_DIR/clauder_update_check.sh"
SECURITY_SCRIPT="$CLAUDER_DIR/clauder_security_check.sh"
FOOTER_FILE="$CLAUDER_DIR/assets/clauder_footer.txt"
# Function to display footer
clauder_footer() {
if [[ -f "$FOOTER_FILE" ]]; then
local footer_content="$(cat "$FOOTER_FILE")"
echo -e "$footer_content"
fi
}
# Function to check if colors are supported
colors_supported() {
# Check if we're in a terminal and colors are supported
if [[ -t 1 ]] && command -v tput >/dev/null 2>&1 && [[ $(tput colors 2>/dev/null) -ge 8 ]]; then
return 0
else
return 1
fi
}
# Function to print text in gray
print_gray() {
if colors_supported; then
echo -n "$(tput setaf 8)$1$(tput sgr0)"
else
echo -n "$1"
fi
}
# Function to source shell configuration files
source_shell_configs() {
# print_gray "Sourcing terminal configuration.."
# echo ""
# Define shell configuration files
local shell_files=("$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile" "$HOME/.zshrc")
for shell_file in "${shell_files[@]}"; do
if [ -f "$shell_file" ]; then
local display_path="${shell_file/#$HOME/~}"
if . "$shell_file" >/dev/null 2>&1; then
# Silently source successful files
:
else
print_gray " ⚠ Failed to source $display_path"
fi
fi
done
# Reset color to default
if colors_supported; then
echo -n "$(tput sgr0)"
fi
echo ""
}
# Check if required files exist
if [[ ! -f "$BANNER_SCRIPT" ]]; then
echo "Error: Banner script not found at $BANNER_SCRIPT"
exit 1
fi
if [[ ! -f "$UPDATE_SCRIPT" ]]; then
echo "Error: Update check script not found at $UPDATE_SCRIPT"
exit 1
fi
if [[ ! -f "$SECURITY_SCRIPT" ]]; then
echo "Error: Security check script not found at $SECURITY_SCRIPT"
exit 1
fi
# Run the banner script
if [[ -f "$BANNER_FILE" ]]; then
bash "$BANNER_SCRIPT" "$BANNER_FILE"
fi
# Source shell configuration files before update check
source_shell_configs
# Run the update check script
bash "$UPDATE_SCRIPT"
# Source shell configuration files after update check
source_shell_configs
# Run the security check script and capture exit code
bash "$SECURITY_SCRIPT"
security_exit_code=$?
# Check if security check failed with codes 1 or 2
if [[ $security_exit_code -eq 1 || $security_exit_code -eq 2 ]]; then
echo "Security check failed. Aborting execution."
exit $security_exit_code
fi
# Display footer
clauder_footer
# Display active MCP servers
display_mcp_servers() {
echo ""
print_gray "Active MCP servers:"
echo ""
if command -v claude >/dev/null 2>&1; then
local mcp_output=$(claude mcp list 2>/dev/null)
if [ $? -eq 0 ] && [ -n "$mcp_output" ]; then
# Check if the output indicates no servers configured
if echo "$mcp_output" | grep -qi "no mcp servers configured"; then
print_gray "⌀ (none)"
else
# Filter out header lines and count servers
local server_lines=$(echo "$mcp_output" | grep -E '^[a-zA-Z0-9_-][a-zA-Z0-9_-]*:')
local server_count=$(echo "$server_lines" | wc -l)
if [ "$server_count" -eq 0 ]; then
print_gray "⌀ (none)"
else
# Process each server line
echo "$server_lines" | while IFS= read -r line; do
local server_name=$(echo "$line" | sed 's/:.*$//')
local server_status=$(echo "$line" | sed 's/^[^:]*: *//')
# Check if the status contains "Connected" (case insensitive)
if echo "$server_status" | grep -qi "connected"; then
if colors_supported; then
echo -e "$(tput setaf 2)✓$(tput sgr0) $(tput setaf 8)$server_name$(tput sgr0)"
else
echo "✓ $server_name"
fi
else
if colors_supported; then
echo -e "$(tput setaf 1)✗$(tput sgr0) $(tput setaf 8)$server_name$(tput sgr0)"
else
echo "✗ $server_name"
fi
fi
done
fi
fi
echo ""
echo ""
else
print_gray "⌀ (none)"
echo ""
echo ""
fi
else
print_gray "⌀ (none)"
echo ""
echo ""
fi
}
display_mcp_servers
echo ""
echo ""
# Pause and wait for user to press any key
echo -n "Press any key to start... "
read -n 1 -s
echo ""
# Finally, run Claude with all forwarded arguments
claude "$@"