Skip to content

Commit 0154011

Browse files
committed
Update findrefs.bash
1 parent f4fcdf7 commit 0154011

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

escape_xml.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
# ------------------------------------
3+
# Escapes '<' and '>' symbols for XML.
4+
#
5+
# For example:
6+
#
7+
# $ ./escape_xml.sh '<Master>'
8+
# &lt;Master&gt;
9+
# ------------------------------------
10+
echo "$1" | \
11+
sed 's/>/\&gt;/g' | \
12+
sed 's/</\&lt;/g'

findreferences.bash

Lines changed: 0 additions & 30 deletions
This file was deleted.

findrefs.bash

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# ----------------------------------------------
3+
# Find all references to a spreadsheet alias.
4+
# Third positional alias argument is optional.
5+
# Supports escaping '<' and '>' symbols for XML.
6+
# ----------------------------------------------
7+
if [ -z "$1" ] || [ -z "$2" ]; then
8+
echo "Usage: findrefs.bash <document> <spreadsheet> [alias]"
9+
exit 1
10+
fi
11+
12+
# https://unix.stackexchange.com/a/635518
13+
escape_xml="${0%/*}/escape_xml.sh"
14+
15+
freecad_documents=`find . -type f -name "*.FCStd"`
16+
document=$($escape_xml $1)
17+
spreadsheet=$($escape_xml $2)
18+
alias=$3
19+
20+
SAVEIFS=$IFS
21+
IFS=$(echo -en "\n\b")
22+
for freecad_document in $freecad_documents
23+
do
24+
result=$(zipgrep "$document#$spreadsheet.$alias" "$freecad_document")
25+
26+
if [ ! -z "$result" ]; then
27+
printf "$freecad_document\n"
28+
if [ ! -z "$result" ]; then
29+
echo $result | xargs | grep --color=auto $document#$spreadsheet.$alias
30+
fi
31+
printf "\n"
32+
fi
33+
done
34+
IFS=$SAVEIFS

0 commit comments

Comments
 (0)