-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-path.sh
More file actions
executable file
·145 lines (123 loc) · 5.05 KB
/
fix-path.sh
File metadata and controls
executable file
·145 lines (123 loc) · 5.05 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
#!/bin/zsh
# Fix PATH issues in shell environment
# This script diagnoses and fixes PATH corruption issues
echo "╔════════════════════════════════════════════════════════════════════╗"
echo "║ AINISH-CODER PATH DIAGNOSTIC & FIX TOOL ║"
echo "╚════════════════════════════════════════════════════════════════════╝"
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo "${BLUE}[1/5] Checking current PATH...${NC}"
echo "Current PATH: ${PATH:-<EMPTY>}"
echo ""
# Standard paths that should always be present
STANDARD_PATHS=(
"/usr/local/bin"
"/usr/bin"
"/bin"
"/usr/sbin"
"/sbin"
)
echo "${BLUE}[2/5] Checking for standard directories in PATH...${NC}"
missing_paths=()
for std_path in "${STANDARD_PATHS[@]}"; do
if [[ ":$PATH:" == *":$std_path:"* ]]; then
echo "${GREEN}✓${NC} $std_path found in PATH"
else
echo "${RED}✗${NC} $std_path MISSING from PATH"
missing_paths+=("$std_path")
fi
done
echo ""
echo "${BLUE}[3/5] Testing basic commands...${NC}"
commands_to_test=("mkdir" "date" "git" "dirname" "cp" "mv" "rm")
failed_commands=()
for cmd in "${commands_to_test[@]}"; do
if command -v "$cmd" &> /dev/null; then
echo "${GREEN}✓${NC} $cmd: $(command -v $cmd)"
else
echo "${RED}✗${NC} $cmd: NOT FOUND"
failed_commands+=("$cmd")
fi
done
echo ""
# If there are issues, offer to fix
if [ ${#missing_paths[@]} -gt 0 ] || [ ${#failed_commands[@]} -gt 0 ]; then
echo "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo "${RED} PATH IS CORRUPTED!${NC}"
echo "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "${YELLOW}Missing paths: ${missing_paths[*]}${NC}"
echo "${YELLOW}Failed commands: ${failed_commands[*]}${NC}"
echo ""
echo "${BLUE}[4/5] Generating fix...${NC}"
# Build a comprehensive PATH
FIXED_PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
# Add Homebrew if it exists
if [ -d "/opt/homebrew/bin" ]; then
FIXED_PATH="/opt/homebrew/bin:$FIXED_PATH"
fi
# Add user bin directories
if [ -d "$HOME/bin" ]; then
FIXED_PATH="$HOME/bin:$FIXED_PATH"
fi
if [ -d "$HOME/.local/bin" ]; then
FIXED_PATH="$HOME/.local/bin:$FIXED_PATH"
fi
# Add ainish-coder
if [ -d "$HOME/code/ainish-coder/bin" ]; then
FIXED_PATH="$HOME/code/ainish-coder/bin:$FIXED_PATH"
fi
# Add Cursor if it exists
if [ -d "/Applications/Cursor.app/Contents/Resources/app/bin" ]; then
FIXED_PATH="/Applications/Cursor.app/Contents/Resources/app/bin:$FIXED_PATH"
fi
# Add Windsurf if it exists
if [ -d "$HOME/.codeium/windsurf/bin" ]; then
FIXED_PATH="$HOME/.codeium/windsurf/bin:$FIXED_PATH"
fi
echo ""
echo "${GREEN}Recommended PATH:${NC}"
echo "$FIXED_PATH"
echo ""
echo "${BLUE}[5/5] Applying fix...${NC}"
echo ""
echo "${YELLOW}To apply this fix, run the following command:${NC}"
echo ""
echo " ${GREEN}export PATH=\"$FIXED_PATH\"${NC}"
echo ""
echo "${YELLOW}To make this permanent, add this line to your ~/.zshrc:${NC}"
echo ""
echo " ${GREEN}# Fix PATH (added $(date '+%Y-%m-%d'))${NC}"
echo " ${GREEN}export PATH=\"$FIXED_PATH\"${NC}"
echo ""
echo "${YELLOW}Then reload your shell:${NC}"
echo ""
echo " ${GREEN}source ~/.zshrc${NC}"
echo ""
# Create a source-able fix file
cat > /tmp/path-fix.sh << EOF
# PATH fix generated by ainish-coder fix-path.sh
# Generated: $(date)
export PATH="$FIXED_PATH"
EOF
echo "${GREEN}✓${NC} Quick fix saved to: ${BLUE}/tmp/path-fix.sh${NC}"
echo ""
echo "${YELLOW}To apply immediately, run:${NC}"
echo " ${GREEN}source /tmp/path-fix.sh${NC}"
echo ""
else
echo "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo "${GREEN} PATH IS HEALTHY!${NC}"
echo "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "All standard directories are present in PATH."
echo "All basic commands are accessible."
fi
echo ""
echo "${BLUE}[DONE] Diagnostic complete.${NC}"
echo ""