From 8e413fc8ac75bae6fdba9dbd170019db6efec020 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 17 May 2017 09:35:35 -0700 Subject: [PATCH] Fallback to readlink -f on macOS 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 --- kubectx | 4 +++- kubens | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kubectx b/kubectx index 9434742f..f6d7574a 100755 --- a/kubectx +++ b/kubectx @@ -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 diff --git a/kubens b/kubens index 9fa5500a..59b074cd 100755 --- a/kubens +++ b/kubens @@ -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