forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.plugin.bash
executable file
·215 lines (195 loc) · 5.58 KB
/
base.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
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
cite about-plugin
about-plugin 'miscellaneous tools'
function ips ()
{
about 'display all ip addresses for this host'
group 'base'
if command -v ifconfig &>/dev/null
then
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
elif command -v ip &>/dev/null
then
ip addr | grep -oP 'inet \K[\d.]+'
else
echo "You don't have ifconfig or ip command installed!"
fi
}
function down4me ()
{
about 'checks whether a website is down for you, or everybody'
param '1: website url'
example '$ down4me http://www.google.com'
group 'base'
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
}
function myip ()
{
about 'displays your ip address, as seen by the Internet'
group 'base'
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
for url in ${list[*]}
do
res=$(curl -s "${url}")
if [ $? -eq 0 ];then
break;
fi
done
res=$(echo "$res" | grep -Eo '[0-9\.]+')
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
}
function pickfrom ()
{
about 'picks random line from file'
param '1: filename'
example '$ pickfrom /usr/share/dict/words'
group 'base'
local file=$1
[ -z "$file" ] && reference $FUNCNAME && return
length=$(cat $file | wc -l)
n=$(expr $RANDOM \* $length \/ 32768 + 1)
head -n $n $file | tail -1
}
function passgen ()
{
about 'generates random password from dictionary words'
param 'optional integer length'
param 'if unset, defaults to 4'
example '$ passgen'
example '$ passgen 6'
group 'base'
local i pass length=${1:-4}
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
echo "With spaces (easier to memorize): $pass"
echo "Without (use this as the password): $(echo $pass | tr -d ' ')"
}
# Create alias pass to passgen when pass isn't installed or
# BASH_IT_LEGACY_PASS is true.
if ! command -v pass &>/dev/null || [ "$BASH_IT_LEGACY_PASS" = true ]
then
alias pass=passgen
fi
function pmdown ()
{
about 'preview markdown file in a browser'
param '1: markdown file'
example '$ pmdown README.md'
group 'base'
if command -v markdown &>/dev/null
then
markdown $1 | browser
else
echo "You don't have a markdown command installed!"
fi
}
function mkcd ()
{
about 'make one or more directories and cd into the last one'
param 'one or more directories to create'
example '$ mkcd foo'
example '$ mkcd /tmp/img/photos/large'
example '$ mkcd foo foo1 foo2 fooN'
example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing'
group 'base'
mkdir -p -- "$@" && eval cd -- "\"\$$#\""
}
function lsgrep ()
{
about 'search through directory contents with grep'
group 'base'
ls | grep "$*"
}
function quiet ()
{
about 'what *does* this do?'
group 'base'
$* &> /dev/null &
}
function banish-cookies ()
{
about 'redirect .adobe and .macromedia files to /dev/null'
group 'base'
rm -r ~/.macromedia ~/.adobe
ln -s /dev/null ~/.adobe
ln -s /dev/null ~/.macromedia
}
function usage ()
{
about 'disk usage per directory, in Mac OS X and Linux'
param '1: directory name'
group 'base'
if [ $(uname) = "Darwin" ]; then
if [ -n "$1" ]; then
du -hd 1 "$1"
else
du -hd 1
fi
elif [ $(uname) = "Linux" ]; then
if [ -n "$1" ]; then
du -h --max-depth=1 "$1"
else
du -h --max-depth=1
fi
fi
}
if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then
# if user has installed todo plugin, skip this...
function t ()
{
about 'one thing todo'
param 'if not set, display todo item'
param '1: todo text'
if [[ "$*" == "" ]] ; then
cat ~/.t
else
echo "$*" > ~/.t
fi
}
fi
function command_exists ()
{
about 'checks for existence of a command'
param '1: command to check'
example '$ command_exists ls && echo exists'
group 'base'
type "$1" &> /dev/null ;
}
mkiso ()
{
about 'creates iso from current dir in the parent dir (unless defined)'
param '1: ISO name'
param '2: dest/path'
param '3: src/path'
example 'mkiso'
example 'mkiso ISO-Name dest/path src/path'
group 'base'
if type "mkisofs" > /dev/null; then
[ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1
[ -z ${2+x} ] && local destpath=../ || local destpath=$2
[ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3
if [ ! -f "${destpath}${isoname}.iso" ]; then
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}"
else
echo "${destpath}${isoname}.iso already exists"
fi
else
echo "mkisofs cmd does not exist, please install cdrtools"
fi
}
# useful for administrators and configs
function buf ()
{
about 'back up file with timestamp'
param 'filename'
group 'base'
local filename=$1
local filetime=$(date +%Y%m%d_%H%M%S)
cp -a "${filename}" "${filename}_${filetime}"
}
function del() {
about 'move files to hidden folder in tmp, that gets cleared on each reboot'
param 'file or folder to be deleted'
example 'del ./file.txt'
group 'base'
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash;
}