-
Notifications
You must be signed in to change notification settings - Fork 20
/
bin-path
executable file
·42 lines (36 loc) · 880 Bytes
/
bin-path
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
#!/bin/bash
dir="`pwd`"
cd "$(dirname "$0")"
home="`pwd`"
cd "${dir}"
old="$1"
new="$2"
if [ -z "${old}" ]; then
echo "${home}"
exit 0
fi
found="$(echo "`llbin "${new}"`" | grep -i "^${new}$" | firstline)"
script="`which "${found}"`"
scriptdir="$(dirname "${script}")"
if [ -e "${script}" ]; then
1>&2 echo "${new} already exists at ${script}"
if [ -z "${noedit}" ]; then
1>&2 echo "Opening it in an editor..."
fi
else
found="$(echo "`llbin "${old}"`" | grep -i "^${old}$" | firstline)"
if [ -z "${found}" ]; then
1>&2 echo "No such scriptfile: ${old}"
exit 1
fi
script="`which "${found}"`"
scriptdir="$(dirname "${script}")"
cp "${script}" "${scriptdir}/${new}"
if [ ! -t 0 ]; then
cat > "${scriptdir}/${new}"
fi
echo "\"${script}\" => \"${scriptdir}/${new}\""
fi
if [ -z "${noedit}" ]; then
exec edit "${scriptdir}/${new}"
fi