diff --git a/.bash_profile b/.bash_profile index a183746..d4057a9 100644 --- a/.bash_profile +++ b/.bash_profile @@ -42,7 +42,7 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { echo alias ssh='ssh-add -l >/dev/null 2>&1 && unalias ssh || { ssh-add && unalias ssh; }; ssh' else - echo -e '\033[1;31mProblem connecting to forwarded ssh-agent!\033[0m' + echo -e '$(tput setaf 1 || tput AF 1)Problem connecting to forwarded ssh-agent!$(tput op)' echo fi else @@ -61,11 +61,11 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { echo alias ssh='ssh-add -l >/dev/null 2>&1 && unalias ssh || { ssh-add && unalias ssh; }; ssh' else - echo "Problem connecting to local ssh-agent!" + echo "$(tput setaf 1 || tput AF 1)Problem connecting to local ssh-agent!$(tput op)" echo fi else - echo "Failed to start local ssh-agent!" + echo "$(tput setaf 1 || tput AF 1)Failed to start local ssh-agent!$(tput op)" echo fi fi diff --git a/.bashrc b/.bashrc index 60ae0e7..81137c5 100644 --- a/.bashrc +++ b/.bashrc @@ -1,5 +1,5 @@ -# Make bash a little more pleasent. -shopt -s cdspell checkhash checkjobs checkwinsize cmdhist dirspell histappend no_empty_cmd_completion +# Make bash a little more pleasent - these are valid for all versions. +shopt -s cdspell checkhash checkwinsize cmdhist histappend no_empty_cmd_completion # Exit the shell on a Ctl+D. IGNOREEOF=0 @@ -12,22 +12,44 @@ HISTSIZE=-1 HISTTIMEFORMAT="%d/%m/%y %H:%M:%S " history -r -# Set the prompts. -if (( ${BASH_VERSINFO[0]} >= 4 )); then - export PROMPT_DIRTRIM=2 - if (( $(id -u) == 0 )); then - PS1="[\[\033[1;31m\]\u\[\033[0m\]@\h] \w ->" - else - PS1="[\u@\h] \w ->" - fi +# Determine the colour of the username in the prompt. +if (( $(id -u) == 0 )); then + _COLOUR=1 # Red else - if (( $(id -u) == 0 )); then - PS1="[\[\033[1;31m\]\u\[\033[0m\]@\h] \$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}') ->" - else - PS1="[\u@\h] \$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}') ->" - fi + _COLOUR=2 # Green fi -PS4='+(\$?=$?) $BASH_SOURCE${FUNCNAME:+($FUNCNAME)}:$LINENO: ' + +# Version specific set up. +if (( ${BASH_VERSINFO[0]} >= 4 )); then + # Add to the shopts. + shopt -s checkjobs dirspell + + # Set the prompts. + PROMPT_DIRTRIM=2 + # No colour: + # PS1="[\u@\h] \w ->" + # Coloured username: + # PS1="[\[$(tput bold)$(tput setaf $_COLOUR)\]\u\[$(tput sgr0)\]@\h] \w ->" + # Coloured username + host: + # PS1="[\[$(tput bold)$(tput setaf $_COLOUR)\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \w ->" + # Coloured username + host + directory: + PS1="[\[$(tput bold)$(tput setaf $_COLOUR)\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\w\[$(tput sgr0)\] ->" +else + # Set the prompts. + # No colour: + # PS1="[\u@\h] \$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}') ->" + # Coloured username: + # PS1="[\[$(tput bold)$(tput setaf $_COLOUR)\]\u\[$(tput sgr0)\]@\h] \$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}') ->" + # Coloured username + host: + # PS1="[\[$(tput bold)$(tput setaf $_COLOUR)\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}') ->" + # Coloured username + host + directory: + PS1="[\[$(tput bold)$(tput setaf $_COLOUR)\]\u\[$(tput sgr0)\]@\[$(tput bold)$(tput setaf 3)\]\h\[$(tput sgr0)\]] \[$(tput bold)$(tput setaf 4)\]\$(echo \"\${PWD/#\$HOME/~}\" | awk -F/ '{if (NF>3) {printf \".../\" \$(NF-1) \"/\" \$NF} else {printf \$0}}')\[$(tput sgr0)\] ->" +fi +unset _COLOUR + +# Set the debugger prompt. +# PS4="+(\\\$? = \$?) \${BASH_SOURCE##*/}\${FUNCNAME:+(\$FUNCNAME)}:\$LINENO: " +PS4="+(\[\e[33m\]\\\$? = \$?\[$(tput sgr0)\]) \[$(tput bold)$(tput setaf 4)\]\${BASH_SOURCE##*/}\[$(tput sgr0)\]\${FUNCNAME:+(\[$(tput bold)$(tput setaf 2)\]\$FUNCNAME\[$(tput sgr0)\])}:\[$(tput bold)$(tput setaf 1)\]\$LINENO\[$(tput sgr0)\]: " # Platform specific set up. _PLATFORM="$(uname -s)"