-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
145 lines (103 loc) · 4.45 KB
/
bashrc
File metadata and controls
145 lines (103 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
umask 0022
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
unset COLORTERM # 256 colours makes my vim ugly.
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion -a -z "${BASH_COMPLETION}" ]
then
. /etc/bash_completion || true
fi
### General settings ###########################################################
PS1="\[\033[;32m\][\[\033[;39m\]\h\[\033[;32m\]@\[\033[;31m\]\A\[\033[01;34m\] \w\[\033[;32m\]]\[\033[00m\]\\$ "
### Exports ####################################################################
export PATH="~/.bin:${PATH}"
export EDITOR=vim VISUAL=vim PAGER=less
export LC_ALL=en_GB.utf8
export MANWIDTH=80 # 80-column man-pages, even when the terminal is wider
### History ####################################################################
# Append to history file, rather than overwrite it.
shopt -s histappend
export HISTIGNORE=" :&:ls:[bf]g:exit:cd"
export HISTCONTROL=ignoreboth # ignore duplicate entries, and ones that start with a space
export HISTFILESIZE=10000 HISTSIZE=10000
### Completion #################################################################
shopt -s no_empty_cmd_completion
# autocomplete for netcat is nice.
complete -F _known_hosts nc
# Hide these files from the completion suggestions.
export FIGNORE=CVS:.svn:.git
### Miscellanea ################################################################
# load the keychain environment for this host.
[ -r ~/.keychain/`hostname -f`-sh ] && . ~/.keychain/`hostname -f`-sh
### Aliases ####################################################################
alias aack='ack -a' # ack over all files, not just code.
alias alf='ack -af' # list all files in the tree. like find -type f, but with less svn/git spuff.
alias cw='cut -c-$COLUMNS' # limit output to the width of the screen
alias fcat='grep ^ '
alias ffx-open='while read url; do firefox "$url"; sleep 0.1; done'
alias hd='hexdump -C'
alias iotop='iotop -d3'
alias less="less -R"
alias nt='nice top'
alias ozdate='TZ=Australia/Canberra date'
alias msdate='TZ=America/Los_Angeles date'
alias kindle-backup='rsync -hav --delete /run/media/mlb/Kindle/ /home/local/mlb/.kindle/ --exclude-from ~/.kindle-excludes --stats'
alias sansa-backup='rsync -hav --delete /run/media/mlb/0123-4567/ /home/local/mlb/scratch/.sansa/ --exclude-from ~/.sansa-excludes --stats'
### Functions ##################################################################
# show vim help on a topic. eg. "vimhelp scrolloff"
function vimhelp() { vim -n "+help $1" "+only"; }
# view source of a perl module in Vim. eg. "pmvim Net::SNMP"
function pmvim() { perldoc -m "$1" | vim - -RnM "+set ft=perl"; }
complete -o bashdefault -F _perldoc pmvim
# quickfix for the search terms.
function fnf() { vim -q <(ack -H --nocolor --nogroup --column "$@"); }
# scrub out stale SSH keys.
function rm_bad_ssh_key()
{
[[ -n $1 ]] || return
if grep -q $1 /etc/ssh/ssh_known_hosts
then
echo Deleting $1 from system known_hosts files
sudo sed -i '/^\[\?'$1'/d' /etc/ssh/ssh_known_hosts
fi
if grep -q $1 ${HOME}/.ssh/known_hosts
then
echo Deleting $1 from local known_hosts files
sed -i '/^\[\?'$1'/d' ${HOME}/.ssh/known_hosts
fi
}
# colorified and paged version of svn diff
function csdiff() { svn diff "$@" | dos2unix | colordiff | less -RFX; }
# work around broken Fedora perldoc
perldoc () { command perldoc "$@" | less -F; }
# shortcut for perl one-liners
p1 () {
case "$1" in
-*) ;;
*) set -- -E "$@" ;;
esac
perl -MData::Dumper -E "sub D(\$){ say Dumper(shift) }" "$@"
}
# lists tabs in another firefox session that aren't already open.
othertabs () {
[ -n "$1" ] && comm -13 <(ffx-open-tabs | sort) <(ffx-open-tabs "$1" | sort)
}