-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_common
414 lines (339 loc) · 11.5 KB
/
.bashrc_common
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#-------------------------------------------------------------
# FJ Standard Bash Configuration File
# Include it in the system specific .bashrc file
#-------------------------------------------------------------
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
#----------------------------------------------------------------------
# General functions
#----------------------------------------------------------------------
#find replace
function find_functions()
{
echo "find <path> -name <name> -type f -exec sed -i 's/SEARCH_STR/REPLACE_STR/g' {} \;"
echo "see this https://www.cyberciti.biz/faq/howto-finding-files-by-date/"
echo "Following command will print the list of all pdf file that were accessed in last 60 days:"
echo "find <path> '*.pdf' -atime +60 -type -f"
echo "find -exec rm -f {} \;"
echo "find -delete -maxdepth 1"
}
function find-in-files()
{
find . -type f -name '$1' -exec grep -i '$2' {} +
}
#usage - killps(procname)
function killps()
{
ps -ef | grep $1 | awk '// { print $2 }'|xargs kill -s 9
}
#create the keys for the localhost
function create_keys()
{
ssh-keygen -t dsa
ssh-agent sh -c 'ssh-add < /dev/null && bash'
exec ssh-agent sh -c 'ssh-add </dev/null && exec /usr/local/bin/wmaker'
}
#distribute the secure keys for localhost to remotehost
#run create_keys() on localhost first !!
function ssh_keys()
{
if [ "$1" == "" ]
then
echo "usage: ssh_keys <login@remote_host_name>";
echo "run create_keys() " $(hostname ) " first !!"
return;
fi
remote_host=$1;
cat ~/.ssh/id_dsa.pub |ssh $remote_host 'sh -c "cat - >>~/.ssh/authorized_keys2"'
}
function untar()
{
for file in `ls *.tar`;
do tar -xvf $file;
done;
}
# Extract many files with one command
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar Jxvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip -d `echo $1 | sed 's/\(.*\)\.zip/\1/'` $1;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'" ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# Compress many files with one command
function compress () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar cvjf $1 ;;
*.tar.gz) tar cvzf $1 ;;
*.tar.xz) tar Jcvf $1 ;;
*.bz2) bzip2 $1 ;;
*.gz) gzip $1 ;;
*.tar) tar cvf $1 ;;
*.tbz2) tar cvjf $1 ;;
*.tgz) tar cvzf $1 ;;
*) echo "don't know how to extract '$1'" ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;36m") \
LESS_TERMCAP_md=$(printf "\e[1;36m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;33m") \
man "$@"
}
###############################################################
# I have no idea what all this shit below does
###############################################################
# 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 dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
#-------------------------------------------------------------
# Some settings
#-------------------------------------------------------------
#set -o notify
#set -o noclobber
#set -o ignoreeof
#set -o nounset
#set -o xtrace # useful for debuging
shopt -s cdspell
shopt -s cdable_vars
shopt -s checkhash
shopt -s cmdhist
shopt -s checkwinsize
shopt -s mailwarn
shopt -s sourcepath
shopt -s no_empty_cmd_completion
shopt -s histappend histreedit
shopt -s extglob # useful for programmable completion
shopt -s nocaseglob
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
export HISTCONTROL=ignoreboth
# 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 "$(SHELL=/bin/sh lesspipe)"
#----------------------------------------------------------------------
# X11 Settings
#----------------------------------------------------------------------
function xtitle ()
{
case $TERM in
*term | rxvt)
echo -n -e "\033]0;$*\007" ;;
*) ;;
esac
}
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# 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
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
#-------------------------------------------------------------
# Shell prompt
#-------------------------------------------------------------
# Define some colors first:
red='\[\033[1;31m\]'
blue='\[\033[1;34m\]'
green='\[\033[1;32m\]'
cyan='\[\033[1;36m\]'
nc='\[\033[0m\]' # No Color
function fastprompt()
{
unset PROMPT_COMMAND
case $TERM in
*term | rxvt )
PS1="[\h] \W > \[\033]0;[\u@\h] \w\007\]" ;;
*)
PS1="[\h] \W > " ;;
esac
}
function powerprompt()
{
_powerprompt()
{
LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g")
TIME=$(date +%H:%M)
}
PROMPT_COMMAND=_powerprompt
case $TERM in
*term | rxvt )
PS1="${blue}[\u@\h: \t${cyan}] ${red}{\w}${green}[\#]>${nc}" ;;
*)
PS1="[\$TIME - \$LOAD][\u@\h \#] \w >" ;;
esac
}
#powerprompt # this is the default prompt - might be slow
# If too slow, use fastprompt instead....
PS1='[\u@\h \#] \w >'
#---------------------------------------------------------------------
# Programmable completion features
#----------------------------------------------------------------------
shopt -s extglob # necessary
#set +o nounset # otherwise some completions will fail
complete -A hostname rsh rcp telnet rlogin r ftp ping disk
complete -A command nohup exec eval trace gdb
complete -A command command type which
complete -A export printenv
complete -A variable export local readonly unset
complete -A enabled builtin
complete -A alias alias unalias
complete -A function function
complete -A user su mail finger
complete -A helptopic help # currently same as builtins
complete -A shopt shopt
complete -A stopped -P '%' bg
complete -A job -P '%' fg jobs disown
complete -A directory mkdir rmdir
complete -A directory -o default cd
complete -f -d -X '*.gz' gzip
complete -f -d -X '*.bz2' bzip2
complete -f -o default -X '!*.gz' gunzip
complete -f -o default -X '!*.bz2' bunzip2
complete -f -o default -X '!*.pl' perl perl5
complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii
complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype
complete -f -o default -X '!*.pdf' acroread pdf2ps pdf
complete -f -o default -X '!*.+(pdf|ps)' gv
complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf
complete -f -o default -X '!*.tex' tex latex slitex latexfj
complete -f -o default -X '!*.lyx' lyx
complete -f -o default -X '!*.+(jpg|gif|xpm|png|bmp)' xv gimp
complete -f -o default -X '!*.mp3' mpg123
complete -f -o default -X '!*.ogg' ogg123
# This is a 'universal' completion function - it works when commands have
# a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a'
_universal_func ()
{
case "$2" in
-*) ;;
*) return ;;
esac
case "$1" in
\~*) eval cmd=$1 ;;
*) cmd="$1" ;;
esac
COMPREPLY=( $("$cmd" --help | sed -e '/--/!d' -e 's/.*--\([^ ]*\).*/--\1/'| \
grep ^"$2" |sort -u) )
}
complete -o default -F _universal_func ldd wget bash id info
_make_targets ()
{
local mdef makef gcmd cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# if prev argument is -f, return possible filename completions.
# we could be a little smarter here and return matches against
# `makefile Makefile *.mk', whatever exists
case "$prev" in
-*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;;
esac
# if we want an option, return the possible posix options
case "$cur" in
-) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;
esac
# make reads `makefile' before `Makefile'
if [ -f makefile ]; then
mdef=makefile
elif [ -f Makefile ]; then
mdef=Makefile
else
mdef=*.mk # local convention
fi
# before we scan for targets, see if a makefile name was specified
# with -f
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
if [[ ${COMP_WORDS[i]} == -*f ]]; then
eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion
break
fi
done
[ -z "$makef" ] && makef=$mdef
# if we have a partial word to complete, restrict completions to
# matches of that word
if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi
# if we don't want to use *.mk, we can take out the cat and use
# test -f $makef and input redirection
COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) )
}
complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake
_configure_func ()
{
case "$2" in
-*) ;;
*) return ;;
esac
case "$1" in
\~*) eval cmd=$1 ;;
*) cmd="$1" ;;
esac
COMPREPLY=( $("$cmd" --help | awk '{if ($1 ~ /--.*/) print $1}' | grep ^"$2" | sort -u) )
}
complete -F _configure_func configure
_killall ()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# get a list of processes (the first sed evaluation
# takes care of swapped out processes, the second
# takes care of getting the basename of the process)
COMPREPLY=( $( /usr/bin/ps -u $USER -o comm | \
sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \
awk '{if ($0 ~ /^'$cur'/) print $0}' ))
return 0
}
complete -F _killall killall killps
# 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 ]; then
. /etc/bash_completion
fi