-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-functions.plugin.bash
163 lines (149 loc) · 3.92 KB
/
02-functions.plugin.bash
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
: <<EOC
gi() {
#--- FUNCTION ----------------------------------------------------------------
# NAME: gi
# DESCRIPTION: Install a grunt plugin and save to devDependencies
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
npm install --save-dev grunt-"$@"
}
gci() {
#--- FUNCTION ----------------------------------------------------------------
# NAME: gci
# DESCRIPTION: Install a grunt-contrib plugin and save to devDependencies
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
npm install --save-dev grunt-contrib-"$@"
}
EOC
cdd() {
local DIR
if [ -f "$1" ]; then
DIR=$(dirname "$1")
elif [ -d "$1" ]; then
DIR=$1
fi
cd $DIR
}
lsmod() {
local LSMOD
LSMOD=$(which /bin/lsmod)
if (( $? )); then
echo "Sorry, there isn't lsmod in system"
return
fi
if [ $# -eq 0 ]; then
$LSMOD
else
case $1 in
-h)
$LSMOD -h
;;
--help)
$LSMOD --help
;;
*)
OLDIFS=$IFS
IFS="|"
$LSMOD | egrep "$*"
IFS=$OLDIFS
unset OLDIFS
;;
esac
fi
}
ipaddr() {
ip addr show $1 | awk '/inet\>/ {print $2}'
}
aa_mod_parameters () {
N=/dev/null;
C=`tput op` O=$(echo -en "\n`tput setaf 2`>>> `tput op`");
for mod in $(cat /proc/modules|cut -d" " -f1);
do
md=/sys/module/$mod/parameters;
[[ ! -d $md ]] && continue;
m=$mod;
d=`modinfo -d $m 2>$N | tr "\n" "\t"`;
echo -en "$O$m$C";
[[ ${#d} -gt 0 ]] && echo -n " - $d";
echo;
for mc in $(cd $md; echo *);
do
de=`modinfo -p $mod 2>$N | grep ^$mc 2>$N|sed "s/^$mc=//" 2>$N`;
echo -en "\t$mc=`cat $md/$mc 2>$N`";
[[ ${#de} -gt 1 ]] && echo -en " - $de";
echo;
done;
done
}
join() {
#--- FUNCTION ----------------------------------------------------------------
# NAME: join
# DESCRIPTION: join arguments with first parameter as delimited
# PARAMETERS: delimited elements to join separated by spaces(IFS)
# RETURNS: -
#-------------------------------------------------------------------------------
local IFS="$1"
shift
echo "$*"
}
enable-bracketed-mode() {
printf "\e[?2004h"
}
disable-bracketed-mode() {
printf "\e[?2004l"
}
lndir1() {
fromdir=${1?Missing fromdir parameter}
todir=${2?Missing todir parameter}
abs=${fromdir%${fromdir#/}}
find "$fromdir" \( -type f -o -type d \) | while read frompath ; do
topath=${frompath#$fromdir}
topath=${topath#/}
[ -n "$topath" ] || topath="."
if [ -f "$frompath" ] ; then
if [ $abs ] ; then
ln -sf "$frompath" "$todir/$topath"
else
old_IFS=$IFS
IFS=/
set -- $todir/$topath
IFS=$old_IFS
dots=""
while [ $# -gt 0 ] ; do
[ $1 = "." ] || dots="$dots../"
shift
done
ln -sf "$dots$frompath" "$todir/$topath"
fi
else
mkdir -p "$todir/$topath"
fi
done
}
killfg() {
local PIDS=$(jobs -p)
if [[ -n $PIDS ]]; then
kill -9 $PIDS
fi
}
listening() {
if [ $# -eq 0 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P
elif [ $# -eq 1 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
else
echo "Usage: listening [pattern]"
fi
}
listening1() {
printf "\nchecking established connections\n\n"
for i in $(sudo lsof -i -n -P | grep TCP | grep ESTABLISHED | grep -v IPv6 | grep -v 127.0.0.1 | cut -d ">" -f2 | cut -d " " -f1 | cut -d ":" -f1); do
printf "$i : "
curl freegeoip.net/xml/$i -s -S | grep CountryName | cut -d ">" -f2 | cut -d"<" -f1
done
printf "\ndisplaying listening ports\n\n"
sudo lsof -i -n -P | grep TCP | grep LISTEN | cut -d " " -f 1,32-35
}