9 # Check for unsupported TERM variable
10 if ! tput init &> /dev/null; then
11 echo "Warning! TERM=$TERM unsupported, using TERM=xterm"
15 # Disable CTRL-s / CTRL-q
18 # Sets colour scheme in apps like Vim
19 export COLORFGBG="15;0"
27 # Revision control status for git, hg, svn
29 [ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
31 find_up_recurse .git || return
32 GIT_PS1_SHOWDIRTYSTATE=1 \
33 GIT_PS1_SHOWUNTRACKEDFILES=1 \
34 __git_ps1 2> /dev/null
38 find_up_recurse .hg || return
39 b="$(hg branch 2>/dev/null)" || return
40 s="$(hg status | cut -c1 | sort -u | tr -d " \n")"
42 [ -n "$s" ] && echo -n " $s"
47 find_up_recurse .svn || return
48 s="$(svn status --ignore-externals 2>/dev/null | cut -c1 | sort -u | tr -d " \n")"
56 PS1="$PS1"'\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
57 PS1="$PS1"'\[\033[01;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]'
67 DISPLAY_TITLE_COMMAND='echo -ne "\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\007"'
69 if [[ "$TERM" =~ ^xterm ]]; then
70 PROMPT_COMMAND="$DISPLAY_TITLE_COMMAND"
73 if [[ "$TERM" =~ ^screen ]]; then
74 PROMPT_COMMAND="${DISPLAY_TITLE_COMMAND}; echo -ne '\033k\033\\'"
79 #################################
80 # Display return codes on error #
81 #################################
83 function print_exit_code {
84 _exit_msg="\033[01;33mexit code: $?\033[00m"
85 if [ -z "${BASH_SOURCE[1]}" ]; then
90 trap print_exit_code ERR
98 # Bash should check the terminal size after every command terminates
101 # Don't attempt to tab-complete an empty line
102 shopt -s no_empty_cmd_completion
104 # Prevent overwriting existing files on stdout redirection
110 export HISTCONTROL="erasedups:ignoredups"
111 export HISTSIZE="100000"
112 export HISTTIMEFORMAT="%F %T "
116 ##########################
117 # ls aliases and colours #
118 ##########################
121 eval $(TERM=xterm dircolors 2> /dev/null)
124 export LSCOLORS="ExFxCxDxBxEGEDABAGACAD"
127 if ls --color=auto -v &> /dev/null; then
128 alias ls='ls --color=auto -v'
129 elif gls --color=auto -v &> /dev/null; then
130 alias ls='gls --color=auto -v'
131 elif ls -G &> /dev/null; then
146 alias _psresources='ps -wAo pid,user,%cpu,%mem,stat,start,time,args'
147 if [ "$(uname)" = "Linux" ]; then
148 alias pscpu='_psresources --sort -%cpu|less -S'
149 alias psmem='_psresources --sort -%mem|less -S'
150 alias pstree='ps --forest -weo pid,user:16,args --sort start_time|less -S'
151 alias pstime='ps -wAo pid,user,lstart,args --sort start_time|less -S'
153 alias pscpu='_psresources -r|less -S'
154 alias psmem='_psresources -m|less -S'
155 alias pstime='ps -wAo pid,user,lstart,args|less -S'
163 alias f='find . -iname'
164 alias webshare='python3 -mhttp.server'
166 if echo x | grep -q --color=auto x &> /dev/null; then
167 alias grep='grep --color=auto'
169 alias scp='scp -o ControlPath=none'
171 alias watch='watch -n1'
172 alias sudo='sudo ' # ability to use aliases with sudo
173 alias sudosu='sudo su -l -s /bin/bash'
175 if ! which pbcopy &> /dev/null; then
176 alias pbcopy='xsel --clipboard --input'
177 alias pbcopym='xsel --input'
178 alias pbpaste='xsel --clipboard --output'
179 alias pbpastem='xsel --output'
186 echo -ne "\033]0;man $@\007"
189 LESS_TERMCAP_md=$'\E[01;38;5;74m' \
190 LESS_TERMCAP_me=$'\E[0m' \
191 LESS_TERMCAP_us=$'\E[04;38;5;146m' \
192 LESS_TERMCAP_ue=$'\E[0m' \
197 # Creates the directory if it doesn't exist, and changes into it
203 # Usage: editf somefile
204 # Does a recursive search of the current directory for somefile, then edits it
206 find . -iname "${1}" -exec $EDITORBG '{}' +
209 # Usage: edit somefile [otherfiles ...]
214 # Sets the nice and ionice priorities for the current shell to the lowest values
220 # SSH to an unknown host and print the new known_hosts entry
222 local new_known_hosts_file="$(mktemp)"
223 ssh -o UserKnownHostsFile="$new_known_hosts_file" "$@" echo Connection ok
224 cat "$new_known_hosts_file"
225 rm -f "$new_known_hosts_file"
228 # SSH without verifying host key
229 function ssh_unsafe {
230 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"
239 # Local customisations
240 [ -r "${HOME}/.bash/interactive_local" ] && source "${HOME}/.bash/interactive_local"
242 # Load bash completion if available
243 [ -r "/etc/bash_completion" ] && source "/etc/bash_completion"