## Note! This prompt has been modified by arne to fit bashish
## the installation instructions has been removed
## and the title changing code has been removed
##
## everything else were left intact as this was quite beatiful code =)
## /arne


##  Bash prompt "theme" - shortstatus
##
##  What is it?
##  
##     Here's what I don't like in prompts: prompts that are packed with
##     too much information I need only occasionally, or that use a bunch of
##     characters to show a little information. I especially don't like
##     multiline prompts. I don't like slow prompts; this is usually caused by
##     executing a bunch of commands to build the prompt.
##     
##     I like having the full working directory in it, and showing it all in
##     "\u@\h:\w" format--I can paste that into an scp or rsync command to copy
##     files. I was pretty happy with that for a long time, but wanted a few
##     extra things.
##  
##     Namely, I'm always doing things that produce output into the current
##     directory, and it's useful to know whether I can write to it or not. So
##     I color-code the directory part of the prompt: green if I own it, cyan
##     if it's writeable, and red if it's nonwriteable.
##  
##     I also use ssh-agent and agent forwarding a lot. It's useful to know if
##     my agent has been forwarded or not and if a working agent's running. I
##     suppose it would actually be useful to know if the agent not only is
##     running but if it has keys--but that would mean running an external
##     command (ssh-add -l) and slowing the prompt down; no thanks.
##  
##  What do I do if it all goes horribly wrong?
##  
##     Use this prompt at your own risk. You can look at the code and
##     understand what it's doing. If you don't like it, change it, but don't
##     blame me when this thing deletes every file you own and overwrites
##     your libc.

# shortstatus - terse bash prompt uses text characteristics to show
# ssh-agent status, writability of current directory and exit code of
# last command, if nonzero. The prompt format is common; I got the idea
# for showing the exit code from "Dan's Prompt"
# http://www.dreaming.org/~giles/bashprompt/prompts/dan.html
#
# jeremy-bash@batray.net
#

THEME_AUTHOR="jeremy-bash@batray.net"

export T_normal=0
export T_bold=1
export T_underline=4
export C_owner='0;32'
export C_write='0;36'
export C_nowrite='0;31'
export C_error='1;31'

export DIRCOLOR=$T_normal
export EXIT_CODE=0
export CODE_COLOR=$T_normal
export CODE_STRING=
export USER_STYLE=$T_normal

prompt_command()
{
   EXIT_CODE=$?
   DIRCOLOR=$T_normal

   # Color-code directory
   if [ -O $PWD ]
   then
      DIRCOLOR=$C_owner
   elif [ -w $PWD ]
   then
      DIRCOLOR=$C_write
   else
      DIRCOLOR=$C_nowrite
   fi

   # Add a bold red number for exitcode if its nonzero
   if [ $EXIT_CODE -ne 0 ]
   then
      CODE_COLOR=$C_error
      CODE_STRING=\ $EXIT_CODE
   else
      CODE_COLOR=$T_normal
      CODE_STRING=
   fi

   # Underline username if ssh-agent is running
   if [ -S "$SSH_AUTH_SOCK" ]
   then
      USER_STYLE=$T_underline
   else
      USER_STYLE=$T_normal
   fi
}
export PROMPT_COMMAND=prompt_command

TITLE='\u@\h:\w'

PS1='\[\e[${USER_STYLE}m\]\u\[\e[${T_normal}m\]@\h:\[\e[${DIRCOLOR}m\]\w\[\e[${CODE_COLOR}m\]$CODE_STRING\[\e[${T_normal}m\]\$ '
export PS1
