-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_symbols_list.sh
50 lines (39 loc) · 1.62 KB
/
gen_symbols_list.sh
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
#!/bin/bash
# Retrieve the script path
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
# Define the source and destination paths
clone_path="$SCRIPTPATH/symbols"
output_path="$SCRIPTPATH/symbols.txt"
# Clone the latest KiCAD footprints from repository if not already present
if [ ! -d "$clone_path" ]; then
git clone --depth 1 https://gitlab.com/kicad/libraries/kicad-symbols.git "$clone_path"
else
cd "$clone_path"
git pull
cd "$SCRIPTPATH"
fi
# Empty the output file
> "$output_path"
# Put a header in the output file
echo "# This file contains all the KiCad symbols available in the official library" >> "$output_path"
echo "# Generated by symbols.sh" >> "$output_path"
echo "# on $(date)" >> "$output_path"
# Iterate over all kicad_sym files and extract the symbol names
for file in $(find "$clone_path" -type f -name "*.kicad_sym"); do
# Extract the symbol name from the file
# This line give us something like: '(symbol "74LS574" ('
symbols=$(grep -oP "\(symbol \"(.+)\" \(" $file)
# Now we just need to extract the part from the quotes for each line
# This line give us something like: 74LS574
symbols=$(echo "$symbols" | sed "s|(symbol \"||" | sed "s|\" (||")
# Now prepend the filename to the symbol name
# This line give us something like: 74xx:74LS574
symbols=$(echo "$symbols" | sed "s|^|$file:|" | sed "s|$clone_path/||" | sed "s|.kicad_sym||" | sed "s|/|:|" )
# Sort symbols alphabetically
symbols=$(echo "$symbols" | sort)
if [ ! -z "$symbols" ]; then
echo "$symbols" >> "$output_path"
fi
done
echo "Found $(wc -l < "$output_path") symbols"