aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-17 18:30:31 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-17 18:30:31 +1300
commit2070ffec57756c6a1934e17616fa694dc55d5b2e (patch)
treec49cc943560da1397a44818036164a965da1a4dc
parent390188a950053239b9499d263399bfab30b84c1f (diff)
downloaddotfiles-2070ffec57756c6a1934e17616fa694dc55d5b2e.tar.gz
dotfiles-2070ffec57756c6a1934e17616fa694dc55d5b2e.zip
Resolve a few ksh version differences
-rw-r--r--ksh/kshrc4
-rw-r--r--ksh/kshrc.d/prompt.ksh36
2 files changed, 24 insertions, 16 deletions
diff --git a/ksh/kshrc b/ksh/kshrc
index cf7812d6..c45d4018 100644
--- a/ksh/kshrc
+++ b/ksh/kshrc
@@ -6,6 +6,10 @@ 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 a8835803..f0aaadd3 100644
--- a/ksh/kshrc.d/prompt.ksh
+++ b/ksh/kshrc.d/prompt.ksh
@@ -1,14 +1,3 @@
-# All of this is only known to work on OpenBSD's fork of pdksh
-case $KSH_VERSION in
- *'PD KSH'*)
- case $(uname -s) in
- OpenBSD) ;;
- *) return ;;
- esac
- ;;
- *) return ;;
-esac
-
# Frontend to controlling prompt
prompt() {
@@ -26,12 +15,19 @@ prompt() {
# Basic prompt shape depends on whether we're in SSH or not
PS1=
if [[ -n $SSH_CLIENT ]] || [[ -n $SSH_CONNECTION ]] ; then
- PS1=$PS1'\u@\h:'
+ PS1=$PS1'$USER@$HOST:'
fi
- PS1=$PS1'\w'
- # Add sub-commands; VCS, job, and return status checks
- PS1=$PS1'$(prompt vcs)$(prompt job)$(prompt ret "$?")'
+ # Add sub-commands; working directory with ~ abbreviation, VCS,
+ # job, and return status checks
+ PS1=$PS1'$(prompt pwd)$(prompt vcs)$(prompt job)'
+
+ # 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
+ # $? is set
+ case $KSH_VERSION in
+ *'PD KSH'*) PS1=$PS1'$(prompt ret "$?")'
+ esac
# Add prefix and suffix
PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}'
@@ -78,7 +74,7 @@ prompt() {
} >/dev/null 2>&1
# String it all together
- PS1='\['"$format"'\]'"$PS1"'\['"$reset"'\] '
+ PS1="${format}${PS1}${reset}"' '
PS2='> '
PS3='? '
PS4='+<$?> $LINENO:'
@@ -167,6 +163,14 @@ prompt() {
PS4='+ '
;;
+ # Abbreviated working directory
+ pwd)
+ case $PWD in
+ "$HOME"|"$HOME"/*) printf ~%s "${PWD#"$HOME"}" ;;
+ *) printf %s "$PWD" ;;
+ esac
+ ;;
+
# VCS wrapper prompt function; print the first relevant prompt, if any
vcs)
typeset vcs