aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/ksh.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-17 19:42:10 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-17 19:46:41 +1300
commit1739c457836732e51e18411bb6cbdac1672def7a (patch)
tree9fc5c9bc1c28e0f21fbb9d35a38d1a0580226372 /sh/shrc.d/ksh.sh
parentAdd a second version check to detect ksh (diff)
downloaddotfiles-1739c457836732e51e18411bb6cbdac1672def7a.tar.gz
dotfiles-1739c457836732e51e18411bb6cbdac1672def7a.zip
Improve ksh version test to catch ksh93s+
And hopefully all versions below
Diffstat (limited to 'sh/shrc.d/ksh.sh')
-rw-r--r--sh/shrc.d/ksh.sh26
1 files changed, 25 insertions, 1 deletions
diff --git a/sh/shrc.d/ksh.sh b/sh/shrc.d/ksh.sh
index 5e9fee3b..befa60ee 100644
--- a/sh/shrc.d/ksh.sh
+++ b/sh/shrc.d/ksh.sh
@@ -2,7 +2,31 @@
# configuration if it was defined or if we can find it. Bash and Zsh invoke
# their own rc files first, which I've written to then look for ~/.shrc; ksh
# does it the other way around.
-[ -n "$KSH_VERSION" ] || [ -n "${.sh.version}" ] || return
+
+# Unfortunately, this isn't very simple, because KSH_VERSION is set by PDKSH
+# and derivatives, and in ksh93t+ and above, but not in earlier versions of
+# ksh93.
+
+# If it's not already set, we'll try hard to set it to something before we
+# proceed ...
+if [ -z "$KSH_VERSION" ] ; then
+
+ # Do we have the '[[' builtin? Good start
+ command -v '[[' >/dev/null 2>&1 || return
+
+ # Use the '[[' builtin to test whether $.sh.version is set (yes, that's a
+ # real variable name)
+ [[ -v .sh.version ]] || return
+
+ # If it is, that's our KSH_VERSION
+ KSH_VERSION=${.sh.version}
+fi
+
+# If KSH_ENV isn't already set, set it
[ -n "$KSH_ENV" ] || KSH_ENV=$HOME/.kshrc
+
+# Check the file named in KSH_ENV exists
[ -f "$KSH_ENV" ] || return
+
+# Source it (finally)
. "$KSH_ENV"