#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting. # Bash specific configuration. __prompt_user_colour() { # Determine the colour of the username in the prompt. if [[ "$LOGNAME" == "root" ]]; then printf "%s" "1;31m" # Bright Red. elif [[ "$LOGNAME" == "tadgy" ]]; then printf "%s" "1;32m" # Bright Green. else printf "%s" "1;36m" # Bright Cyan. fi return 0 } # Determine the platform being logged into. PLATFORM="${PLATFORM:-$(uname -s)}" # 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 # History control. HISTCONTROL="ignoredups" HISTFILE="$HOME/.bash_history-${HOSTNAME%%.*}" HISTFILESIZE=1000000 HISTIGNORE="bg:bg *:fg:fg *:jobs:exit:clear:history" HISTSIZE=1000000 HISTTIMEFORMAT="%d/%m/%y %H:%M:%S " history -a history -r # Git prompt options. GIT_PROMPT_SHOW_TYPE=1 GIT_PROMPT_SHOW_UPSTREAM=1 GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 GIT_PROMPT_SHOW_IGNORED=1 GIT_PROMPT_SHOW_UNSTAGED=1 GIT_PROMPT_SHOW_UNCOMMITTED=1 GIT_PROMPT_SHOW_UNTRACKED=1 GIT_PROMPT_SHOW_STASH=1 # Version specific set up. if (( BASH_VERSINFO[0] >= 4 )); then # Add to the shopts. shopt -s checkjobs dirspell # Trim the path in the prompt. PROMPT_DIRTRIM=2 # Coloured username + host + directory in the prompt. PS1='[\[\033[$(__prompt_user_colour)\]\u\[\033[0m\]@\[\033[1;33m\]\h\[\033[0m\]] \[\033[1;34m\]\w\[\033[0m\]' else # Coloured username + host + directory in the prompt. PS1='[\[\033[$(__prompt_user_colour)\]\u\[\033[0m\]@\[\033[1;33m\]\h\[\033[0m\]] \[\033[1;34m\]$(printf "%s" "${PWD/#$HOME/~}" | awk -F/ '\''{if (NF>3) {printf ".../" $(NF-1) "/" $NF} else {printf $0}}'\'')\[\033[0m\]' fi # Set the debugger prompt. # shellcheck disable=SC2155 export PS4='+(\[\033[1;33m\]$?\[\033[0m\]) \[\033[1;34m\]${BASH_SOURCE##*/}\[\033[0m\]${FUNCNAME[0]:+(\[\033[1;32m\]${FUNCNAME[0]}\[\033[0m\])}:\[\033[1;31m\]$LINENO\[\033[0m\]: ' # Common aliases. hash bc >/dev/null 2>&1 && alias bc='bc -lq' hash grep >/dev/null 2>&1 && { alias egrep='grep -E --color=auto'; alias fgrep='grep -F --color=auto'; alias grep='grep --color=auto'; } # Platform specific set up. if [[ "$PLATFORM" = "Linux" ]]; then # Linux specific functions. hash ps grep >/dev/null 2>&1 && psgrep() { if [[ -n "$1" ]]; then # shellcheck disable=SC2009 ps -auwwx | command grep -E --color=always -- "(.*RSS.*|$1)" | command grep -F -v '(.*RSS.*|' else printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} " >&2 return 1 fi } # Linux specific aliases. hash diff >/dev/null 2>&1 && alias diff='diff --color=auto -u' hash ftpwho >/dev/null 2>&1 && alias ftpwho='ftpwho -v' hash gpg2 >/dev/null 2>&1 && alias gpg='command gpg2' && alias gpg2='gpg2 --pinentry-mode=loopback' hash iftop >/dev/null 2>&1 && alias iftop='TERM=vt100 iftop' hash iotop >/dev/null 2>&1 && alias iotop='TERM=linux iotop' hash ip >/dev/null 2>&1 && alias ip='ip -color=auto' hash last less >/dev/null 2>&1 && alias laston='last -a | less' hash ls >/dev/null 2>&1 && alias ls='ls -bFv --color=auto' hash minicom >/dev/null 2>&1 && alias minicom='minicom -m -c on' hash mkpasswd >/dev/null 2>&1 && { alias mkpasswd='mkpasswd -m sha512crypt'; alias pwgen='mkpasswd -m sha512crypt'; } hash nc >/dev/null 2>&1 && alias pastebin='nc termbin.com 9999' hash pinfo >/dev/null 2>&1 && alias info='pinfo' hash ping >/dev/null 2>&1 && alias ping='ping -b' hash xclip >/dev/null 2>&1 && alias file2clip='DISPLAY=:0.0 xclip -selection clipboard' elif [[ "$PLATFORM" = "Darwin" ]]; then # Darwin specific aliases (some dependant on macports). hash df >/dev/null 2>&1 && [[ ! -e "/opt/local/libexec/gnubin/df" ]] && alias df='df -kP' hash diff >/dev/null 2>&1 && alias diff='diff -u' [[ -e "/opt/local/libexec/gnubin//diff" ]] && alias diff='diff --color=auto -u' hash last less >/dev/null 2>&1 && alias laston='last | less' hash ls >/dev/null 2>&1 && alias ls='ls -bFGO' [[ -e "/opt/local/libexec/gnubin/ls" ]] && alias ls='ls -bFv --color=auto' [[ -e "/opt/local/libexec/gnubin/nc" ]] && alias pastebin='nc termbin.com 9999' [[ -e "/opt/local/bin/pinfo" ]] && alias info='pinfo' hash top >/dev/null 2>&1 && alias top='top -o cpu -S' else printf "%s: %s\\n" "${BASH_SOURCE##*/}" "unsupported platform: $PLATFORM" >&2 fi # Read in the shell configuration from .bashrc.d/*. for FILE in "$HOME"/.bashrc.d/*; do [[ -x "$FILE" ]] && source "$FILE" done unset FILE # Finalise the prompt. PS1+=' ->'