dotfiles/.bashrc
2019-04-29 23:35:04 +01:00

90 lines
4.1 KiB
Bash

# 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"
HISTFILESIZE=100000
HISTIGNORE="w:bg:bg *:fg:fg *:jobs:exit:pwd:clear:history"
HISTSIZE=-1
HISTTIMEFORMAT="%d/%m/%y %H:%M:%S "
history -r
# Determine the colour of the username in the prompt.
if (( $(id -u) == 0 )); then
_COLOUR=1 # Red
else
_COLOUR=2 # Green
fi
# 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)"
if [ "$_PLATFORM" = "Linux" ]; then
# Linux specific aliases.
hash ftpwho >/dev/null 2>&1 && alias ftpwho='ftpwho -v'
hash iftop >/dev/null 2>&1 && alias iftop='TERM=vt100 iftop'
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 lynx >/dev/null 2>&1 && alias lynx='lynx -cfg=~/.lynx.cfg -lss=~/.lynx.lss'
hash minicom >/dev/null 2>&1 && alias minicom='minicom -m -c on'
hash mkpasswd >/dev/null 2>&1 && alias pwgen='mkpasswd -m sha512crypt'
hash pine >/dev/null 2>&1 && alias pine='pine -p "{mail.open-source.co.uk/Service=IMAP/User=darren@afterdark.org.uk/TLS/NoValidate-Cert/NoRsh}.pinerc"'
hash pinfo >/dev/null 2>&1 && alias info='pinfo'
hash ping >/dev/null 2>&1 && alias ping='ping -b'
# Linux specific functions.
psgrep() {
ps -auwwx | egrep "(RSS|$1)"
}
elif [ "$_PLATFORM" = "Darwin" ]; then
# Darwin specific aliases.
hash df >/dev/null 2>&1 && alias df='df -P'
hash ls >/dev/null 2>&1 && alias ls='ls -bFG'
hash top >/dev/null 2>&1 && alias top='top -o cpu -S'
else
echo "${BASH_SOURCE##*/}: unsupported platform: $_PLATFORM" >&2
fi
unset _PLATFORM
# Common aliases.
hash bc >/dev/null 2>&1 && alias bc='bc -lq'
hash curl >/dev/null 2>&1 && alias pastebin="curl -F 'sprunge=<-' http://sprunge.us"
hash diff >/dev/null 2>&1 && alias diff='diff -u'
hash egrep >/dev/null 2>&1 && alias egrep='egrep --color=auto'
hash fgrep >/dev/null 2>&1 && alias fgrep='fgrep --color=auto'
hash grep >/dev/null 2>&1 && alias grep='grep --color=auto'
hash screen >/dev/null 2>&1 && alias screen='screen -Ua'