-
Notifications
You must be signed in to change notification settings - Fork 18
/
importfix.sh
65 lines (57 loc) · 1.22 KB
/
importfix.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
#attempt to fix broken Go import paths as a consequence of forking the repo
#sanity check
[ "${GOPATH}" ] || fail 'Sorry you need to set GOPATH'
#fix sed for mactards (like me)
if [ $(uname) == 'darwin' ]
then
s='sed -E'
else
s='sed'
fi
# setup some functions
function fail {
echo "$@"
exit 42
}
function pathEscape {
echo "${@}" | sed -e 's/\//\\\//g'
}
function ZOMGDOIT {
# cross your fingers
for FILE in ${FLIST}
do
cat ${FILE} | sed -e "s/$(pathEscape ${OGPATH})/$(pathEscape ${OUR_PATH})/"> ${TMP} && mv ${TMP} ${FILE}
done
rm -f ${TMP}
}
function dryRun {
echo dryRun baby
for FILE in ${FLIST}
do
LINES=$(grep "${OGPATH}" ${FILE})
if [ -n "${LINES}" ]
then
echo "In file: ${FILE}:"
echo "${LINES}"| while read LINE
do
echo "I'd replace: ${LINE}"
echo "with: "$(echo ${LINE} | sed -e "s/$(pathEscape ${OGPATH})/$(pathEscape ${OUR_PATH})/")
done
echo
fi
done
}
#ok lets see here..
TMP='/tmp/SFTEMPFILE'
PACKAGE=$(basename $(pwd))
FLIST=$(find . -name '*.go')
MINUS_THIS="${GOPATH}/src/"
OGPATH=$(echo ${GOPATH}/src/github.com/djosephsen/lazlo| sed "s/$(pathEscape ${MINUS_THIS})//")
OUR_PATH=$(pwd | sed -e "s/$(pathEscape ${MINUS_THIS})//")
if [ -z ${1} ]
then
ZOMGDOIT
else
dryRun
fi