Skip to content

Instantly share code, notes, and snippets.

@DanielG
Created October 23, 2016 21:01
Show Gist options
  • Save DanielG/a7c89fb530669e9abb18ef74ecf106a1 to your computer and use it in GitHub Desktop.
Save DanielG/a7c89fb530669e9abb18ef74ecf106a1 to your computer and use it in GitHub Desktop.
Split KiCad schematic library into multiple files
################################################################################
# #
# Split KiCad EESchema library file into one file per part #
# #
# Copyright (C) 2016 Daniel Gröber <dxld@darkboxed.org> #
# #
# Copying and distribution of this file, with or without modification, #
# are permitted in any medium without royalty provided the copyright #
# notice and this notice are preserved. This file is offered as-is, #
# without any warranty. #
# #
# Usage: sh split-kicad-lib.sh LIB OUTPUT_DIR #
# #
# Example: #
# $ mkdir klib/ #
# $ sh split-kicad-lib.sh stm32.lib klib/ #
# #
# Now klib/ will contain one file per part defined in stm32.lib and symlinks #
# for any aliases the parts define. #
# #
################################################################################
LIB=$1; shift
ODIR=$1; shift
if [ -z "$LIB" -o -z "$ODIR" ]; then
echo "Usage: $0 LIB OUTPUT_DIR"
exit 1
fi
cat "$LIB" | tr -d '\r' | awk \
'
BEGIN { file = ""; };
/^DEF\>/ {
file = $2;
print "" > "'"$ODIR"'/" file;
};
/^ENDDEF\>/ {
file = "";
};
file && /^ALIAS\>/ {
system("ln -s " file " '"$ODIR"'/" $2);
};
file != "" { print $0 >> "'"$ODIR"'/" file }
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment