Skip to content

Commit

Permalink
colorizing and revamping bash prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
tangledhelix committed Oct 6, 2010
1 parent 567e425 commit 1c1ddae
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
66 changes: 66 additions & 0 deletions bash/colordefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Color definitions to use in prompts (taken from Bashish).
# http://bashish.sourceforge.net/

DULL=0
BRIGHT=1

FG_BLACK=30
FG_RED=31
FG_GREEN=32
FG_YELLOW=33
FG_BLUE=34
FG_VIOLET=35
FG_CYAN=36
FG_WHITE=37

FG_NULL=00

BG_BLACK=40
BG_RED=41
BG_GREEN=42
BG_YELLOW=43
BG_BLUE=44
BG_VIOLET=45
BG_CYAN=46
BG_WHITE=47

BG_NULL=00

##
# ANSI Escape Commands
##
ESC="\033"
NORMAL="\[$ESC[m\]"
RESET="\[$ESC[${DULL};${FG_WHITE};${BG_NULL}m\]"

##
# Shortcuts for Colored Text ( Bright and FG Only )
##

# DULL TEXT

BLACK="\[$ESC[${DULL};${FG_BLACK}m\]"
RED="\[$ESC[${DULL};${FG_RED}m\]"
GREEN="\[$ESC[${DULL};${FG_GREEN}m\]"
YELLOW="\[$ESC[${DULL};${FG_YELLOW}m\]"
BLUE="\[$ESC[${DULL};${FG_BLUE}m\]"
VIOLET="\[$ESC[${DULL};${FG_VIOLET}m\]"
CYAN="\[$ESC[${DULL};${FG_CYAN}m\]"
WHITE="\[$ESC[${DULL};${FG_WHITE}m\]"

# BRIGHT TEXT
BRIGHT_BLACK="\[$ESC[${BRIGHT};${FG_BLACK}m\]"
BRIGHT_RED="\[$ESC[${BRIGHT};${FG_RED}m\]"
BRIGHT_GREEN="\[$ESC[${BRIGHT};${FG_GREEN}m\]"
BRIGHT_YELLOW="\[$ESC[${BRIGHT};${FG_YELLOW}m\]"
BRIGHT_BLUE="\[$ESC[${BRIGHT};${FG_BLUE}m\]"
BRIGHT_VIOLET="\[$ESC[${BRIGHT};${FG_VIOLET}m\]"
BRIGHT_CYAN="\[$ESC[${BRIGHT};${FG_CYAN}m\]"
BRIGHT_WHITE="\[$ESC[${BRIGHT};${FG_WHITE}m\]"

# REV TEXT as an example
REV_CYAN="\[$ESC[${DULL};${BG_WHITE};${BG_CYAN}m\]"
REV_RED="\[$ESC[${DULL};${FG_YELLOW}; ${BG_RED}m\]"

PROMPT_COMMAND='export ERR=$?'

14 changes: 13 additions & 1 deletion bash/general → bash/config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ test -n "$INTERACTIVE" && {
#
_shorthost="$(echo $HOST|perl -p -e 's/^([^.]+\.[^.]+).*$/$1/;s/\.local//;')"

ESC="\033"
BRIGHT=1
FG_RED=31
BRIGHT_RED="\[$ESC[${BRIGHT};${FG_RED}m\]"

RED="\[\033[0;31m\]"
BROWN="\[\033[0;33m\]"
GREY="\[\033[0;97m\]"
BLUE="\[\033[0;34m\]"
PS_CLEAR="\[\033[0m\]"
SCREEN_ESC="\[\033k\033\134\]"

# Prompt
#
# \u Username
Expand All @@ -30,7 +42,7 @@ test -n "$INTERACTIVE" && {
# \$ $ or # (depending on uid)
# \j Number of jobs currently managed by the shell
#
export PS1="\u@$_shorthost[\j]:\W{\$?}\$(parse_git_branch)\\$ "
export PS1="${BRIGHT_BLUE}[\j] ${BRIGHT_VIOLET}\w${BRIGHT_RED}\$(parse_git_branch)\n${BRIGHT_BLACK}\u@$_shorthost{\$?}\\$ ${RESET}"

# An approximate tcsh equivalent is:
# set prompt = '%n@%M:%c{%?}%# '
Expand Down
3 changes: 2 additions & 1 deletion bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ case "$-" in
esac

source ~/.bash/environment
source ~/.bash/general
source ~/.bash/colordefs
source ~/.bash/config
source ~/.bash/aliases
source ~/.bash/functions
source ~/.bash/mac
Expand Down

0 comments on commit 1c1ddae

Please sign in to comment.