Created
January 13, 2011 14:24
-
-
Save provideal/777926 to your computer and use it in GitHub Desktop.
make a prompt for ruby/rails/git development
This file contains hidden or 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
#!/bin/bash | |
function prompt_command { | |
local nowDate="`date "+%H:%M:%S|%a,%m-%d"`" | |
local rubyv='' | |
branch=`git branch 2> /dev/null` | |
if [ $? -eq 0 ]; then | |
local branch="`echo "$branch" | sed -n 's/^\* \(.*\)$/\1/p'`" | |
local temp=`ruby --version` | |
if [ $? -eq 0 ]; then | |
local rubyv="${temp:5:5}" | |
fi | |
fi | |
temp="-(${PWD})-XXX-$branch-$rubyv-(${nowDate})-" | |
let fillsize=${COLUMNS}-${#temp} | |
if [ "$fillsize" -gt "0" ]; then | |
fill="--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" | |
fill="${fill:0:${fillsize}}" | |
newPWD="${PWD}" | |
fi | |
if [ "$fillsize" -lt "0" ]; then | |
fill="" | |
let cut=3-${fillsize} | |
newPWD="...${PWD:${cut}}" | |
fi | |
local NO_COLOUR="\[\033[0m\]" | |
local WHITE="\[\033[1;37m\]" | |
local RED='\e[1;31m' | |
local GREEN='\e[1;32m' | |
local LIGHT_BLUE="\[\033[1;34m\]" | |
local YELLOW="\[\033[1;33m\]" | |
case $TERM in | |
xterm*|rxvt*) | |
TITLEBAR='\[\033]0;\w \u@\h\007\]' | |
;; | |
*) | |
TITLEBAR="" | |
;; | |
esac | |
PS1="${TITLEBAR}${YELLOW}-${NO_COLOUR}(${LIGHT_BLUE}${newPWD}${NO_COLOUR})${YELLOW}-${RED}\$?${YELLOW}-${GREEN}${branch}${YELLOW}-${GREEN}${rubyv}${YELLOW}-${fill}-${NO_COLOUR}[${LIGHT_BLUE}${nowDate}${NO_COLOUR}]${YELLOW}-\n-${LIGHT_BLUE}$(whoami)@$(hostname -s)${NO_COLOUR}\$ " | |
unset branch | |
} | |
PROMPT_COMMAND=prompt_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment