96 lines
4.6 KiB
Bash
96 lines
4.6 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"
|
|
HISTFILE="$HOME/.bash_history-${HOSTNAME%%.*}"
|
|
HISTFILESIZE=100000
|
|
HISTIGNORE="bg:bg *:fg:fg *:jobs:exit: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)\]: "
|
|
export 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)\]: "
|
|
|
|
# The commands to execute before the prompt is displayed.
|
|
# PROMPT_COMMAND=""
|
|
|
|
# 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 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.opensourcerers.net/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)" | fgrep -v "(RSS|"
|
|
}
|
|
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 curl >/dev/null 2>&1 && imagebin() { curl -F file="@${1:-}" https://imagebin.ca/upload.php | grep ^url: | cut -d: -f2-; }
|
|
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 nc >/dev/null 2>&1 && alias pastebin='nc termbin.com 9999'
|
|
hash screen >/dev/null 2>&1 && alias screen='screen -Ua'
|