Skip to content

Commit

Permalink
Fallback to readlink -f on macOS
Browse files Browse the repository at this point in the history
BSD coreutils readlink doesn't have -f option, so
adding a Python one-liner feedback to eval symlinks/homedir.
Fixes #8.

Signed-off-by: Ahmet Alp Balkan <[email protected]>
  • Loading branch information
ahmetb committed May 17, 2017
1 parent 7e10232 commit 8e413fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion kubectx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
set -eou pipefail
IFS=$'\n\t'

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")"

if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then
source "${SCRIPT_DIR}/utils.bash"
else
Expand Down
4 changes: 3 additions & 1 deletion kubens
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
set -eou pipefail
IFS=$'\n\t'

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")"

if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then
source "${SCRIPT_DIR}/utils.bash"
else
Expand Down

0 comments on commit 8e413fc

Please sign in to comment.