path: root/ksh/shrc.d/ksh.sh
diff options
authorTom Ryder <tom@sanctum.geek.nz>2016-12-17 20:03:40 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-17 20:03:40 +1300
commit5ab5ccd94bda49db30e7c600364cc4e14e88df9b (patch)
treeb11762722c2bc3b2b268d951ef799bff941e5d66 /ksh/shrc.d/ksh.sh
parentImprove accuracy of comment (diff)
Move ksh.sh shim into ksh subdir
So it doesn't get installed on systems where I don't use ksh, since it's mostly not needed
Diffstat (limited to 'ksh/shrc.d/ksh.sh')
1 files changed, 30 insertions, 0 deletions
diff --git a/ksh/shrc.d/ksh.sh b/ksh/shrc.d/ksh.sh
new file mode 100644
index 00000000..6c134e88
--- /dev/null
+++ b/ksh/shrc.d/ksh.sh
@@ -0,0 +1,30 @@
+# If we're running some kind of ksh, we'll need to source its specific
+# 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.
+# 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
+ # Test whether we have content in the .sh.version variable. The odd name
+ # causes at least Bash to panic, so we suppress errors, and we run it in a
+ # subshell to work around parsing error precedence.
+ ( test -n "${.sh.version}" ) 2>/dev/null || return
+ # If it is, that's our KSH_VERSION
+ KSH_VERSION=${.sh.version}
+# 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"