Since the first time I installed Void Linux, I've experimented with many shells. The actual point of this was limited since I rarely have a need to write shell script, and when such times do occur it's usually a trivial one-liner that calls other programs and possibly redirects the outputs. I was mostly interested in other things like command history and auto-completion, customized prompts and so forth. There was yash, a rather capable POSIX shell that happens to be six times smaller than bash, yet still providing Emacs-like command line editing and command history, among other things. There were some larger options like zsh (and you thought bash was big? Ha!), and even some strange but interesting options like Hilbish. Normally I'd stick with bash or sh since my needs are pretty simple and could be met with just about any shell except dash.
Well on OpenBSD the default shell is ksh, so it was time to read the man page. Turns out there are some useful escape codes that allowed me to create a simple prompt string without any weird hacks. I could even get a coloured exit status to show up in the prompt!
## My own .kshrc
#
# Set the shell prompt
#
# ANSI terminal escape codes for colourized text
R='\e[31;1m' # Red, Bright
G='\e[32m' # Green
Y='\e[33;1m' # Yellow, Bright
C='\e[36m' # Cyan
X='\e[0m' # Reset
# colourize the exit status ($?)
function s {
ex=$?
if [[ $ex != 0 ]]; then
printf $R
else
printf $G
fi
}
#
# If we don't reset the colors before switching,
# all colors that follow will be bright as well.
#
PS1='$Y\u@\h:$X$C\w$X$(s) $?$X $ '
#
# Set up the terminal parameters
#
export TERM=xterm
export LINES=30
export COLUMNS=80
#
# Change the default umask to something more sensible
#
umask u=rwx,g-rwx,o-rwx
#
# Use Emacs mode for command line editing
#
set -o emacs
#
# Set up aliases
#
alias logout='clear; exit'
alias ls='ls -F'
alias ll='ls -l'
alias la='ls -lA'
alias ..='cd ..'
alias ...='cd ...'
alias mkdir='mkdir -p'
alias df='df -h'
alias du='du -h'
alias svi='doas vi'
alias smg='doas mg'
## END
=> ../../index.gmi Home
=> index.gmi Back to "Adventures in OpenBSD" index