aboutsummaryrefslogtreecommitdiff
path: root/ksh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-06 20:10:53 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-06 20:10:53 +1300
commit22fbdf236c33644eb1f80d9058a0a7e35def1d74 (patch)
tree960c8ee85e03183022eb54e236745d4126fd1322 /ksh
parentMerge branch 'master' into port/bsd/dragonfly-bsd (diff)
parentRename keyboard trap func less ambiguously (diff)
downloaddotfiles-22fbdf236c33644eb1f80d9058a0a7e35def1d74.tar.gz
dotfiles-22fbdf236c33644eb1f80d9058a0a7e35def1d74.zip
Merge branch 'master' into port/bsd/dragonfly-bsd
Diffstat (limited to 'ksh')
-rw-r--r--ksh/kshrc16
-rw-r--r--ksh/kshrc.d/bind.ksh28
-rw-r--r--ksh/kshrc.d/keep.ksh1
-rw-r--r--ksh/kshrc.d/prompt.ksh25
4 files changed, 66 insertions, 4 deletions
diff --git a/ksh/kshrc b/ksh/kshrc
index cf7812d6..5d481bb4 100644
--- a/ksh/kshrc
+++ b/ksh/kshrc
@@ -1,7 +1,21 @@
-# Emacs-style key bindings
+# Emacs-style key bindings; these are present in ksh88 and pdksh
set -o braceexpand
set -o emacs
+# Track locations of binaries
+set -o trackall
+
+# Use subshells to test these newer options, as ksh93 seems to get very upset
+# if you try to set an option and it doesn't exist
+
+# Try to get "**" as a recursive glob
+(set -o globstar) 2>/dev/null &&
+ set -o globstar
+
+# Try to get !-style history expansion
+(set -o histexpand) 2>/dev/null &&
+ set -o histexpand
+
# Save history
HISTFILE=$HOME/.ksh_history
HISTSIZE=$((1 << 10))
diff --git a/ksh/kshrc.d/bind.ksh b/ksh/kshrc.d/bind.ksh
new file mode 100644
index 00000000..34cb5f5a
--- /dev/null
+++ b/ksh/kshrc.d/bind.ksh
@@ -0,0 +1,28 @@
+# Try to bind ^I to complete words and ^L to clear the screen
+case $KSH_VERSION in
+
+ # ksh93 is lovely, but complex; rebind ^L so it does the same as Alt-^L
+ *'93'*)
+ keybd_trap() {
+ # shellcheck disable=SC2154
+ case ${.sh.edchar} in
+ $'\f') .sh.edchar=$'\e\f' ;;
+ esac
+ }
+ trap keybd_trap KEYBD
+ ;;
+
+ # More straightforward with mksh; bind keys to the appropriate emacs mode
+ # editing commands
+ *'MIRBSD KSH'*)
+ bind '^I'='complete'
+ bind '^L'='clear-screen'
+ ;;
+
+ # Similar with pdksh; there's a "complete" command, but not a "clear" one,
+ # so we fake it with clear(1) and some yanking
+ *'PD KSH'*)
+ bind '^I'='complete'
+ bind -m '^L'='^Uclear^J^Y'
+ ;;
+esac
diff --git a/ksh/kshrc.d/keep.ksh b/ksh/kshrc.d/keep.ksh
index c57c41ce..0451fa68 100644
--- a/ksh/kshrc.d/keep.ksh
+++ b/ksh/kshrc.d/keep.ksh
@@ -142,7 +142,6 @@ EOF
# Otherwise the user must want us to print all the NAMEs kept
(
- typeset keep
for keep in "$kshkeep"/*.ksh ; do
[[ -f "$keep" ]] || break
keep=${keep##*/}
diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh
index add96b2a..84129efc 100644
--- a/ksh/kshrc.d/prompt.ksh
+++ b/ksh/kshrc.d/prompt.ksh
@@ -136,8 +136,28 @@ function prompt {
state=${state}'>'
# Tracked files are modified
- git diff-files --no-ext-diff --quiet ||
- state=${state}'!!'
+ if ! git diff-files --no-ext-diff --quiet ; then
+
+ # Different ksh flavours process a bang in PS1 after prompt
+ # parameter expansion in different ways
+ case $KSH_VERSION in
+
+ # ksh93 requires a double-bang to escape it
+ (*'93'*) state=${state}'!!' ;;
+
+ # OpenBSD's pdksh requires a double-bang too, but its
+ # upstream does not
+ (*'PD KSH'*)
+ case $OS in
+ ('OpenBSD') state=${state}'!!' ;;
+ (*) state=${state}'!' ;;
+ esac
+ ;;
+
+ # Everything else should need only one bang
+ (*) state=${state}'!' ;;
+ esac
+ fi
# Changes are staged
git diff-index --cached --no-ext-diff --quiet HEAD ||
@@ -192,6 +212,7 @@ function prompt {
# Show the count of background jobs in curly brackets, if not zero
job)
+ # shellcheck disable=SC2154
((jobc)) && printf '{%u}' "$jobc"
;;