-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bashrc
217 lines (179 loc) · 5.73 KB
/
.bashrc
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Sean Malloy's .bashrc
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# source global bash configuration
if [[ -f /etc/bashrc ]]; then
. /etc/bashrc
fi
# set OS type and version
if [[ -n $(which facter 2> /dev/null) ]]; then
OS_VERSION="$(facter osfamily)" # RedHat, Debian, etc
OS_VERSION="${OS_VERSION}$(facter operatingsystemmajrelease)"
else
# no facter ... must check stuff manually :-(
if [[ -f /etc/centos-release ]]; then
OS_VERSION="RedHat$(awk '{print $4}' /etc/centos-release | awk -F. '{print $1}')"
elif [[ -f /etc/redhat-release ]]; then
OS_VERSION="RedHat$(awk '{print $7}' /etc/redhat-release | awk -F. '{print $1}')"
elif [[ -f /etc/debian_version ]]; then
OS_VERSION="Debian"
else
OS_VERSION=""
fi
fi
# Additional Bash Include Directory
export BASH_INCLUDE_DIR=$HOME/.bash_files
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Enable Colors
if [ -x /usr/bin/dircolors ]; then
test -r $HOME/.dircolors && eval "$(dircolors -b $HOME/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto -F'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Set Shell Options
set -o vi
set -o noclobber
export TECH_DIR=$HOME/tech # top level dir for locally installed software
export BIN_DIR=$TECH_DIR/bin # directory for scripts, binaries, etc.
export MAN_DIR=$TECH_DIR/share/man # directory for man pages
export PROJ_DIR=$HOME/projects # directory for code projects
export VISUAL=vim # vim is my editor
export EDITOR=vim # vim is my editor
export RELEASE_TESTING=1 # For Perl Module Development
export HOSTNAME=$(hostname -s) # Short hostname of this computer
# Go Lang Variables
export GOROOT=$TECH_DIR/go
export GOPATH=$HOME/go
# Generic Aliases
alias ll='ls -l'
alias la='ls -A'
alias ltr='ls -ltr'
alias vi='vim'
alias c='clear'
alias h='history'
alias j='jobs -l'
alias mkdir='mkdir -p'
alias df='df -h'
alias bin='cd $BIN_DIR'
alias tech='cd $TECH_DIR'
alias cd..='cd ..'
alias ..='cd ..'
alias .2='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../../..'
# Puppet Aliases
alias p='puppet'
alias pd='puppet describe'
alias pr='puppet resource'
# Set PATH
export PATH=/usr/bin:/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games:/usr/local/bin
for DIR in $GOROOT/bin $GOPATH/bin $HOME/.rbenv/bin HOME/.plenv/bin $HOME/.vim/bin $BIN_DIR; do
if [[ -d $DIR ]]; then
if [[ ! $PATH =~ $DIR ]]; then
PATH=$DIR:$PATH
fi
fi
done
export MANPATH=$MAN_DIR:$MAN_PATH
### Setup plenv ###
if [[ -n "$(which plenv 2> /dev/null)" ]]; then
eval "$(plenv init -)"
fi
### Setup rbenv
if [[ -n "$(which rbenv 2> /dev/null)" ]]; then
eval "$(rbenv init -)"
fi
#### Git Setup ###
if [[ $OS_VERSION != 'RedHat7' ]]; then
if [ -f "$BASH_INCLUDE_DIR/git-completion.bash" ]; then
# Enable Git Autocomplete
echo "enabling git completion"
. $BASH_INCLUDE_DIR/git-completion.bash
fi
fi
if [ -f "$BASH_INCLUDE_DIR/git-prompt.bash" ]; then
# Add Git Branch To Prompt
export GIT_PS1_SHOWDIRTYSTATE=1
. $BASH_INCLUDE_DIR/git-prompt.bash
fi
### SSH Setup ##
SSH_DIR=$HOME/.ssh
SSH_SOCKET_DIR=$SSH_DIR/sockets
if [ ! -d "$SSH_SOCKET_DIR" ]; then
mkdir -p $SSH_SOCKET_DIR
chmod 700 $SSH_DIR
chmod 700 $SSH_SOCKET_DIR
fi
### TMUX Setup ###
export TMUX_INCLUDE_FILE="$BASH_INCLUDE_DIR/tmux.bash"
. $TMUX_INCLUDE_FILE
alias tmux='tmux -L $TMUX_SOCKET'
### Tmuxinator Setup ###
export TMUXINATOR_INCLUDE_FILE="$BASH_INCLUDE_DIR/tmuxinator.bash"
. $TMUXINATOR_INCLUDE_FILE
### FZF Setup ###
export FZF_INCLUDE_FILE="$BASH_INCLUDE_DIR/fzf.bash"
export FZF_DEFAULT_OPTS='-m -x'
. $FZF_INCLUDE_FILE
### Set Bash Prompt ###
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
PS1="\u@\h $RED\W$YELLOW\$(__git_ps1)$NO_COLOR$ "
### Shell Functions ###
# Create new puppet module
pmg() {
local PUPPET_MODULE_NAME="$1"
local PUPPET_MODULE_AUTHOR="seanmalloy"
local PUPPET_MODULE_FULL_NAME="${PUPPET_MODULE_AUTHOR}-${PUPPET_MODULE_NAME}"
if [[ -z $PUPPET_MODULE_NAME ]]; then
echo "ERROR: must sepcify puppet module name!!!"
return 1
fi
if [[ -e $PUPPET_MODULE_FULL_NAME ]]; then
echo "ERROR: file $PUPPET_MODULE_FULL_NAME already exists!!!"
return 1
fi
puppet module generate --skip-interview ${PUPPET_MODULE_FULL_NAME}
if [[ $? -ne 0 ]]; then
echo "ERROR: command 'puppet module generate ${PUPPET_MODULE_FULL_NAME}' failed!!!"
return 1
fi
cd $PUPPET_MODULE_FULL_NAME
git init .
}
# switch to a project directory
proj() {
if [ -z "$PROJ_DIR" ]; then
local PROJ_DIR="$HOME/projects"
fi
if [ ! -d "$PROJ_DIR" ]; then
mkdir -p $PROJ_DIR
fi
if [[ -z $1 ]]; then
local DIR=$(find $PROJ_DIR -maxdepth 1 -type d -print | grep -v "^$PROJ_DIR$" | awk -F / '{print $NF}' | fzf +m)
else
local DIR=$(find $PROJ_DIR -maxdepth 1 -type d -print | grep -v "^$PROJ_DIR$" | awk -F / '{print $NF}' | fzf +m -q $1 -1)
fi
cd $PROJ_DIR/$DIR
}
# fuzzy find RPM packages
fzpkg() {
repoquery -a --qf "%{name}.%{arch}" | fzf
}
### Custom Key Bindings ###
# CTRL-P: fzf RPM packages
bind '"\C-p":"$(fzpkg)\n"'