3 # Check for unsupported TERM variable
4 if ! tput init &> /dev/null; then
5 echo "Warning! TERM=$TERM unsupported, using TERM=xterm"
9 # Disable CTRL-s / CTRL-q
13 # Fancy PS1 with revision control status for git, hg, svn
15 [ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
17 find_up_recurse .git || return
18 GIT_PS1_SHOWDIRTYSTATE=1 \
19 GIT_PS1_SHOWUNTRACKEDFILES=1 \
20 __git_ps1 2> /dev/null
24 find_up_recurse .hg || return
25 b="$(hg branch 2>/dev/null)" || return
26 s="$(hg status | cut -c1 | sort -u | tr -d " \n")"
28 [ -n "$s" ] && echo -n " $s"
33 find_up_recurse .svn || return
34 s="$(svn status --ignore-externals 2>/dev/null | cut -c1 | sort -u | tr -d " \n")"
39 if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
40 debian_chroot=$(cat /etc/debian_chroot)
42 PS1='${debian_chroot:+($debian_chroot)}'
43 PS1="$PS1"'\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]'
44 PS1="$PS1"'\[\033[00;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]'
49 # Display return codes on error
50 function print_exit_code {
51 _exit_msg="\033[01;33mexit code: $?\033[00m"
52 if [ -z "${BASH_SOURCE[1]}" ]; then
57 trap print_exit_code ERR
62 eval $(TERM=xterm dircolors 2> /dev/null)
64 if [ "${DARKTERM:-1}" -eq 1 ]; then
66 # Sets colour scheme in apps like Vim
67 export COLORFGBG="15;0"
70 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
71 LSCOLORS="ExFxCxDxBxEGEDABAGACAD" # BSD ls
72 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
76 # Sets colour scheme in apps like Vim
77 export COLORFGBG="0;15"
80 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
81 LSCOLORS="exfxcxdxbxegedabagacad" # BSD ls
84 # Display 'hostname:workingdir'
85 DISPLAY_TITLE_COMMAND='echo -ne "\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\007"'
88 if [[ "$TERM" =~ ^xterm ]]; then
89 PROMPT_COMMAND="$DISPLAY_TITLE_COMMAND"
92 # screen window displays current command
93 if [[ "$TERM" =~ ^screen ]]; then
94 PROMPT_COMMAND="${DISPLAY_TITLE_COMMAND}; echo -ne '\033k\033\\'"
98 if [ "$TERM" = "xterm" ]; then
99 export TERM=xterm-256color
101 if [ "$TERM" = "screen-s" ]; then
102 export TERM=screen-256color-s
106 alias ls='ls --color=auto -v'
110 alias f='find . -iname'
111 alias webshare='python3 -mhttp.server'
114 alias grep='grep --color=auto --exclude "*.svn-base"'
115 alias scp='scp -o ControlPath=none'
117 alias watch='watch -n1'
118 alias sudo='sudo ' # ability to use aliases with sudo
119 alias sudosu='sudo su -l -s /bin/bash'
120 alias _psresources='ps -weo pid,user:16,%cpu,%mem,stat,start_time,bsdtime,args'
121 alias pscpu='_psresources --sort -%cpu|less -S'
122 alias psmem='_psresources --sort -%mem|less -S'
123 alias pstree='ps --forest -weo pid,user:16,args --sort start_time|less -S'
124 alias pstime='ps -weo pid,user:16,lstart,args --sort start_time|less -S'
125 alias pbcopy='xsel --clipboard --input'
126 alias pbcopym='xsel --input'
127 alias pbpaste='xsel --clipboard --output'
128 alias pbpastem='xsel --output'
136 echo -ne "\033]0;man $@\007"
139 LESS_TERMCAP_md=$'\E[01;38;5;74m' \
140 LESS_TERMCAP_me=$'\E[0m' \
141 LESS_TERMCAP_us=$'\E[04;38;5;146m' \
142 LESS_TERMCAP_ue=$'\E[0m' \
147 # Creates the directory if it doesn't exist, and changes into it
153 # Usage: editf somefile
154 # Does a recursive search of the current directory for somefile, then edits it
156 find . -iname "${1}" -exec $EDITORBG '{}' +
159 # Usage: edit somefile [otherfiles ...]
164 # Sets the nice and ionice priorities for the current shell to the lowest values
170 # SSH to an unknown host and print the new known_hosts entry
172 local new_known_hosts_file="$(mktemp)"
173 ssh -o UserKnownHostsFile="$new_known_hosts_file" "$@" echo Connection ok
174 cat "$new_known_hosts_file"
175 rm -f "$new_known_hosts_file"
178 # SSH without verifying host key
179 function ssh_unsafe {
180 ssh -o StrictHostKeyChecking=no "$@"
184 # Bash should check the terminal size after every command terminates
185 shopt -s checkwinsize
187 # Don't attempt to tab-complete an empty line
188 shopt -s no_empty_cmd_completion
190 # Prevent overwriting existing files on stdout redirection
196 export HISTCONTROL="erasedups:ignoredups"
197 export HISTSIZE="100000"
198 export HISTTIMEFORMAT="%F %T "
200 # Local customisations
201 [ -r "${HOME}/.bash/interactive_local" ] && source "${HOME}/.bash/interactive_local"
203 # Load bash completion if available
204 [ -r "/etc/bash_completion" ] && source "/etc/bash_completion"