Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Custom bash prompt from: http://www.linuxdoc.org/HOWTO/Bash-Prompt-HOWTO/x848.html
- # termwide prompt with tty number
- # by Giles - created 2 November 98, last tweaked 31 July 2001
- #
- # This is a variant on "termwide" that incorporates the tty number.
- #
- hostnam=$(hostname -s)
- usernam=$(whoami)
- ##temp="$(tty)"
- # Chop off the first five chars of tty (ie /dev/):
- ##cur_tty="${temp:5}"
- unset temp
- function prompt_command {
- # Find the width of the prompt:
- TERMWIDTH=${COLUMNS}
- # Replace home dir with ~. The # prior to ${HOME} restricts the match
- # to the start of the string only.
- TILDEPWD="${PWD/#${HOME}/~}"
- # Git branch name
- gitBRANCH=$(__git_ps1 "[%s]")
- #gitBRANCH=UNKNOWN
- # Fixup for |BISECTING noise that started with git 1.6.5
- gitBRANCH="${gitBRANCH/|BISECTING/}"
- # Add all the accessories below ...
- local temp="--(${TILDEPWD})---\D{%a %H:%M:%S}--${gitBRANCH}--(${usernam}@${hostnam})--"
- let fillsize=${TERMWIDTH}-${#temp}
- if [ "$fillsize" -gt "0" ]; then
- fill=" "
- # It's theoretically possible someone could need more
- # dashes than above, but very unlikely! HOWTO users,
- # the above should be ONE LINE, it may not cut and
- # paste properly
- fill="${fill:0:${fillsize}}"
- newPWD="${TILDEPWD}"
- fi
- if [ "$fillsize" -lt "0" ]; then
- fill=""
- let cut=3-${fillsize}
- newPWD="...${TILDEPWD:${cut}}"
- fi
- if [ "$(id -u)" -ne 0 ]; then echo "[$(__git_ps1 "%s")]" `date` `pwd` `history 1` >> ~/.shell.log; fi
- twtty
- }
- PROMPT_COMMAND=prompt_command
- function twtty {
- local NO_COLOR="\[\e[0m\]"
- local BG_BLACK="40;"
- local BG_RED="41;"
- local BG_GREEN="42;"
- local BG_YELLOW="43;"
- local BG_BLUE="44;"
- local BG_MAGENTA="45;"
- local BG_CYAN="46;"
- local BG_WHITE="47;"
- local FG_BLACK="1;30m"
- local FG_RED="1;31m"
- local FG_GREEN="1;32m"
- local FG_YELLOW="1;33m"
- local FG_BLUE="1;34m"
- local FG_MAGENTA="1;35m"
- local FG_CYAN="1;36m"
- local FG_WHITE="1;37m"
- local COLOR1="\[\e[${BG_GREEN}${FG_BLACK}\]"
- local COLOR2="\[\e[${BG_GREEN}${FG_WHITE}\]"
- if [ -z $gitBRANCH ]; then
- COLOR1="\[\e[${BG_WHITE}${FG_BLACK}\]"
- COLOR2="\[\e[${BG_WHITE}${FG_BLACK}\]"
- fi
- case $TERM in
- xterm*|rxvt*)
- if [ -z $gitBRANCH ]; then
- TITLEBAR='\[\e]0;\u@\h: (\w)\007\]'
- else
- TITLEBAR='\[\e]0;\u@\h: (\w) - ${gitBRANCH}\007\]'
- fi
- ;;
- *)
- TITLEBAR=""
- ;;
- esac
- # Bugger... TODO: put a # in as the prompt
- export PS1="$TITLEBAR\
- ${COLOR2} (\${newPWD})\
- ${COLOR1} \D{%a %H:%M:%S} ${COLOR2}\${gitBRANCH}${COLOR1} \${fill}\
- (\$usernam@\$hostnam) ${NO_COLOR}\nLaptop $ "
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement