forked from Edznux/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
300 lines (247 loc) · 6.86 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# Add global composer install to path
if [ -x "$(command -v composer)" ]; then
export PATH=$PATH:"$(composer global config home 2>/dev/null)""/vendor/bin/"
fi
if [ -z "$PS1" ]; then
return
fi
export GPG_TTY=$(tty)
cd
date=$(date)
load=$(awk '{print $1}' < /proc/loadavg)
root_usage=$(df -h / | awk '/\// {print $(NF-1)}')
memory_usage=$(free -m | awk '/Mem/ { printf("%3.1f%%", $3/$2*100) }')
swap_usage=$(free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }')
users=$(users | wc -w)
tmux_sessions=$(tmux ls 2>/dev/null)
tmux_state=$?
case $(hostname) in
"inva")
machineColor="0;36"
;;
"bebefedora")
machineColor="0;33"
;;
"Bebe")
machineColor="0;35"
;;
"common")
machineColor="1;31"
;;
"pidoor")
machineColor="0;34"
;;
*)
machineColor="1;33"
;;
esac
echo "System information as of: $date"
echo
printf "System load:\t%s\tMemory usage:\t%s\n" $load $memory_usage
printf "Usage on /:\t%s\tSwap usage:\t%s\n" $root_usage $swap_usage
printf "Local users:\t%s\n" $users
if [ $(cat .todo | head -c1 | wc -c) -ne 0 ]; then
echo
echo -e $(cat .todo)
fi
echo
if [ $tmux_state -eq 0 ]; then
echo "Available tmux sessions:"
echo -e "$tmux_sessions" | GREP_COLORS="mt=$machineColor" egrep '\(attached\)|'
else
echo "tmux is not running"
fi
echo
#setting up git bash prompt
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
#PS1='\u@\h:\w$(__git_ps1) \$ '
__git_ps1 ()
{
local b="$(git symbolic-ref HEAD 2>/dev/null)";
local bname="${b##refs/heads/}";
case $bname in
"master")
local bcolor="1;31"
;;
"develop")
local bcolor="36"
;;
*)
local bcolor="1;33"
;;
esac
if [ -n "$b" ]; then
printf " \001\e[""$bcolor""m\002(%s)\001\e[m\002" "$bname";
fi
}
all_colors ()
{
echo -e "\033[1;30mGRAY"
echo -e "\033[0;31mRED"
echo -e "\033[1;31mLIGHT_RED"
echo -e "\033[0;32mGREEN"
echo -e "\033[1;32mLIGHT_GREEN"
echo -e "\033[0;33mYELLOW"
echo -e "\033[1;33mLIGHT_YELLOW"
echo -e "\033[0;34mBLUE"
echo -e "\033[1;34mLIGHT_BLUE"
echo -e "\033[0;35mPURPLE"
echo -e "\033[1;35mLIGHT_PURPLE"
echo -e "\033[0;36mCYAN"
echo -e "\033[1;36mLIGHT_CYAN"
echo -e "\033[0;37mLIGHT_GRAY"
echo -e "\033[1;37mWHITE"
}
PS1="\t \[\e[38;5;253m\]\u\[\e[38;5;245m\]@\[\e[""$machineColor""m\]\h\[\e[m\]:\[\e[00;36m\][\w]\[\e[38;5;245m\]\$(__git_ps1)\[\e[0m\]\[\e[00;37m\]\[\e[0m\]\$\[\e[m\] \[\e[0;37m\]"
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors -b ~/.dir_colors`"
# history control !
export HISTCONTROL=ignoreboth:erasedups
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
#ccat with color
alias ccat='pygmentize'
# LS cmd
alias ls='ls --color=auto'
alias la='ls -ah'
alias ll='ls -lah'
alias l='ls'
#CD shortcut
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
#Changing du to have a default comportement that I like better
alias du='du -sh'
#clear shortcut
alias c='clear'
# GREP Styling
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
#Mkdir auto parents & verbose
alias mkdir='mkdir -pv'
#Human readable
alias du='du -kh'
alias df='df -kTh'
#Reload BashRc
alias bashrc='. ~/.bashrc'
#apt aliases
alias update='sudo apt-get update && sudo apt-get upgrade'
alias clean='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean'
#launch tmux in UTF8 mode (for putty)
alias tmux='tmux -u'
#using ip with colors
alias ip='ip -c'
# Weather in terminal (useless but pretty)
# Options described there: http://wttr.in/:help
weather() {
curl "http://wttr.in/${1-}?F2q";
}
lastWeatherDay=$(date -d "@$(stat -c %X ~/.lastweather)" +'%Y-%m-%d')
nowDay=$(date +'%Y-%m-%d')
if [ $lastWeatherDay != $nowDay ]; then
weather
touch ~/.lastweather
fi
#Extracting function
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ] ; then
# NAME=${1%.*}
# mkdir $NAME && cd $NAME
case $1 in
*.tar.bz2) tar xvjf ./$1 ;;
*.tar.gz) tar xvzf ./$1 ;;
*.tar.xz) tar xvJf ./$1 ;;
*.lzma) unlzma ./$1 ;;
*.bz2) bunzip2 ./$1 ;;
*.rar) unrar x -ad ./$1 ;;
*.gz) gunzip ./$1 ;;
*.tar) tar xvf ./$1 ;;
*.tbz2) tar xvjf ./$1 ;;
*.tgz) tar xvzf ./$1 ;;
*.zip) unzip ./$1 ;;
*.Z) uncompress ./$1 ;;
*.7z) 7z x ./$1 ;;
*.xz) unxz ./$1 ;;
*.exe) cabextract ./$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}
export EDITOR='vim'
#struct de gestion de clés
function sshagent_findsockets {
find /tmp -uid $(id -u) -type s -name agent.\* 2>/dev/null
}
function sshagent_testsocket {
if [ ! -x "$(which ssh-add)" ] ; then
echo "ssh-add is not available; agent testing aborted"
return 1
fi
if [ X"$1" != X ] ; then
export SSH_AUTH_SOCK=$1
fi
if [ X"$SSH_AUTH_SOCK" = X ] ; then
return 2
fi
if [ -S $SSH_AUTH_SOCK ] ; then
ssh-add -l > /dev/null
if [ $? = 2 ] ; then
echo "Socket $SSH_AUTH_SOCK is dead! Deleting!"
rm -f $SSH_AUTH_SOCK
return 4
else
echo "Found ssh-agent $SSH_AUTH_SOCK"
return 0
fi
else
echo "$SSH_AUTH_SOCK is not a socket!"
return 3
fi
}
function sshagent_init {
# ssh agent sockets can be attached to a ssh daemon process or an
# ssh-agent process.
AGENTFOUND=0
# Attempt to find and use the ssh-agent in the current environment
if sshagent_testsocket ; then AGENTFOUND=1 ; fi
# If there is no agent in the environment, search /tmp for
# possible agents to reuse before starting a fresh ssh-agent
# process.
if [ $AGENTFOUND = 0 ] ; then
for agentsocket in $(sshagent_findsockets) ; do
if [ $AGENTFOUND != 0 ] ; then break ; fi
if sshagent_testsocket $agentsocket ; then AGENTFOUND=1 ; fi
done
fi
# If at this point we still haven't located an agent, it's time to
# start a new one
if [ $AGENTFOUND = 0 ] ; then
eval `ssh-agent`
fi
# Clean up
unset AGENTFOUND
unset agentsocket
# Finally, show what keys are currently in the agent
ssh-add -l
}
alias sagent="sshagent_init"