Home > bash, fun > Emulate the MS-DOS prompt

Emulate the MS-DOS prompt

MS-DOS prompt

If you miss the MS-DOS times :), here is how to emulate the DOS prompt in bash.

Version #1

Here is the basic version:

export PS1='C:\w> '

To make it permanent, add it to your ~/.bashrc file :)


C:/> cd /tmp
C:/tmp> cd /etc/grub.d/

Version #2

Here is how to replace the ‘/‘ characters to ‘\‘ in the prompt path. First, add the following function to your ~/.bashrc:

function msdos_pwd {
   echo `pwd` | tr '/' '\\'

Then, either source ~/.bashrc, or open a new terminal window.

Finally, set PS1 like this:

export PS1='C:`msdos_pwd`> '


C:\> cd /tmp
C:\tmp> cd /etc/grub.d/

Improvement #1:

If you want to see ‘~’ instead of full path when you enter your HOME directory, use this function:

function msdos_pwd
    if [ "`pwd`" == "$HOME" ]
    echo '~'
    echo `pwd` | tr '/' '\\'

Improvement #2 (update 20110210):

The previous version showed ‘~’ in the HOME directory only. When you entered a subdirectory of HOME, HOME was expanded. Here is the revised version:

function msdos_pwd
    local dir="`pwd`"

    echo $dir | tr '/' '\\'


Similar work (update 20110210)

As I was browsing the web looking for something alike, I found a similar approach. His implementation is different and he doesn’t replace the HOME directory by ‘~’.

Blinking cursor (update 20110304)

In MS-DOS, the cursor was a blinking underscore. Here is how to set it under Konsole: Settings -> Configure Profiles… -> Edit Profile… -> Advanced tab. Here, under the Cursor section, tick Blinking cursor and for cursor shape select “Underline”. Apply, OK. Close konsole and open a new instance.

Final touch (update 20110311)

To make it even better, let’s print some MS-DOS boot text when opening a new shell. Add these lines to the end of your ~/.bashrc file:

echo Starting MS-DOS...
echo HIMEM is testing extended memory...done.

You can download everything here.

Screenshot of the final product.

Update (20120927)
On reddit, someone suggested the following one-liner:

export PS1='C:${PWD//\//\\\\}>'
Categories: bash, fun Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: