Customize ksh display for OpenBSD

The default shell for OpenBSD is ksh, and it looks a little monotonous:

1

To make its user-experience more friendly, I need to do some customizations:

(1) Modify the “Prompt String” to display the user name and current directory:

PS1='$USER:$PWD# '

(2) Install colorls package:

# pkg_add colorls

Use it to replace the shipped ls command:

alias ls='colorls -G'

(3) Change LSCOLORS environmental variable to make your favorite color. For example, I don’t want the directory is displayed in default blue, change it to magenta:

LSCOLORS=fxexcxdxbxegedabagacad

For detailed explanation of LSCOLORS, please refer manual of colorls:

# man colorls
......
LSCOLORS        The value of this variable describes what color to use
                     for which attribute when colors are enabled with
                     CLICOLOR.  This string is a concatenation of pairs of the
                     format fb, where f is the foreground color and b is the
                     background color.

                     The color designators are as follows:

                           a     black
                           b     red
......

This is my final modification of .profile:

......
PS1='$USER:$PWD# '
export PS1
LSCOLORS=fxexcxdxbxegedabagacad
export LSCOLORS
alias ls='colorls -G'
......

And this is the final effect:

Capture
References:
Add Color to Your Terminal;
Why doesn’t alias work in AIX (Korn shell, .profile)?;
ksh.kshrc.

 

8 thoughts on “Customize ksh display for OpenBSD”

  1. Hi there excellent blog! Does running a blog similar to this require a massive amount work? I’ve very little understanding of computer programming however I was hoping to start my own blog in the near future. Anyway, should you have any suggestions or techniques for new blog owners please share. I know this is off subject but I just wanted to ask. Thanks a lot!|

    1. Build your own blog is very easy, even requires little knowledge. You just need to apply for a domain name. If you don’t want to lease host, you can utilise github pages to hold your blog. If you don’t want to spend a cent, or feel a little difficult to do this. You can use third-party blog platform, such as blogspot, wordpress, etc.

      If you want to share your stories, great! Just write it. Don’t care whether people would read it or not. The important thing is you get joy from blogging.

      Trust me, enjoy blogging!

  2. Maybe it’s a kind of electronic Stockholm Syndrome, but for _me_ the default is totally fine. I don’t see any need to call it “monstrous.”

    What you’ve come up with is nice for sure (too many folks go way too far with customizing their terminal prompts) but I myself don’t feel the need to customize my profile and install third party software just to get dotfiles printed in purple.

    Anyhow, keep up the nice OpenBSD coverage!

  3. Couldn’t you create and export the variable in one shot, so that instead of having two lines for LSCOLORS and PS1, you could have one each? Of does OpenBSD’s ksh not support that?

  4. Observation: ksh has many escape sequences built in.

    They can be found in the man page, look for “PS1″


    \A The current time, in 24-hour HH:MM format.
    \u The current user’s username.
    \v The current version of ksh.
    \V Like `\v’, but more verbose.
    \w The current working directory. $HOME is
    abbreviated as `~’.
    \W The basename of the current working directory.
    $HOME is abbreviated as `~’.

    So your PS1 could be written as

    PS1=”\u:\W\$ ”

    However, I have no informed opinion on the merits of using shell variables vs builtin ksh escapes.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.