-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-profiles.sh
More file actions
176 lines (147 loc) · 5.28 KB
/
setup-profiles.sh
File metadata and controls
176 lines (147 loc) · 5.28 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
#!/bin/bash
# Script to create VS Code profiles with extensions
# Each profile includes common extensions + specific ones
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
GRAY='\033[0;90m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Parse command line arguments
DRY_RUN=false
if [[ "$1" == "--dry-run" ]] || [[ "$1" == "-d" ]]; then
DRY_RUN=true
fi
# Function to read extensions from a file
get_extensions() {
local file_path="$1"
local extensions=()
if [[ -f "$file_path" ]]; then
while IFS= read -r line; do
# Trim whitespace and skip empty lines
line=$(echo "$line" | xargs)
if [[ -n "$line" ]]; then
extensions+=("$line")
fi
done < "$file_path"
fi
echo "${extensions[@]}"
}
# Function to create a profile and install extensions
create_profile() {
local profile_name="$1"
shift
local extensions=("$@")
echo ""
echo -e "${CYAN}========================================${NC}"
echo -e "${CYAN}Creating profile: $profile_name${NC}"
echo -e "${CYAN}========================================${NC}"
if [[ "$DRY_RUN" == true ]]; then
echo -e "${YELLOW}[DRY RUN] Would create profile '$profile_name'${NC}"
echo -e "${YELLOW}[DRY RUN] Extensions to install: ${#extensions[@]}${NC}"
for ext in "${extensions[@]}"; do
echo -e "${GRAY} - $ext${NC}"
done
return
fi
# Create the profile
echo -e "${GREEN}Creating profile '$profile_name'...${NC}"
code --profile "$profile_name" --new-window --wait &
sleep 2
# Install extensions
echo ""
echo -e "${GREEN}Installing ${#extensions[@]} extensions...${NC}"
local installed=0
local failed=0
for extension in "${extensions[@]}"; do
echo -e "${GRAY} Installing: $extension${NC}"
if code --profile "$profile_name" --install-extension "$extension" --force > /dev/null 2>&1; then
((installed++))
echo -e "${GREEN} ✓ Installed${NC}"
else
((failed++))
echo -e "${RED} ✗ Failed${NC}"
fi
done
echo ""
echo -e "${CYAN}Summary for profile '$profile_name':${NC}"
echo -e "${GREEN} Installed: $installed${NC}"
if [[ $failed -gt 0 ]]; then
echo -e "${RED} Failed: $failed${NC}"
else
echo -e "${GREEN} Failed: $failed${NC}"
fi
}
# Main Script
echo -e "${MAGENTA}========================================${NC}"
echo -e "${MAGENTA}VS Code Profiles Setup${NC}"
echo -e "${MAGENTA}========================================${NC}"
# Read common extensions
common_extensions=($(get_extensions "./extensions-common.txt"))
echo ""
echo -e "${YELLOW}Common extensions: ${#common_extensions[@]}${NC}"
# Automatically discover all extension files (excluding common)
shopt -s nullglob
extension_files=(./extensions-*.txt)
shopt -u nullglob
# Remove common from the list
filtered_files=()
for file in "${extension_files[@]}"; do
if [[ "$file" != "./extensions-common.txt" ]]; then
filtered_files+=("$file")
fi
done
if [[ ${#filtered_files[@]} -eq 0 ]]; then
echo ""
echo -e "${RED}No profile extension files found!${NC}"
echo -e "${YELLOW}Create files named 'extensions-<ProfileName>.txt' to define profiles.${NC}"
exit 1
fi
echo -e "${YELLOW}Found ${#filtered_files[@]} profile(s) to create${NC}"
echo ""
# Build profiles associative array from discovered files
declare -A profiles
for file in "${filtered_files[@]}"; do
# Extract profile name from filename (e.g., "extensions-python.txt" -> "python")
filename=$(basename "$file")
profile_name="${filename#extensions-}"
profile_name="${profile_name%.txt}"
# Replace dashes and underscores with spaces, convert to lowercase first
profile_name=$(echo "$profile_name" | tr '_-' ' ' | tr '[:upper:]' '[:lower:]')
# Capitalize first letter of each word
profile_name=$(echo "$profile_name" | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1')
profiles["$profile_name"]="$file"
echo -e "${GRAY} - $profile_name${NC}"
done
# Create each profile
for profile_name in "${!profiles[@]}"; do
# Read specific extensions
specific_extensions=($(get_extensions "${profiles[$profile_name]}"))
# Combine common + specific (remove duplicates)
all_extensions=("${common_extensions[@]}" "${specific_extensions[@]}")
# Remove duplicates using associative array
declare -A unique_extensions
for ext in "${all_extensions[@]}"; do
unique_extensions["$ext"]=1
done
# Convert back to array
final_extensions=("${!unique_extensions[@]}")
# Create the profile
create_profile "$profile_name" "${final_extensions[@]}"
# Clean up for next iteration
unset unique_extensions
done
echo ""
echo -e "${MAGENTA}========================================${NC}"
echo -e "${MAGENTA}Setup completed!${NC}"
echo -e "${MAGENTA}========================================${NC}"
echo ""
echo -e "${CYAN}To use a profile, run:${NC}"
echo -e "${WHITE} code --profile \"Profile Name\"${NC}"
echo ""
echo -e "${CYAN}Example:${NC}"
echo -e "${WHITE} code --profile Python${NC}"
echo -e "${WHITE} code --profile Java${NC}"