forked from networkservicemesh/deployments-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
to-ref.sh
executable file
·30 lines (25 loc) · 942 Bytes
/
to-ref.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
#!/bin/bash
if [[ "$OSTYPE" == "darwin"* ]]; then
sedi() { sed -i "" "$@"; }
else
sedi() { sed -i "$@"; }
fi
escape() {
echo "$1" | sed 's/\//\\\//g'
}
get_root() {
root="$(echo "$1" | sed 's/[^/]*$//g')"
root="$(echo "$(pwd)/${root}" | sed 's/[^/]*\//..\//g')"
root="$(echo "${root}$(pwd)" | sed 's/\/\//\//g')"
escape "${root}"
}
FILE_PATTERN="$(escape 'https://raw.githubusercontent.com/networkservicemesh/deployments-k8s/7786c2b60b48543d066828dd910a3ce3358f340d/\1')"
grep "$(pwd)" -rl examples/* | while IFS= read -r file; do
root="$(get_root "$file")"
sedi -E "s/${root//./\.}\/([^ ]*\.[a-z]+)/${FILE_PATTERN}/g" "${file}"
done
DIR_PATTERN="$(escape 'https://github.com/networkservicemesh/deployments-k8s/\1?ref=7786c2b60b48543d066828dd910a3ce3358f340d')"
grep "$(pwd)" -rl examples/* | while IFS= read -r file; do
root="$(get_root "$file")"
sedi -E "s/${root//./\.}\/([^ ]*)/${DIR_PATTERN}/g" "${file}"
done