]> code.delx.au - dotfiles/blob - .bash/interactive
gitconfig: added expire-prune
[dotfiles] / .bash / interactive
1 #! bash
2
3 # 256 color terminal
4 if [[ "$TERM" =~ ^xterm ]]; then
5 export TERM=xterm-256color
6 fi
7 if [[ "$TERM" =~ ^screen ]]; then
8 export TERM=screen-256color-bce
9 fi
10
11 # Check for unsupported TERM variable
12 if ! tput init &> /dev/null; then
13 echo "Warning! TERM=$TERM unsupported, using TERM=xterm"
14 export TERM=xterm
15 fi
16
17 # Disable CTRL-s / CTRL-q
18 stty -ixon
19
20
21 # Fancy PS1 with revision control status for git, hg, svn
22
23 [ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
24 function my_git_ps1 {
25 find_up_recurse .git || return
26 GIT_PS1_SHOWDIRTYSTATE=1 \
27 GIT_PS1_SHOWUNTRACKEDFILES=1 \
28 __git_ps1 2> /dev/null
29 }
30
31 function my_hg_ps1 {
32 find_up_recurse .hg || return
33 b="$(hg branch 2>/dev/null)" || return
34 s="$(hg status | cut -c1 | sort -u | tr -d " \n")"
35 echo -n " ($b"
36 [ -n "$s" ] && echo -n " $s"
37 echo -n ")"
38 }
39
40 function my_svn_ps1 {
41 find_up_recurse .svn || return
42 s="$(svn status --ignore-externals 2>/dev/null | cut -c1 | sort -u | tr -d " \n")"
43 [ -z "$s" ] && return
44 echo -n " ($s)"
45 }
46
47 if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
48 debian_chroot=$(cat /etc/debian_chroot)
49 fi
50 PS1='${debian_chroot:+($debian_chroot)}'
51 PS1="$PS1"'\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]'
52 PS1="$PS1"'\[\033[00;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]'
53 PS1="$PS1"'\n\$ '
54
55
56
57 # Display return codes on error
58 function print_exit_code {
59 _exit_msg="\033[01;33mexit code: $?\033[00m"
60 if [ -z "${BASH_SOURCE[1]}" ]; then
61 echo -e "$_exit_msg"
62 fi
63 unset _exit_msg
64 }
65 trap print_exit_code ERR
66
67
68
69 # ls colours
70 eval $(TERM=xterm dircolors 2> /dev/null)
71
72 if [ "${DARKTERM:-1}" -eq 1 ]; then
73
74 # Sets colour scheme in apps like Vim
75 export COLORFGBG="15;0"
76
77 # Bold ls colours
78 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
79 LSCOLORS="ExFxCxDxBxEGEDABAGACAD" # BSD ls
80 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
81
82 else
83
84 # Sets colour scheme in apps like Vim
85 export COLORFGBG="0;15"
86
87 # Unbold ls colours
88 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
89 LSCOLORS="exfxcxdxbxegedabagacad" # BSD ls
90 fi
91
92 # Display 'hostname:workingdir'
93 DISPLAY_TITLE_COMMAND='echo -ne "\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\007"'
94
95 # xterm title
96 if [[ "$TERM" =~ ^xterm ]]; then
97 PROMPT_COMMAND="$DISPLAY_TITLE_COMMAND"
98 fi
99
100 # screen window displays current command
101 if [[ "$TERM" =~ ^screen ]]; then
102 PROMPT_COMMAND="${DISPLAY_TITLE_COMMAND}; echo -ne '\033k\033\\'"
103 fi
104
105 # Useful aliases
106 alias ls='ls --color=auto -v'
107 alias ll='ls -hlF'
108 alias la='ls -ha'
109 alias l='ls -halF'
110 alias f='find . -iname'
111 alias webshare='python3 -mhttp.server'
112 alias rm='rm -i'
113 alias less='less -R'
114 alias grep='grep --color=auto --exclude "*.svn-base"'
115 alias scp='scp -o ControlPath=none'
116 alias bc='bc -ql'
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'
129
130
131
132 # Super man!
133 # Colourful headings
134 # Terminal title
135 function man {
136 echo -ne "\033]0;man $@\007"
137
138 env \
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' \
143 man "$@"
144 }
145
146 # Usage: mcd somedir
147 # Creates the directory if it doesn't exist, and changes into it
148 function mcd {
149 mkdir -p "${1}" &&
150 cd "${1}"
151 }
152
153 # Usage: editf somefile
154 # Does a recursive search of the current directory for somefile, then edits it
155 function editf {
156 find . -iname "${1}" -exec $EDITORBG '{}' +
157 }
158
159 # Usage: edit somefile [otherfiles ...]
160 function edit {
161 $EDITORBG "$@"
162 }
163
164 # Sets the nice and ionice priorities for the current shell to the lowest values
165 function slowshell {
166 ionice -c 3 -p $$
167 renice -n 19 -p $$
168 }
169
170 # SSH to an unknown host and print the new known_hosts entry
171 function ssh_new {
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"
176 }
177
178 # SSH without verifying host key
179 function ssh_unsafe {
180 ssh -o StrictHostKeyChecking=no "$@"
181 }
182
183
184 # Bash should check the terminal size after every command terminates
185 shopt -s checkwinsize
186
187 # Don't attempt to tab-complete an empty line
188 shopt -s no_empty_cmd_completion
189
190 # Prevent overwriting existing files on stdout redirection
191 set -o noclobber
192
193 # Better history
194 shopt -s histappend
195 shopt -s cmdhist
196 export HISTCONTROL="erasedups:ignoredups"
197 export HISTSIZE="100000"
198 export HISTTIMEFORMAT="%F %T "
199
200 # Local customisations
201 [ -r "${HOME}/.bash/interactive_local" ] && source "${HOME}/.bash/interactive_local"
202
203 # Load bash completion if available
204 [ -r "/etc/bash_completion" ] && source "/etc/bash_completion"
205