aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-18 13:42:46 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-18 13:42:46 +1300
commitc5da7f548fba673d98fded77810f563c5c6183a9 (patch)
treead24f4eb0fa30c4dbc175753a2c34cc94fc57ccd
parentMerge branch 'master' into freebsd (diff)
parentAdd ksh version distinguisher to prompt (diff)
downloaddotfiles-c5da7f548fba673d98fded77810f563c5c6183a9.tar.gz
dotfiles-c5da7f548fba673d98fded77810f563c5c6183a9.zip
Merge branch 'master' into freebsd
-rw-r--r--ISSUES.markdown2
-rw-r--r--Makefile2
-rw-r--r--README.markdown5
-rw-r--r--games/drakon.awk4
-rw-r--r--ksh/kshrc4
-rw-r--r--ksh/kshrc.d/prompt.ksh29
-rw-r--r--ksh/shrc.d/ksh.sh37
-rw-r--r--sh/profile4
-rw-r--r--sh/shrc3
-rw-r--r--sh/shrc.d/ksh.sh8
10 files changed, 75 insertions, 23 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index 19375c83..b02db22e 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -18,3 +18,5 @@ Known issues
* dr(1df) is probably more practical in awk
* How come commands I fix with the fc builtin always seem to exit 1 even if
they succeed? Did I do that or is it Bash?
+* typeset in ksh93 does not seem to make the variable local, maybe I'm
+ missing some magic
diff --git a/Makefile b/Makefile
index f2e9e278..9961da71 100644
--- a/Makefile
+++ b/Makefile
@@ -292,7 +292,9 @@ install-mysql :
install-ksh : check-ksh install-sh
install -m 0755 -d -- \
+ "$(HOME)"/.shrc.d \
"$(HOME)"/.kshrc.d
+ install -pm 0644 -- ksh/shrc.d/* "$(HOME)"/.shrc.d
install -pm 0644 -- ksh/kshrc "$(HOME)"/.kshrc
install -pm 0644 -- ksh/kshrc.d/* "$(HOME)"/.kshrc.d
diff --git a/README.markdown b/README.markdown
index 5c9dc392..fb517bad 100644
--- a/README.markdown
+++ b/README.markdown
@@ -255,9 +255,8 @@ Otherwise, they're all loaded on startup.
#### Korn shell
-The `ksh` configuration files and functions are not nearly as featureful as the
-Bash ones. At the moment these are mainly being maintained for use on OpenBSD
-`pdksh`.
+These are experimental; they are mostly used to tinker with MirBSD `mksh`, AT&T
+`ksh93`, and OpenBSD `pdksh`.
`ksh`, `ksh93`, `pdksh`, and `mksh` shells default to having a prompt coloured
yellow.
diff --git a/games/drakon.awk b/games/drakon.awk
index 39bb3732..4b8c35c5 100644
--- a/games/drakon.awk
+++ b/games/drakon.awk
@@ -2,11 +2,11 @@
# <http://www.adomgb.info/adomgb-4.html>
{
line = ""
- case = 0
+ toggle = 0
for (i = 1; i <= length; i++) {
char = substr($0, i, 1)
if (char ~ /[a-zA-Z]/)
- char = (case = !case) ? tolower(char) : toupper(char)
+ char = (toggle = !toggle) ? tolower(char) : toupper(char)
line = line char
}
print line
diff --git a/ksh/kshrc b/ksh/kshrc
index c45d4018..cf7812d6 100644
--- a/ksh/kshrc
+++ b/ksh/kshrc
@@ -6,10 +6,6 @@ set -o emacs
HISTFILE=$HOME/.ksh_history
HISTSIZE=$((1 << 10))
-# If HOST and HOSTNAME aren't set by this version of ksh, set them
-HOSTNAME=$(uname -n)
-HOST=${HOSTNAME%%.*}
-
# Load any supplementary scripts
for kshrc in "$HOME"/.kshrc.d/*.ksh ; do
[[ -e $kshrc ]] && . "$kshrc"
diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh
index f0aaadd3..32bb8192 100644
--- a/ksh/kshrc.d/prompt.ksh
+++ b/ksh/kshrc.d/prompt.ksh
@@ -1,5 +1,5 @@
# Frontend to controlling prompt
-prompt() {
+function prompt {
# If no arguments, print the prompt strings as they are
if ! (($#)) ; then
@@ -15,12 +15,12 @@ prompt() {
# Basic prompt shape depends on whether we're in SSH or not
PS1=
if [[ -n $SSH_CLIENT ]] || [[ -n $SSH_CONNECTION ]] ; then
- PS1=$PS1'$USER@$HOST:'
+ PS1=$PS1'$USER@${HOSTNAME%%.*}:'
fi
# Add sub-commands; working directory with ~ abbreviation, VCS,
- # job, and return status checks
- PS1=$PS1'$(prompt pwd)$(prompt vcs)$(prompt job)'
+ # job, and ksh version code
+ PS1=$PS1'$(prompt pwd)$(prompt vcs)$(prompt job)$(prompt ver)'
# If this is PDKSH, add the exit code of the previous command; this
# doesn't seem to work on ksh93, probably different timing for when
@@ -35,6 +35,17 @@ prompt() {
# Add terminating "$" or "#" sign
PS1=$PS1'\$'
+ # Add > signs at the front of the prompt to show the current shell
+ # level, taking tmux sessions into account, assuming this version
+ # of ksh does SHLVL; I think only ksh93t+ does it from what I can
+ # tell
+ typeset shlvl
+ ((shlvl = SHLVL - TMUX_SHLVL))
+ while ((shlvl > 1)); do
+ PS1='>'$PS1
+ ((shlvl--))
+ done
+
# Declare variables to contain terminal control strings
typeset format reset
@@ -192,6 +203,16 @@ prompt() {
((jobc)) && printf '{%u}' "$jobc"
;;
+ # Show a short code denoting the ksh flavour, if it can be gleaned from
+ # KSH_VERSION
+ ver)
+ case $KSH_VERSION in
+ *'PD KSH'*) printf %s ':pd' ;;
+ *'MIRBSD KSH'*) printf %s ':mk' ;;
+ *' 93'*) printf %s ':93' ;;
+ esac
+ ;;
+
# Print error
*)
printf 'prompt: Unknown command %s\n' "$1" >&2
diff --git a/ksh/shrc.d/ksh.sh b/ksh/shrc.d/ksh.sh
new file mode 100644
index 00000000..0045a470
--- /dev/null
+++ b/ksh/shrc.d/ksh.sh
@@ -0,0 +1,37 @@
+# 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. To make matters worse, the best way I can find for testing the version
+# makes other shells throw tantrums.
+
+# Does the name of our shell have "ksh" in it at all? This is in no way
+# guaranteed. It's just a heuristic that e.g. Bash and Yash shouldn't pass.
+case $0 in
+ *ksh*) ;;
+ *) return ;;
+esac
+
+# If KSH_VERSION is 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. Suppress errors
+ # and run it in a subshell to work around parsing error precedence.
+ ( test -n "${.sh.version}" ) 2>/dev/null || return
+
+ # If that peculiarly named variable was set, then 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"
diff --git a/sh/profile b/sh/profile
index fd87b8fa..5d9c80bf 100644
--- a/sh/profile
+++ b/sh/profile
@@ -7,8 +7,8 @@ for sh in "$HOME"/.profile.d/*.sh ; do
done
unset -v sh
-# If ENV is still unset, and ~/.shinit exists, use that
-if [ -z "$ENV" ] && [ -f "$HOME"/.shinit ] ; then
+# If ~/.shinit exists, set ENV to that
+if [ -f "$HOME"/.shinit ] ; then
ENV=$HOME/.shinit
export ENV
fi
diff --git a/sh/shrc b/sh/shrc
index 6c4eac8b..8bbc5147 100644
--- a/sh/shrc
+++ b/sh/shrc
@@ -7,6 +7,9 @@ command -p stty -ixon -ctlecho 2>/dev/null
# Keep around 4K lines of history in memory
HISTSIZE=$((1 << 12))
+# If HOSTNAME isn't set by this shell, we'll do it
+[ -n "$HOSTNAME" ] || HOSTNAME=$(uname -n)
+
# Don't warn me about new mail
unset -v MAILCHECK
diff --git a/sh/shrc.d/ksh.sh b/sh/shrc.d/ksh.sh
deleted file mode 100644
index 9cb72e8e..00000000
--- a/sh/shrc.d/ksh.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-# 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.
-[ -n "$KSH_VERSION" ] || return
-[ -n "$KSH_ENV" ] || KSH_ENV=$HOME/.kshrc
-[ -f "$KSH_ENV" ] || return
-. "$KSH_ENV"