From e3f97d6c12e6e311b155ce24ce586717b1abc18b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 25 Jan 2017 14:31:32 +1300 Subject: Show prompt prefix if a shell is exotic That is, include e.g. "ksh:" as a prefix to the prompt if the user appears to have Bash or Zsh (or anything else) as their login shell. This is probably imperfect, but it's a start. --- README.markdown | 3 +++ bash/bashrc.d/prompt.bash | 6 ++++++ ksh/kshrc.d/prompt.ksh | 14 ++++++++++++++ zsh/zshrc.d/prompt.zsh | 6 ++++++ 4 files changed, 29 insertions(+) diff --git a/README.markdown b/README.markdown index 9c956d51..70234ed8 100644 --- a/README.markdown +++ b/README.markdown @@ -147,6 +147,9 @@ include these elements in this order: You can set `PROMPT_COLOR`, `PROMPT_PREFIX`, and `PROMPT_SUFFIX` too, which all do about what you'd expect. +If you start up Bash, Ksh, or Zsh and it detects that it's not normally your +`$SHELL`, the prompt will display an appropriate prefix. + This is all managed within the `prompt` function. There's some mildly hacky logic on `tput` codes included such that it should work correctly for most common terminals using both `termcap(5)` and `terminfo(5)`, including \*BSD diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index b22f118f..2bd70c2f 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -22,6 +22,12 @@ prompt() { # Add sub-commands; VCS, job, and return status checks PS1=$PS1'$(ret=$?;prompt vcs;prompt job;prompt ret)' + # Add a helpful prefix if this shell appears to be exotic + case ${SHELL##*/} in + (bash) ;; + (*) PS1=bash:$PS1 ;; + esac + # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh index bf77f626..09c7de6e 100644 --- a/ksh/kshrc.d/prompt.ksh +++ b/ksh/kshrc.d/prompt.ksh @@ -22,6 +22,20 @@ function prompt { # count, and previous command return value PS1=$PS1'$(ret=$?;jobc=$(jobs -p|sed -n '\''$='\'');prompt pwd;prompt vcs;prompt job;prompt ret;:)' + # Add a helpful prefix if this shell appears to be exotic + typeset ksh + case $KSH_VERSION in + (*'93'*) ksh=ksh93 ;; + (*'PD KSH'*) ksh=pdksh ;; + (*'MIRBSD KSH'*) ksh=mksh ;; + esac + case ${SHELL##*/} in + ('') ;; + (ksh) ;; + ("$ksh") ;; + (*) PS1=$ksh:$PS1 ;; + esac + # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh index cfac7ffd..f374dbec 100644 --- a/zsh/zshrc.d/prompt.zsh +++ b/zsh/zshrc.d/prompt.zsh @@ -18,6 +18,12 @@ prompt() { # Add sub-commands; VCS, job, and return status checks PS1=$PS1'$(ret=$?;prompt vcs;prompt job;prompt ret)' + # Add a helpful prefix if this shell appears to be exotic + case ${SHELL##*/} in + (zsh) ;; + (*) PS1=zsh:$PS1 ;; + esac + # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' -- cgit v1.2.3