Skip to content
Newer
Older
100644 123 lines (106 sloc) 2.95 KB
f36c699 @derekwyatt Initial commit
authored Mar 15, 2012
1 #!/bin/bash
2
3 set -o allexport
4 function prompt_command
5 {
6 TERMWIDTH=${COLUMNS}
7
8 hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
9
10 usernam=$(whoami)
11 cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")
12 newPWD="${PWD}"
13 gitBranch=$(git branch 2>/dev/null | grep '^\*' | cut -c3-)
14 if [[ -z "$gitBranch" ]]; then
15 gitBranch=" "
16 else
17 gitBranch="$gitBranch"
18 fi
19 let promptsize=$(echo -n "--(${usernam}@${hostnam})-[$gitBranch]-(${PWD})--" | wc -c | tr -d " ")
20 let fillsize=${TERMWIDTH}-${promptsize}
21 fill=""
22 while [ "$fillsize" -gt "0" ]
23 do
24 fill="${fill}-"
25 let fillsize=${fillsize}-1
26 done
27
28 if [ "$fillsize" -lt "0" ]
29 then
30 let cut=3-${fillsize}
31 newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
32 fi
33 }
34
35 PROMPT_COMMAND=prompt_command
36
37 function setXtermTitle
38 {
39 export XTERM_TITLE=
40 if [ $TERM == xterm ]; then
41 if [ -n "$PERFORCE_PROJECT" ]; then
42 typeset proj="[$PERFORCE_PROJECT]"
43 else
44 typeset proj=
45 fi
46 typeset title="$proj"
47 if [ $# != 0 ]; then
48 title="$*${proj:+ $proj}"
49 fi
50 if [ -n "$title" ]; then
51 title="$title: "
52 fi
53 typeset h=
54 if [ "$HOSTNAME" != "dqw-linux" ]; then
55 h="$HOSTNAME:"
56 fi
57 XTERM_TITLE="\[\033]0;$h${title}\w\007\]"
58 else
59 XTERM_TITLE=
60 fi
61 twtty
62 }
63
64 alias st=setXtermTitle
65
66 function twtty
67 {
68 local GRAY="\[\033[1;30m\]"
69 local LIGHT_GRAY="\[\033[0;37m\]"
70 local WHITE="\[\033[1;37m\]"
71 local NO_COLOUR="\[\033[0m\]"
72
73 local LIGHT_BLUE="\[\033[1;34m\]"
74
75 local RED="\[\033[0;31m\]"
76 local BRIGHT_RED="\[\033[1;31m\]"
77
78 local CYAN="\[\033[0;36m\]"
79 local BRIGHT_CYAN="\[\033[1;36m\]"
80
81 local YELLOW="\[\033[0;33m\]"
82 local BRIGHT_YELLOW="\[\033[1;33m\]"
83
84 local GREEN="\[\033[0;32m\]"
85 local BRIGHT_GREEN="\[\033[1;32m\]"
86
87 if [ "$(hostname)" == "lambda.local" ]; then
88 ((SHLVL=SHLVL+1))
89 fi
90 if [ $SHLVL -lt 2 ]; then
91 local BASIC_TEXT="$GREEN"
92 local BRIGHT_TEXT="$BRIGHT_GREEN"
93 local DELIM_TEXT="$LIGHT_BLUE"
94 local BRANCH_TEXT="$BRIGHT_RED"
95 elif [ $SHLVL -lt 3 ]; then
96 local BASIC_TEXT="$YELLOW"
97 local BRIGHT_TEXT="$BRIGHT_YELLOW"
98 local DELIM_TEXT="$LIGHT_BLUE"
99 local BRANCH_TEXT="$BRIGHT_GREEN"
100 elif [ $SHLVL -lt 4 ]; then
101 local BASIC_TEXT="$CYAN"
102 local BRIGHT_TEXT="$BRIGHT_CYAN"
103 local DELIM_TEXT="$LIGHT_BLUE"
104 local BRANCH_TEXT="$BRIGHT_GREEN"
105 else
106 local BASIC_TEXT="$RED"
107 local BRIGHT_TEXT="$BRIGHT_RED"
108 local DELIM_TEXT="$LIGHT_BLUE"
109 local BRANCH_TEXT="$YELLOW"
110 fi
111 if [ "$(whoami)" = "root" ]; then
112 local USER_TEXT="\[\033[0;41m\]\[\033[1;37m\]"
113 else
114 local USER_TEXT=$BASIC_TEXT
115 fi
116
117 PS1="$XTERM_TITLE$BASIC_TEXT-$DELIM_TEXT-($USER_TEXT\$usernam$NO_COLOUR$DELIM_TEXT@$BASIC_TEXT\$hostnam${DELIM_TEXT})-${DELIM_TEXT}[${BRANCH_TEXT}\$gitBranch${DELIM_TEXT}]-($BRIGHT_TEXT\${newPWD}$DELIM_TEXT)-$BASIC_TEXT\${fill}$BASIC_TEXT-\n$BASIC_TEXT-$DELIM_TEXT->$NO_COLOUR "
118 PS2="$DELIM_TEXT-$BASIC_TEXT-$BASIC_TEXT-$NO_COLOUR "
119 }
120
121 setXtermTitle
122 set +o allexport
Something went wrong with that request. Please try again.