-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
210 lines (160 loc) · 6 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
###############
# Source other files
# Senstive functions which are not pushed to Github
# It contains GOPATH, some functions, aliases etc...
[ -r ~/.bash_private ] && source ~/.bash_private
# Get it from the original Git repo:
# https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
source ~/.git-prompt.sh
###############
# Exports (custom)
export GOPATH=/Users/iliec/Documents/_workspace/godev
export GOBIN=$GOPATH/bin
export PATH=$PATH:$HOME/bin:/usr/local/bin:$GOBIN
export EDITOR="vim"
# checkout `man ls` for the meaning
export LSCOLORS=cxBxhxDxfxhxhxhxhxcxcx
# enable GIT prompt color
export GIT_PS1_SHOWCOLORHINTS=true
# On Mac OS X: brew install bash-completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
###############
# Aliases (custom)
alias ..='cd ..'
alias mvim='/usr/local/bin/mvim -v'
alias vim='/usr/local/bin/mvim'
alias vi='/usr/local/bin/mvim'
alias ls='ls -GpF' # Mac OSX specific
alias ll='ls -alGpF' # Mac OSX specific
# most used fast git commands
alias t="tig status"
alias tigs="tig status" #old habits don't die
alias d='git diff'
###############
# Bash settings
# -- Prompt
# This is not used anymore as we use __git_ps1 for evaluatin the PS1, just here
# in case we might need it in the future
# PS1="\[$(tput setaf 6)\]\w\[$(tput sgr0)\]\[$(tput sgr0)\] \$ "
# 1. Git branch is being showed
# 2. Title of terminal is changed for each new shell
# 3. History is appended each time
export PROMPT_COMMAND='__git_ps1 "\[$(tput setaf 6)\]\w\[$(tput sgr0)\]\[$(tput sgr0)\]" " "; echo -ne "\033]0;$PWD\007"'
# -- History
# ignoreboth ignores commands starting with a space and duplicates. Erasedups
# removes all previous dups in history
export HISTCONTROL=ignoreboth:erasedups
export HISTFILE=~/.bash_history # be explicit about file path
export HISTSIZE=100000 # in memory history size
export HISTFILESIZE=100000 # on disk history size
export HISTTIMEFORMAT='%F %T '
shopt -s histappend # append to history, don't overwrite it
shopt -s cmdhist # save multi line commands as one command
# -- Completion
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind "set completion-ignore-case on" # note: bind used instead of sticking these in .inputrc
bind "set bell-style none" # no bell
bind "set show-all-if-ambiguous On" # show list automatically, without double tab
# bind "TAB: menu-complete" # TAB syle completion
# -- Functions
# Update Wifi setings to use Iasi static config
ManualWorkAddr () {
local RED=$(tput setaf 1)
local GREEN=$(tput setaf 2)
local NORMAL=$(tput sgr0)
local col=10 # change this to whatever column you want the output to start at
networksetup -setmanual Wi-Fi 10.220.40.54 255.255.0.0 10.220.0.1
if [ $? = 0 ]; then
printf 'Sucessfull updated IP Addr %s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf 'Updating IP Addr failed %s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
fi
networksetup -setdnsservers Wi-Fi 10.220.10.1 10.220.10.2
if [ $? = 0 ]; then
printf 'Sucessfull updated IP Addr %s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf 'Updating IP Addr failed %s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
fi
}
#flush DNS cache
flushDNScache (){
local RED=$(tput setaf 1)
local GREEN=$(tput setaf 2)
local NORMAL=$(tput sgr0)
local col=10 # change this to whatever column you want the output to start at
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say cache flushed
if [ $? = 0 ]; then
printf 'Flush DNS Cache %s%*s%s\n' "$GREEN" $col "[OK]" "$NORMAL"
else
printf 'Flush DNS Cache %s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
fi
}
# Set Wifi settings to use DHCP
DhcpAddr (){
local RED=$(tput setaf 1)
local GREEN=$(tput setaf 2)
local NORMAL=$(tput sgr0)
local col=10 # change this to whatever column you want the output to start at
#Set the interface called Wi-Fi to obtain it if it isn’t already
networksetup -setdhcp Wi-Fi
if [ $? = 0 ]; then
printf 'Sucessfull set Wi-Fi to use DHCP %s%*s%s\n' "$GREEN" $col "[OK]" "$NORMAL"
else
printf 'Updating Wi-Fi to use DHCP failed %s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
fi
#Set DNS Servers to use the DHCP ones on the Wi-Fi connection
networksetup -setdnsservers Wi-Fi
if [ $? = 0 ]; then
printf 'Sucessfull updated DNS Servers on Wi-Fi %s%*s%s\n' "$GREEN" $col "[OK]" "$NORMAL"
else
printf 'Failed updating DNS Servers %s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
fi
}
# extracts the given file
x () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# -- Misc
# Colored man pages
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
# check windows size if windows is resized
shopt -s checkwinsize
# autocorrect directory if mispelled
#shopt -s dirspell direxpand
# auto cd if only the directory name is given
#shopt -s autocd
#use extra globing features. See man bash, search extglob.
shopt -s extglob
#include .files when globbing.
shopt -s dotglob
PATH="/Users/iliec/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/Users/iliec/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/Users/iliec/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/Users/iliec/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/Users/iliec/perl5"; export PERL_MM_OPT;