Mac OS X : Create stunning prompt!


Background

Most of the time, command line prompt in terminal are boring and not very helpful. The default prompt on Mac OS looks like "$" or "#". I would like to have some more information and add more visibility.

After a few tweaks and researches, my actual prompt looks like this :




Let's do it !

Changing the Mac OS prompt is all about setting up the $PS1 variable.

$ echo $PS1

\[\033[00m\]\[\033[0;90m\]$fill \t\n\[\033[00m\]${debian_chroot:+($debian_chroot)} MacBook-Air:\w\$\[\033[00m\]\[\033[1;29m\]

This prompt has been built from variables and functions that match your actual environment like hostname, date and time, width of the terminal window, etc etc ...

As you can see above on the screenshot, there is ligne which separates every commands and its output, I really think this is adding visibility.

The script that build the $PS1 variable above is located in the $HOME/.bash_profile startup script. Edit this file and add the following lines at the very bottom :


# -----------------------------------------------------------------------------------------------------------------

fill="--- "
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black

# Prompt variable:

PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)} MacBook-Air:\w\$'"$command_style "

# Reset color for command output
# (this one is invoked every time before a command is executed):

trap 'echo -ne "\033[00m"' DEBUG

function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-9
fill=""
while [ "$fillsize" -gt "0" ]
do

fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;

*)

;;

esac
}

PROMPT_COMMAND=prompt_command

export CLICOLOR=1


Save the file and restart your terminal or source the file. The prompt above should be applied.

Best thing ever : it also works with Linux. I've tried on CentOS and Ubuntu.

Comments

What's hot ?

ShredOS : HDD degaussing with style

Wallbox : Get The Most Of It (with API)