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\]'
59 if ! [[ "$TERM" =~ ^screen ]]; then
62 PS1="$PS1"'\n\[\033k\033\\\]\$> '
71 PROMPT_COMMAND='echo -ne "\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\007"'
75 #################################
76 # Display return codes on error #
77 #################################
79 function print_exit_code {
80 _exit_msg="\033[01;33mexit code: $?\033[00m"
81 if [ -z "${BASH_SOURCE[1]}" ]; then
86 trap print_exit_code ERR
94 # Bash should check the terminal size after every command terminates
97 # Don't attempt to tab-complete an empty line
98 shopt -s no_empty_cmd_completion
100 # Prevent overwriting existing files on stdout redirection
106 export HISTCONTROL="erasedups:ignoredups:ignorespace"
107 export HISTSIZE="100000"
108 export HISTTIMEFORMAT="%F %T "
112 ##########################
113 # ls aliases and colours #
114 ##########################
117 eval $(TERM=xterm dircolors 2> /dev/null)
120 export LSCOLORS="ExFxCxDxBxEGEDABAGACAD"
123 if ls --color=auto -v &> /dev/null; then
124 alias ls='ls --color=auto -v'
125 elif gls --color=auto -v &> /dev/null; then
126 alias ls='gls --color=auto -v'
127 elif ls -G &> /dev/null; then
142 alias _psresources='ps -wAo pid,user,%cpu,%mem,stat,start,time,args'
143 if [ "$(uname)" = "Linux" ]; then
144 alias pscpu='_psresources --sort -%cpu|less -S'
145 alias psmem='_psresources --sort -%mem|less -S'
146 alias pstree='ps --forest -weo pid,user:16,args --sort start_time|less -S'
147 alias pstime='ps -wAo pid,user,lstart,args --sort start_time|less -S'
149 alias pscpu='_psresources -r|less -S'
150 alias psmem='_psresources -m|less -S'
151 alias pstime='ps -wAo pid,user,lstart,args|less -S'
159 alias f='find . -iname'
160 alias webshare='python3 -mhttp.server'
161 if echo x | grep -q --color=auto x &> /dev/null; then
162 alias grep='grep --color=auto'
164 alias scp='scp -o ControlPath=none'
166 alias watch='watch -n1'
167 alias sudo='sudo ' # ability to use aliases with sudo
168 alias sudosu='sudo su -l -s /bin/bash'
170 if ! which pbcopy &> /dev/null; then
171 alias pbcopy='xsel --clipboard --input'
172 alias pbcopym='xsel --input'
173 alias pbpaste='xsel --clipboard --output'
174 alias pbpastem='xsel --output'
181 echo -ne "\033]0;man $@\007"
184 LESS_TERMCAP_md=$'\E[01;38;5;74m' \
185 LESS_TERMCAP_me=$'\E[0m' \
186 LESS_TERMCAP_us=$'\E[04;38;5;146m' \
187 LESS_TERMCAP_ue=$'\E[0m' \
188 man --encoding ascii "$@"
192 # Creates the directory if it doesn't exist, and changes into it
198 # Usage: editf somefile
199 # Does a recursive search of the current directory for somefile, then edits it
201 find . -iname "${1}" -exec $EDITORBG '{}' +
204 # Usage: edit somefile [otherfiles ...]
209 # Sets the nice and ionice priorities for the current shell to the lowest values
215 # SSH to an unknown host and print the new known_hosts entry
217 local new_known_hosts_file="$(mktemp)"
218 ssh -o UserKnownHostsFile="$new_known_hosts_file" "$@" echo Connection ok
219 cat "$new_known_hosts_file"
220 rm -f "$new_known_hosts_file"
223 # SSH without verifying host key
224 function ssh_unsafe {
225 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"
234 # Local customisations
235 [ -r "${HOME}/.bash/interactive_local" ] && source "${HOME}/.bash/interactive_local"
237 # Load bash completion if available
238 [ -r "/etc/bash_completion" ] && source "/etc/bash_completion"