Skip to content
Snippets Groups Projects
Commit f733e69f authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Changed filters for .pro and .sch

parent 5e60638e
No related branches found
No related tags found
No related merge requests found
*~
#!/bin/sh #!/bin/bash
shopt -s nullglob shopt -s nullglob
kicad-sch-filter() {
cat $(realpath $(dirname $0)/kicad-sch-filter)
}
kicad-pro-filter() {
cat $(realpath $(dirname $0)/kicad-pro-filter)
}
mkdir -p ~/.config/git
for s in kicad-pro-filter kicad-sch-filter ; do
if ! declare -f -F $s > /dev/null ; then
echo "${s} not defined"
continue
fi
if [ ! -f ~/.config/git/${s} ] ; then
echo "Creating ~/.config/git/${s}"
cat <($s) > ~/.config/git/${s}
chmod +x ~/.config/git/${s}
elif ! diff <($s) <(cat ~/.config/git/${s}) > /dev/null ; then
echo "Updating ~/.config/git/${s}"
cat <($s) > ~/.config/git/${s}
chmod +x ~/.config/git/${s}
fi
done
SCHEMATICS=( *.sch ) SCHEMATICS=( *.sch )
if [ ${#SCHEMATICS[*]} -eq 0 ] ; then if [ ${#SCHEMATICS[*]} -eq 0 ] ; then
echo "No schematic file(s) in directory" >&2 echo "No schematic file(s) in directory" >&2
...@@ -35,8 +60,9 @@ for i in "${GITIGNORE[@]}" ; do ...@@ -35,8 +60,9 @@ for i in "${GITIGNORE[@]}" ; do
done done
# Install filtering (see https://jnavila.github.io/plotkicadsch/) # Install filtering (see https://jnavila.github.io/plotkicadsch/)
GITATTRIBUTES=( "*.pro filter=kicad_pro" ) GITATTRIBUTES+=( "*.pro filter=kicad-pro" )
GITATTRIBUTES+=( "*.sch filter=kicad_sch" ) GITATTRIBUTES+=( "*.sch ident" )
GITATTRIBUTES+=( "*.sch filter=kicad-sch" )
if [ ! -f .gitattributes ] ; then if [ ! -f .gitattributes ] ; then
touch .gitattributes touch .gitattributes
fi fi
...@@ -45,10 +71,10 @@ for a in "${GITATTRIBUTES[@]}" ; do ...@@ -45,10 +71,10 @@ for a in "${GITATTRIBUTES[@]}" ; do
echo "${a}" >> .gitattributes echo "${a}" >> .gitattributes
fi fi
done done
FILTER=( "filter.kicad_pro.clean sed -E 's/^update=.*$/update=Date/'" ) FILTER=( "filter.kicad-pro.clean ~/.config/git/kicad-pro-filter clean %f" )
FILTER+=( "filter.kicad_pro.smudge cat" ) FILTER+=( "filter.kicad-pro.smudge ~/.config/git/kicad-pro-filter smudge %f" )
FILTER+=( "filter.kicad_sch.clean sed -E 's/#(PWR|FLG)[0-9]+/#\1?/'" ) FILTER+=( "filter.kicad-sch.clean ~/.config/git/kicad-sch-filter clean %f" )
FILTER+=( "filter.kicad_sch.smudge cata" ) FILTER+=( "filter.kicad-sch.smudge ~/.config/git/kicad-sch-filter smudge %f" )
for f in "${FILTER[@]}" ; do for f in "${FILTER[@]}" ; do
if [[ "$f" =~ ([^\ ]+)[\ ]+(.*) ]] ; then if [[ "$f" =~ ([^\ ]+)[\ ]+(.*) ]] ; then
KEY=${BASH_REMATCH[1]} KEY=${BASH_REMATCH[1]}
......
#!/usr/bin/python3
import sys
import re
def clean(filename):
for line in sys.stdin:
line = line[0:-1]
m = re.match('^#\$Id[^\$]*\$$', line)
if m:
continue
m = re.match('^(update|last_client)=', line)
if m:
print("%s=" % m.group(1))
continue
m = re.match('^\[([^\]]*)\]', line)
if m:
key = m.group(1)
break
print(line)
section = {}
section[key] = []
for line in sys.stdin:
line = line[0:-1]
m = re.match('^\[([^\]]*)\]', line)
if m:
key = m.group(1)
section[key] = []
continue
section[key].append(line)
for k in sorted(section.keys()):
print('[%s]' % k)
for line in section[k]:
print(line)
def smudge(filename):
for line in sys.stdin:
line = line[0:-1]
m = re.match('^#\$Id[^\$]*\$$', line)
if m:
continue
print(line)
if __name__ == '__main__':
if sys.argv[1] == 'clean':
clean(sys.argv[2])
elif sys.argv[1] == 'smudge':
smudge(sys.argv[2])
else:
raise Exception("Unknown command '%s' on '%s'",
sys.argv[1], sys.argv[2])
#!/bin/bash
clean() {
IFS= read -r LINE
if [[ "${LINE}" =~ ^(EESchema.*[^\ ])[\ ]*\#(\$Id.*\$)$ ]] ; then
echo "${BASH_REMATCH[1]} #${BASH_REMATCH[2]}"
elif [[ "${LINE}" =~ ^(EESchema[^\#\$]*[^\ ])[\ ]*$ ]] ; then
echo "${BASH_REMATCH[1]} #\$Id\$"
else
echo "Unknown schema type '${LINE}'" 1>&2
exit 1
fi
(
while IFS= read -r LINE ; do
if [[ "${LINE}" =~ ^((Rev|Date)\ \").*(\") ]] ; then
# Clean out revision and date
echo "${BASH_REMATCH[1]}${BASH_REMATCH[3]}"
else
echo "${LINE}"
fi
done
) | sed -E 's/#(PWR|FLG)[0-9]+/#\1?/'
}
smudge() {
local REV="Unknown"
local DATE="Unknown"
local HASH=
IFS= read -r LINE
if [[ "${LINE}" =~ ^EESchema.*\#\$Id:(.*)\$ ]] ; then
local HASH=${BASH_REMATCH[1]}
REV=$(git describe ${HASH} 2>/dev/null | sed -e 's/:.*//')
if [ -z "${REV}" ] ; then
REV="g$(git describe --always ${HASH} | sed -e 's/:.*//')"
fi
DATE=$(git log --format="%ai" -- "$1" | head -1)
if [ -z "${DATE}" ] ; then
DATE="Unknown2"
fi
echo "${LINE}"
elif [[ "${LINE}" =~ ^EESchema.* ]] ; then
echo "${LINE}"
else
echo "Unknown schema type '${LINE}'" 1>&2
exit 1
fi
while IFS= read -r LINE; do
if [[ "${LINE}" =~ ^(Rev\ \").*(\") ]] ; then
echo "${BASH_REMATCH[1]}${REV}${BASH_REMATCH[2]}"
elif [[ "${LINE}" =~ ^(Date\ \").*(\") ]] ; then
echo "${BASH_REMATCH[1]}${DATE}${BASH_REMATCH[2]}"
else
echo "${LINE}"
fi
done
}
case "$1" in
clean)
clean $2
;;
smudge)
smudge $2
;;
*)
echo "unknown command '$1'" 1>&2
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment