Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 67 lines (57 sloc) 1.573 kb
d7802234 »
2012-02-21 Add SVN version / Thx to David Olivier
1 # Colors
2 NoColor="\e[0;0m"
3 Cyan="\e[0;36m"
4 Green="\e[0;32m"
5 Red="\e[0;31m"
6 Yellow="\e[0;33m"
7
8 # Prompts chars
9 UserPrompt="$"
10 RootPrompt="#"
11
12 # Contextual prompt
13 prompt() {
14 USERNAME=`whoami`
15 HOSTNAME=`hostname`
16 CURRENTPATH=`pwd | sed "s|$HOME|~|g"`
17
18 LEFTPROMPT=$Cyan$USERNAME@$HOSTNAME":"$Yellow$CURRENTPATH
19 let LEFTSIZE=$(echo -n "$USERNAME@$HOSTNAME:$CURRENTPATH" | wc -c)
20
21 RIGHTPROMPT=""
22 let RIGHTSIZE=0
23 if [ -d ".svn" ]; then
24 SVNSTATUS=$(svn status 2>&1)
25 echo $SVNSTATUS | grep 'not a working copy' 2>&1 > /dev/null
26 if [ $? -eq 1 ]; then
27 echo $SVNSTATUS | grep -P '^\s*[AMDCR]' 2>&1 > /dev/null
28 if [ $? -eq 0 ]; then
29 RIGHTPROMPT=$Red
30 else
31 RIGHTPROMPT=$Green
32 fi
33 BRANCH=$(svn info | grep 'Repository Root' | sed -r 's|^.*/([a-z]+)$|\1|')
34 RIGHTPROMPT=$RIGHTPROMPT"[SVN Repository $BRANCH]"
35 let RIGHTSIZE=$(echo -n "[SVN Repository $BRANCH]" | wc -c)
36 fi
37 fi
38
39 let BLANCKSIZE=${COLUMNS}-${LEFTSIZE}-${RIGHTSIZE}
40 RIGHTPROMPT=$RIGHTPROMPT$NoColor
41
42 echo -e -n "\n"$LEFTPROMPT
43 printf "%$(($BLANCKSIZE))s"
44 echo -e $RIGHTPROMPT
45 }
46
dea800b4 »
2012-02-21 Patch for windows Title
47 # Define PROMPT_COMMAND if not already defined (fix: Modifying title on SSH connections)
d7802234 »
2012-02-21 Add SVN version / Thx to David Olivier
48 if [ -z "$PROMPT_COMMAND" ]; then
dea800b4 »
2012-02-21 Patch for windows Title
49 case $TERM in
50 xterm*)
51 PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
52 ;;
53 screen)
54 PROMPT_COMMAND='printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
55 ;;
56 esac
d7802234 »
2012-02-21 Add SVN version / Thx to David Olivier
57 fi
58
dea800b4 »
2012-02-21 Patch for windows Title
59 # Main prompt
60 PROMPT_COMMAND="prompt;$PROMPT_COMMAND"
61
d7802234 »
2012-02-21 Add SVN version / Thx to David Olivier
62 if [ $EUID -ne 0 ]; then
63 PS1=$UserPrompt" "
64 else
65 PS1=$RootPrompt" "
66 fi
Something went wrong with that request. Please try again.