Shell Share your .shrc, .kshrc or .mkshrc file segments: Bourne or Korn shell

Share your .shrc and/or .kshrc configuration file(s) or samples. .profile can also be used to set common configurations of Bourne and Korn shells. Samples from this file intended for Bourne and Korn can be shared too.

There's not as many posts about use of Bourne shells and variant Korn shells on FreeBSD as there are for other shells. These shells are similar and use many of the same settings, that they can go on the same thread. Signify which shell file is being referred to for the configuration. Additionally, a description or a display of its results can be added.
This may be additionally useful related to the discussion of: Thread current-proposal-to-make-bin-sh-the-default-shell-for-root.82157.
I only have my prompt configurations there. I've use this same style of prompt since 1999 or so, so I have "ported" to other shells. The user is green-ish, while the root is red-ish.
Bash: As needed.
For user:
PS1="\[\e[1;34m\]┌\[\e[m\]\[\e[1;34m\][\[\e[1;36m\]\u\[\e[33m\]@\[\e[1;32m\]\h\[\e[1;34m\]]\[\e[1;34m\]\[\e[1;34m\]─[\[\e[1;33m\]\$PWD\[\e[1;34m\]]─\[   \[\e[m\]\n\[\e[1;34m\]└\[\e[m\]\[\e[1;34m\][\[\e[m\]\j\[\e[1;34m\]]\[\e[m\]\[\e[1;34m\]─ \[\e[m\]"
For root:
PS1="\[\e[1;31m\]┌\[\e[m\]\[\e[1;31m\][\[\e[31m\]\u\[\e[33m\]@\[\e[1;32m\]\h\[\e[1;31m\]]\[\e[1;31m\]\[\e[1;31m\]─[\[\e[1;33m\]\$PWD\[\e[1;31m\]]─\[   \[\e[m\]\n\[\e[1;31m\]└\[\e[m\]\[\e[1;31m\][\[\e[m\]\j\[\e[1;31m\]]\[\e[m\]\[\e[1;31m\]─ \[\e[m\]"
Csh: Only for root.
set     red="%{\033[0;31m%}"
set    bred="%{\033[1;31m%}"
set   green="%{\033[0;32m%}"
set  bgreen="%{\033[1;32m%}"
set  yellow="%{\033[0;33m%}"
set byellow="%{\033[1;33m%}"
set    blue="%{\033[1;34m%}"
set magenta="%{\033[1;35m%}"
set    cyan="%{\033[1;36m%}"
set   white="%{\033[0;37m%}"
set     end="%{\033[0m%}"
set prompt="${bred}┌[${red}%n${yellow}@${bgreen}%m${bred}]-[${byellow}%~${bred}]-\n${bred}└[${white}0${bred}]─${white} ${end}"
if [ $USER_ID == 0 ];
        PS1=$'\a\r\a\e[1;31m\a┌[\a\e[0;31m\a${USER:=$(ulimit -c 0; \
            id -un 2>/dev/null || echo \?)}\e[1;33m@\e[32m\${HOSTNAME%%.*}\a\e[1;31m\a]─[\a\e[0;33m\a$(
                local d=${PWD:-?} p=~
                [[ $p = ?(*/) ]] || d=${d/#$p/~}
                print -nr -- "$d"
            )\a\e[1;31m\a]─\n└ \a\e[0m\a';
        PS1=$'\a\r\a\e[1;34m\a┌[\a\e[0;36m\a${USER:=$(ulimit -c 0; \
            id -un 2>/dev/null || echo \?)}\e[1;33m@\e[32m\${HOSTNAME%%.*}\a\e[1;34m\a]─[\a\e[0;33m\a$(
                local d=${PWD:-?} p=~
                [[ $p = ?(*/) ]] || d=${d/#$p/~}
                print -nr -- "$d"
            )\a\e[1;34m\a]─\n└ \a\e[0m\a';
This one is for Bourne (sh) and ksh. As you've posted one for ksh, at least it got started. There's not enough on ksh and sh on the forums. It's also for .profile sections pertaining to sh and ksh.

Csh isn't Bourne. C shell also has Thread share-your-tcshrc-file.21040.

This one isn't for Bash. While it's based on Bourne, it's very different, and isn't not Posix Bourne. Bash is more of something else: it can have its own thread for sharing files/samples.

I took .profile out of the title, because while this thread is meant for including parts from it, it's not about that for Bash or Csh.
Is it possible to have a prompt with glyphs and colors in sh? I didn't find any useful tips about it.
PS1="\[\e[${background}${color};1m\]${prompthost}_\w > \\[\e[0m\]"

Here, background is a number between 40 and 47 for the background color of the prompt (plus a ";" appended to it), color a number between 30 and 37 for the foreground color, and prompthost the name of host as it should be shown in the prompt.

Warning: This is for bash, but I think it works in modern sh variants too; it does not work in the traditional FreeBSD default shell. If it does not, replace \e with escape, and \[ and \] are not vitally needed, if you're willing to deal with the prompt doing funny things when scrolling.
.mkshrc for shells/mksh:
export LSCOLORS="gxxxxxxxxxxxdx"
PS1=$'\E[1m\E[32m$PWD \E[0m$ '

Tried copying this to .kshrc for use with other Korn shells (shells/pdksh and shells/oksh), but it didn't work as is. ksh carried the LSCOLORS settings over from the last session of Csh. Mksh is easier to configure than the other Korn shells.

Couldn't figure out the autoload argument to use arrowkeys to scroll commands for partially typed commands/words on terminal.

I didn't realize that mksh used .mkshrc rather than .kshrc. Share .mkshrc file contents too. It may be better to share specific configuration files than .profile, for simplicity. However, .profile can be shared too, when it's relevant to these shells.

sh was difficult for me to work with. I got the value for LSCOLORS to work from the configuration file one time, so it was persistent, but couldn't replicate that. The value of the variable also matched the settings when that happened. Setting it from the terminal can be easily done, but putting that value into the configuration file and making it stay is difficult. When it's set, even by command line for only that session, echo shows the value of LSCOLORS. Sh also carried LSCOLORS over from the last session of Csh.
Thread the-bourne-shell-prompt-color.85914 is someone's attempt to color the prompt for sh. Thread colorize-your-bsd-shell.85458 has information for colorizing, but it wasn't enough for the prompt of Bourne Shell.

Here's ShelLuser's included settings for ksh:
ShelLuser said:
So first... my ~/.profile does all the usual stuff. Sets path, aliases, $EDITOR, and...
# Set ENV to sustain ksh settings
. $ENV
if [ "`basename ${0#-}`" == "ksh" ]; then
   set -o posix -o braceexpand -o vi -o vi-tabcomplete;
   PS1="`whoami`@`hostname -s`:\${PWD} \$ ";
ShelLuser said:
As you can see I like my shell somewhat "spartan", I actually use & enjoy VI mode.
export ENV=/home/myuser/.kshrc

.kshrc for shells/oksh
bind '^N'=down-history
bind '^P'=up-history

#clear screen
bind '^L=clear-screen'
#delete line
bind -m ^U='^[0^K'

alias aa='ls -Ih --color'
alias zz='ls -Al --color'

PS1='OKSH: $PWD # '

export PATH=/usr/local/libexec/ccache:$PATH
export CCACHE_DIR=/ccache
Last edited: