Changing the win32 native BASH prompt

If you like using BASH on Windows but don’t want to use the Cygwin port, you may have run across some of the native BASH ports available.

Trouble is, BASH on Windows does not read your host name, and many of the native ports ignore your BASH configuration files.

If you just want to create a new static prompt instead of the default “bash$”, it’s very easy to do using a hex editor. The hack below was done on a Bash version 1.14.7(53) native port dated 2005/7/9. I don’t recall where I found it anymore.

The first thing to do is find where your current prompt is stored. Remember, the $ is an escaped string, so to find “bash$” you need to search for “bash\$ “. In my EXE this was at $0712c8.

Next, you need this string’s pointer. 0×712c8 + 0×400000 = 0×4712c8. Search for the hex bytes “c8 12 47″ since Windows does addressing in Little Endian. For me, this was at $03e99c

Now you need some blank space for your new prompt. In my EXE, there wasn’t much going on at $075960, so I stuck it there. Change the pointer you found before to go to the new address. In this case, you would change it to “60 59 47″ because 0×75960 + 0×400000 = 0×475960.

Last, we need to decide how to format it. I chose a simple prompt that just says “CINNAMON$ “, but you could do something fancy like, “[d@cinnamon:/]\$ ” or whatever pleases you.

Now when you run BASH, you should see your new prompt instead of the common “bash$” default.

CINNAMON$ php --version
PHP 5.2.0 (cli) (built: Nov 2 2006 11:57:36)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
CINNAMON$

Update:

You can also use some of the BASH flags in this line, but most will not work correctly. Ones which will work (in the native win32 BASH, not Cygwin BASH):

\a - ASCII bell
\d - Date (Mon Dec 25)
\j - Number of suspended processes
\n - New line
\r - Carriage return
\s - Shell executable’s filename
\v - Bash version
\w - Current working directory
\W - Current full path
\$ - Shows $ (you cannot be “root” in the mind of the win32 port)
\\ - Backslash

Related Posts

Related posts brought to you by Yet Another Related Posts Plugin.


About this entry