How do I customize my command line prompt?

Status
Not open for further replies.

Osiris

Golden Master
Messages
36,817
Location
Kentucky
I'm a command line beginner, but these days I'm starting to use it more and more on my Mac, in Cygwin on my PC, and now sometimes even on a Unix server. I've seen other people's command line prompts with colors and different formats, and I'd like the same thing. Is there any way to customize my command prompt to my liking so it looks the same on all my computers?

Signed,
CLI Geek in Training




Dear CLI Geek,

Congrats on developing your command line chops! Like everything else at the prompt, the prompt itself is highly configurable using a textual config file. The file itself will depend on the system (see below), but the customization code stays the same. I'm no designer, but here's what my prompt customization code looks like to get what you see in the screenshot above:

function prompt
{
local WHITE="\[\033[1;37m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
export PS1="
${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w${GRAY}
$ "
}
prompt
There you can see I'm declaring colors, and then in the "export PS1" line I'm setting what the prompt should look like. \u refers to the current username (gina), \h refers to the host name (my computer's named "scully"), and \w refers to the current file path.

Use the code above as a starting point to get your ideal prompt worked out. Once you've got something you like, edit the proper configuration file, which will be located in your home directory on each system.

Here's what file you want to add this code to based on your operating system:

OS File name
Mac OS X .bash_profile
Cygwin (Windows) .profile
Linux .bashrc

http://lifehacker.com/software/ask-...i-customize-my-command-line-prompt-202042.php
 
Status
Not open for further replies.
Back
Top Bottom