vicho /.bashrc

I like to display the whole working directory in my prompt, but sometimes that gets too big. So, the my prompt displays the whole working directory if that doesn't exceed half the window size, otherwise, it removes some characters in the middle of the pwd string (I believe the topmost and bottommost directories are important to know where you are). The prompt also colours the host if we are in a ssh session and displays in red the exit status of the last command if it failed. I'd like to improve this to handle signals, so if the last command was killed by signal INT, the prompt should display INT instead of 130. My aliases are in .bash_aliases .
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If running interactively, then:
if [ "$PS1" ]; then

    # don't put duplicate lines in the history. See bash(1) for more options
    # export HISTCONTROL=ignoredups

    # enable color support of ls
    alias ls='ls --color=auto'
    eval `dircolors -b`

    # enable color support for grep
    export GREP_OPTIONS='--color=auto'

    # Aliases are in a separate file
    if [ -e $HOME/.bash_aliases ]; then
      . $HOME/.bash_aliases
    fi

    #PS1='\u@\h:\w\$ '

    export EXIT_CODE=0
    export CODE_STRING=

    prompt_command()
    {
      EXIT_CODE=$?
      if [ $EXIT_CODE -ne 0 ]
      then
        CODE_STRING="\[\e[1;31m\] $EXIT_CODE \[\e[0m\]"
      else
        CODE_STRING=''
      fi
      if [ -z "$SSH_CLIENT" ]; then
        COLORED_HOST='\h'
      else
        COLORED_HOST='\[\e[0;32m\h\[\e[0m'
      fi

      newPWD="${PWD/#$HOME/~}"
      local pwdmaxlen=$((${COLUMNS:-80}/3))
      [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="${newPWD:0:4}\[\e[1;30m\]...\[\e[0m\]${newPWD:7-$pwdmaxlen}"

      PS1="\u@${COLORED_HOST}$WINDOW:${newPWD}${CODE_STRING}\$ "
    }
    export PROMPT_COMMAND=prompt_command

    # enable programmable completion features (you don't need to enable
    # this, if it's already enabled in /etc/bash.bashrc).
    if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
    fi

    [ -d ~/bin ] && PATH=~/bin:$PATH
fi