-
Notifications
You must be signed in to change notification settings - Fork 35
/
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/7a2735f6f8c8ed02d058c1a6a2f04846a3d88cad/\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=7a2735f6f8c8ed02d058c1a6a2f04846a3d88cad')"
grep "$(pwd)" -rl examples/* | while IFS= read -r file; do
root="$(get_root "$file")"
sedi -E "s/${root//./\.}\/([^ ]*)/${DIR_PATTERN}/g" "${file}"
done