]> code.delx.au - dotfiles/blob - .bash/interactive
bash: remove 'rm -i' alias
[dotfiles] / .bash / interactive
1 #! bash
2
3
4
5 ##################
6 # Terminal setup #
7 ##################
8
9 # Check for unsupported TERM variable
10 if ! tput init &> /dev/null; then
11 echo "Warning! TERM=$TERM unsupported, using TERM=xterm"
12 export TERM=xterm
13 fi
14
15 # Disable CTRL-s / CTRL-q
16 stty -ixon
17
18 # Sets colour scheme in apps like Vim
19 export COLORFGBG="15;0"
20
21
22
23 #############
24 # Fancy PS1 #
25 #############
26
27 # Revision control status for git, hg, svn
28
29 [ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
30 function my_git_ps1 {
31 find_up_recurse .git || return
32 GIT_PS1_SHOWDIRTYSTATE=1 \
33 GIT_PS1_SHOWUNTRACKEDFILES=1 \
34 __git_ps1 2> /dev/null
35 }
36
37 function my_hg_ps1 {
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")"
41 echo -n " ($b"
42 [ -n "$s" ] && echo -n " $s"
43 echo -n ")"
44 }
45
46 function my_svn_ps1 {
47 find_up_recurse .svn || return
48 s="$(svn status --ignore-externals 2>/dev/null | cut -c1 | sort -u | tr -d " \n")"
49 [ -z "$s" ] && return
50 echo -n " ($s)"
51 }
52
53 # Two line prompt
54
55 PS1=''
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\]'
58 PS1="$PS1"'\n\$ '
59
60
61
62 ################
63 # xterm titles #
64 ################
65
66 # hostname:workingdir
67 DISPLAY_TITLE_COMMAND='echo -ne "\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\007"'
68
69 if [[ "$TERM" =~ ^xterm ]]; then
70 PROMPT_COMMAND="$DISPLAY_TITLE_COMMAND"
71 fi
72
73 if [[ "$TERM" =~ ^screen ]]; then
74 PROMPT_COMMAND="${DISPLAY_TITLE_COMMAND}; echo -ne '\033k\033\\'"
75 fi
76
77
78
79 #################################
80 # Display return codes on error #
81 #################################
82
83 function print_exit_code {
84 _exit_msg="\033[01;33mexit code: $?\033[00m"
85 if [ -z "${BASH_SOURCE[1]}" ]; then
86 echo -e "$_exit_msg"
87 fi
88 unset _exit_msg
89 }
90 trap print_exit_code ERR
91
92
93
94 ################
95 # bash options #
96 ################
97
98 # Bash should check the terminal size after every command terminates
99 shopt -s checkwinsize
100
101 # Don't attempt to tab-complete an empty line
102 shopt -s no_empty_cmd_completion
103
104 # Prevent overwriting existing files on stdout redirection
105 set -o noclobber
106
107 # Better history
108 shopt -s histappend
109 shopt -s cmdhist
110 export HISTCONTROL="erasedups:ignoredups"
111 export HISTSIZE="100000"
112 export HISTTIMEFORMAT="%F %T "
113
114
115
116 ##########################
117 # ls aliases and colours #
118 ##########################
119
120 # GNU ls colours
121 eval $(TERM=xterm dircolors 2> /dev/null)
122
123 # BSD ls colours
124 export LSCOLORS="ExFxCxDxBxEGEDABAGACAD"
125
126 # Lets find the ls
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
132 alias ls='ls -G'
133 else
134 alias ls='ls -F'
135 fi
136 alias ll='ls -hlF'
137 alias la='ls -ha'
138 alias l='ls -halF'
139
140
141
142 ##############
143 # ps aliases #
144 ##############
145
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'
152 else
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'
156 fi
157
158
159 ##################
160 # Useful aliases #
161 ##################
162
163 alias f='find . -iname'
164 alias webshare='python3 -mhttp.server'
165 alias less='less -R'
166 if echo x | grep -q --color=auto x &> /dev/null; then
167 alias grep='grep --color=auto'
168 fi
169 alias scp='scp -o ControlPath=none'
170 alias bc='bc -ql'
171 alias watch='watch -n1'
172 alias sudo='sudo ' # ability to use aliases with sudo
173 alias sudosu='sudo su -l -s /bin/bash'
174 alias pbcopy='xsel --clipboard --input'
175 alias pbcopym='xsel --input'
176 alias pbpaste='xsel --clipboard --output'
177 alias pbpastem='xsel --output'
178
179 # Super man!
180 # Colourful headings
181 # Terminal title
182 function man {
183 echo -ne "\033]0;man $@\007"
184
185 env \
186 LESS_TERMCAP_md=$'\E[01;38;5;74m' \
187 LESS_TERMCAP_me=$'\E[0m' \
188 LESS_TERMCAP_us=$'\E[04;38;5;146m' \
189 LESS_TERMCAP_ue=$'\E[0m' \
190 man "$@"
191 }
192
193 # Usage: mcd somedir
194 # Creates the directory if it doesn't exist, and changes into it
195 function mcd {
196 mkdir -p "${1}" &&
197 cd "${1}"
198 }
199
200 # Usage: editf somefile
201 # Does a recursive search of the current directory for somefile, then edits it
202 function editf {
203 find . -iname "${1}" -exec $EDITORBG '{}' +
204 }
205
206 # Usage: edit somefile [otherfiles ...]
207 function edit {
208 $EDITORBG "$@"
209 }
210
211 # Sets the nice and ionice priorities for the current shell to the lowest values
212 function slowshell {
213 ionice -c 3 -p $$
214 renice -n 19 -p $$
215 }
216
217 # SSH to an unknown host and print the new known_hosts entry
218 function ssh_new {
219 local new_known_hosts_file="$(mktemp)"
220 ssh -o UserKnownHostsFile="$new_known_hosts_file" "$@" echo Connection ok
221 cat "$new_known_hosts_file"
222 rm -f "$new_known_hosts_file"
223 }
224
225 # SSH without verifying host key
226 function ssh_unsafe {
227 ssh -o StrictHostKeyChecking=no "$@"
228 }
229
230
231
232 ###########
233 # The end #
234 ###########
235
236 # Local customisations
237 [ -r "${HOME}/.bash/interactive_local" ] && source "${HOME}/.bash/interactive_local"
238
239 # Load bash completion if available
240 [ -r "/etc/bash_completion" ] && source "/etc/bash_completion"
241