Created
January 8, 2009 21:24
-
-
Save ddollar/44894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ansi control sequences | |
BLACK="\[\033[0m\]" | |
BOLD_BLACK="\[\033[1;30m\]" | |
RED="\[\033[0;31m\]" | |
BOLD_RED="\[\033[1;31m\]" | |
GREEN="\[\033[0;32m\]" | |
BOLD_GREEN="\[\033[1;32m\]" | |
YELLOW="\[\033[0;33m\]" | |
BOLD_YELLOW="\[\033[1;33m\]" | |
BLUE="\[\033[0;34m\]" | |
BOLD_BLUE="\[\033[1;34m\]" | |
MAUVE="\[\033[0;35m\]" | |
BOLD_MAUVE="\[\033[1;35m\]" | |
CYAN="\[\033[0;36m\]" | |
BOLD_CYAN="\[\033[1;36m\]" | |
WHITE="\[\033[0;37m\]" | |
DEFAULT="\[\033[0;39m\]" | |
USER=$(whoami) | |
HOSTNAME=$(hostname) | |
PWD=$(pwd) | |
TIME=$(date "+%a, %b %d, %H:%M:%S") | |
TTY=$(tty|cut -d/ -f3) | |
LAST_PROMPT_DISPLAY_TIME=$(date +%s) | |
format_time() | |
{ | |
FTIME="$1" | |
HOURS=$(echo "${FTIME} 3600 / p" | dc) | |
FTIME=$(echo "${FTIME} 3600 % p" | dc) | |
MINS=$(echo "${FTIME} 60 / p" | dc) | |
FTIME=$(echo "${FTIME} 60 % p" | dc) | |
SECS="${FTIME}" | |
FORMATTED=$(printf "%0.2d:%0.2d" "${MINS}" "${SECS}") | |
if [ $HOURS != "0" ]; then | |
FORMATTED="${HOURS}:${FORMATTED}" | |
fi | |
echo $FORMATTED | |
} | |
PROMPT_COMMAND=' | |
echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"; | |
CURRENT_PROMPT_DISPLAY_TIME=$(date +%s) | |
PROMPT_DISPLAY_TIME=$(format_time $(($CURRENT_PROMPT_DISPLAY_TIME - $LAST_PROMPT_DISPLAY_TIME))) | |
LAST_PROMPT_DISPLAY_TIME=$(date +%s) | |
GIT_BRANCH=$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git branch | grep '^*' |sed s/\*\ //)"; fi) | |
if [ ! $GIT_BRANCH == "" ]; then | |
GIT_BRANCH_DISPLAY="$BOLD_BLACK[${CYAN}git:$GIT_BRANCH$BOLD_BLACK]" | |
GIT_BRANCH_TITLE=":$GIT_BRANCH" | |
else | |
GIT_BRANCH_DISPLAY="" | |
GIT_BRANCH_TITLE="" | |
fi | |
TITLE_HOSTNAME=$(hostname -s) | |
TITLE_DIR=$(basename $(pwd)) | |
TITLE_BRANCH=$GIT_BRANCH_TITLE | |
echo -ne "\033]0;$TITLE_HOSTNAME:$TITLE_DIR$TITLE_BRANCH\007"; | |
PS1="$BOLD_BLACK[$CYAN\u@$CYAN$HOSTNAME$BOLD_BLACK] [$CYAN$TTY/$PROMPT_DISPLAY_TIME$BOLD_BLACK] $GIT_BRANCH_DISPLAY | |
[$BOLD_YELLOW\w$BOLD_BLACK]$DEFAULT " | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment