Skip to content

Commit 9bf1130

Browse files
authored
Merge pull request #21 from kamatama41/fix-patch-1
Fix symlinking support
2 parents 0979ee0 + 8e2077d commit 9bf1130

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Currently tfenv supports the following OSes
2525
fi
2626
```
2727

28+
OR you can make a symlink into a path that is already added to your `$PATH`
29+
30+
```
31+
ln -s /some/path/to/tfenv/bin/tfenv /usr/local/bin/tfenv
32+
```
33+
2834
## Usage
2935
### tfenv install
3036
Install a specific version of Terraform

bin/tfenv

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ if [ -n "$TFENV_DEBUG" ]; then
55
set -x
66
fi
77

8+
# http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
9+
readlink_f() {
10+
local target_file=$1
11+
local file_name
12+
13+
while [ "$target_file" != "" ]; do
14+
cd $(dirname ${target_file})
15+
file_name=$(basename ${target_file})
16+
target_file=$(readlink ${file_name})
17+
done
18+
19+
echo $(pwd -P)/${file_name}
20+
}
21+
822
if [ -z "${TFENV_ROOT}" ]; then
9-
TFENV_ROOT=$(cd $(dirname $0)/.. && pwd)
23+
TFENV_ROOT=$(cd $(dirname $(readlink_f $0))/.. && pwd)
1024
else
1125
TFENV_ROOT="${TFENV_ROOT%/}"
1226
fi

libexec/tfenv---version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
set -e
1313
[ -n "$TFENV_DEBUG" ] && set -x
1414

15-
version="0.3.1"
15+
version="0.3.2"
1616
git_revision=""
1717

1818
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q tfenv; then

test/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if [ -n "$TFENV_DEBUG" ]; then
44
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
55
set -x
66
fi
7-
export TFENV_ROOT=$(cd $(dirname $0)/.. && pwd)
7+
TFENV_ROOT=$(cd $(dirname $0)/.. && pwd)
88
export PATH="${TFENV_ROOT}/bin:${PATH}"
99

1010
errors=()

test/test_install_and_use.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ check_version() {
88
}
99

1010
echo "### Install latest version"
11-
rm -rf ${TFENV_ROOT}/versions
12-
rm -rf ${TFENV_ROOT}/.terraform-version
11+
rm -rf ./versions
12+
rm -rf ./.terraform-version
1313

1414
v=$(tfenv list-remote | head -n 1)
1515
tfenv install latest
@@ -20,8 +20,8 @@ if ! check_version ${v}; then
2020
fi
2121

2222
echo "### Install specific version"
23-
rm -rf ${TFENV_ROOT}/versions
24-
rm -rf ${TFENV_ROOT}/.terraform-version
23+
rm -rf ./versions
24+
rm -rf ./.terraform-version
2525

2626
v=0.6.16
2727
tfenv install ${v}
@@ -32,11 +32,11 @@ if ! check_version ${v}; then
3232
fi
3333

3434
echo "### Install .terraform-version"
35-
rm -rf ${TFENV_ROOT}/versions
36-
rm -rf ${TFENV_ROOT}/.terraform-version
35+
rm -rf ./versions
36+
rm -rf ./.terraform-version
3737

3838
v=0.6.15
39-
touch ${TFENV_ROOT}/.terraform-version && echo ${v} > ${TFENV_ROOT}/.terraform-version
39+
echo ${v} > ./.terraform-version
4040
tfenv install
4141
if ! check_version ${v}; then
4242
echo "Installing .terraform-version ${v}" 1>&2

test/test_list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[ -n "$TFENV_DEBUG" ] && set -x
44

5-
rm -rf ${TFENV_ROOT}/versions
5+
rm -rf ./versions
66

77
echo "### List local versions"
88
for v in 0.6.2 0.6.16 0.7.0-rc4 0.7.0 0.8.0-beta2; do

test/test_symlink.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
[ -n "$TFENV_DEBUG" ] && set -x
4+
5+
TFENV_BIN_SYM=/tmp/tfenv
6+
rm -rf ${TFENV_BIN_SYM}
7+
ln -s ${PWD}/bin/tfenv ${TFENV_BIN_SYM}
8+
9+
echo "### Test supporting symlink"
10+
${TFENV_BIN_SYM} --help

0 commit comments

Comments
 (0)