Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

123 lines (106 sloc) 3.025 kb
#!/bin/bash
set -o allexport
function prompt_command
{
TERMWIDTH=${COLUMNS}
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
usernam=$(whoami)
cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")
newPWD="${PWD}"
gitBranch=$(git branch 2>/dev/null | grep '^\*' | cut -c3-)
if [[ -z "$gitBranch" ]]; then
gitBranch=" "
else
gitBranch="$gitBranch"
fi
let promptsize=$(echo -n "--(${usernam}@${hostnam})-[$gitBranch]-(${PWD})--" | wc -c | tr -d " ")
let fillsize=${TERMWIDTH}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}-"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
let cut=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
fi
}
PROMPT_COMMAND=prompt_command
function setXtermTitle
{
export XTERM_TITLE=
if [ $TERM == xterm ]; then
if [ -n "$PERFORCE_PROJECT" ]; then
typeset proj="[$PERFORCE_PROJECT]"
else
typeset proj=
fi
typeset title="$proj"
if [ $# != 0 ]; then
title="$*${proj:+ $proj}"
fi
if [ -n "$title" ]; then
title="$title: "
fi
typeset h=
if [ "$HOSTNAME" != "dqw-linux" ]; then
h="$HOSTNAME:"
fi
XTERM_TITLE="\[\033]0;$h${title}\w\007\]"
else
XTERM_TITLE=
fi
twtty
}
alias st=setXtermTitle
function twtty
{
local GRAY="\[\033[1;30m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
local WHITE="\[\033[1;37m\]"
local NO_COLOUR="\[\033[0m\]"
local LIGHT_BLUE="\[\033[1;34m\]"
local RED="\[\033[0;31m\]"
local BRIGHT_RED="\[\033[1;31m\]"
local CYAN="\[\033[0;36m\]"
local BRIGHT_CYAN="\[\033[1;36m\]"
local YELLOW="\[\033[0;33m\]"
local BRIGHT_YELLOW="\[\033[1;33m\]"
local GREEN="\[\033[0;32m\]"
local BRIGHT_GREEN="\[\033[1;32m\]"
if [ "$(hostname)" == "lambda.local" ]; then
((SHLVL=SHLVL+1))
fi
if [ $SHLVL -lt 2 ]; then
local BASIC_TEXT="$GREEN"
local BRIGHT_TEXT="$BRIGHT_GREEN"
local DELIM_TEXT="$LIGHT_BLUE"
local BRANCH_TEXT="$BRIGHT_RED"
elif [ $SHLVL -lt 3 ]; then
local BASIC_TEXT="$YELLOW"
local BRIGHT_TEXT="$BRIGHT_YELLOW"
local DELIM_TEXT="$LIGHT_BLUE"
local BRANCH_TEXT="$BRIGHT_GREEN"
elif [ $SHLVL -lt 4 ]; then
local BASIC_TEXT="$CYAN"
local BRIGHT_TEXT="$BRIGHT_CYAN"
local DELIM_TEXT="$LIGHT_BLUE"
local BRANCH_TEXT="$BRIGHT_GREEN"
else
local BASIC_TEXT="$RED"
local BRIGHT_TEXT="$BRIGHT_RED"
local DELIM_TEXT="$LIGHT_BLUE"
local BRANCH_TEXT="$YELLOW"
fi
if [ "$(whoami)" = "root" ]; then
local USER_TEXT="\[\033[0;41m\]\[\033[1;37m\]"
else
local USER_TEXT=$BASIC_TEXT
fi
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 "
PS2="$DELIM_TEXT-$BASIC_TEXT-$BASIC_TEXT-$NO_COLOUR "
}
setXtermTitle
set +o allexport
Jump to Line
Something went wrong with that request. Please try again.