-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbash.alias.examples.sh
executable file
·355 lines (324 loc) · 8.35 KB
/
bash.alias.examples.sh
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
#!/bin/bash
# Generated by Alias Manager 1.6
# Christopher Welborn
# Note to user:
# If you must edit this file manually please stick to this style:
# Use tabs, not spaces.
# No tabs before definitons.
# Seperate lines for curly braces.
# Use 1 tab depth for start of code block in functions.
# Function description is first comment in code block.
# Alias description is comment right side of alias definition.
#
# ...if you use a different style it may or may not
# break the program and I can't help you.
# Aliases:
alias ....="cd /" # cd to root
alias ...="cd ../.." # cd up twice
alias ..="cd .." # cd up one dir
alias .="pwd" # print working directory path
alias aptfix="sudo apt-get -f update" # try to fix broken packages..
alias cdsym="cd `pwd -P`" # leave symlink to actual directory
alias fe=" find . -type f -iname '*'${1:-}'*' -exec ${2:-file} {} \; ; " # find file and execute command on it
alias ff=" find . -type f -iname '*'$*'*' -ls ; " # find file
alias la="ls -Fa --color" # list all files in dir
alias ll="ls -alh --group-directories-first --color" # long list dir
alias ls="ls -a --color" # list dir
alias lt="tree -a --dirsfirst | less -W" # list dir using tree
alias mkdir="mkdir -p" # prevents "clobbering" files
alias myaliases="aliasmgr -pca" # print my aliases
alias myfunctions="aliasmgr -pcf" # print my functions
alias pipinstall="sudo pip install" # install pip package by name
alias pipsearch="sudo pip search" # search for pip package by name
alias pwd="pwd -P" # show actual directory (not symlink)
alias redit="gksudo kate" # root editor
alias rfiles="gksudo dolphin" # root browser
# Functions:
function aptcheck()
{
# check if an apt package is installed by name...
if [ "${1}" = "" ] ; then
echo "Usage: aptcheck packagename"
else
aptitude show ${1} | grep "State:"
fi
}
function aptinstall()
{
# install apt package by name
if [ "${1}" == "" ] ; then
echo "Usage: aptinstall packagename"
else
sudo apt-get install ${1}
fi
}
function aptname()
{
# search for apt package by name
if [ "${1}" == "" ] ; then
echo "Usage: aptname packagename"
else
sudo apt-cache search --names-only ${1}
fi
}
function aptsearch()
{
# use dpkg to search for package (uses substring match)
if [ "${1}" = "" ] ; then
echo "Usage: aptsearch packagename"
else
dpkg -l *${1}*
fi
}
function ask()
{
# ask a question
echo -n "$@" '[y/n] ' ; read ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
function b64decode()
{
# decode base64 string
if [ "${1}" == "" ]; then
echo "Usage: b64decode QWxpYXMgTWFuYWdlcgo="
else
echo "${1}" | base64 -d
fi
}
function b64encode()
{
# encode a base64 string
if [ "${1}" == "" ]; then
echo "Usage: b64encode whattoencode"
else
echo "${1}" | base64
fi
}
function camrecord()
{
# record an uncrompressed avi with webcam
if [ "${1}" == "" ]; then
echo "Usage: camrecord newfilename.avi"
else
mencoder tv:// -tv driver=v4l:width=320:height=240:device=/dev/video0 -nosound -ovc lavc -o ${1}
fi
}
function debinstall()
{
# install a .deb package
if [ "${1}" = "" ] ; then
echo "Usage: debinstall debfile.deb"
else
if [ -f ${1} ]; then
sudo dpkg -i *${1}*
else
echo "debinstall: File not found at "${1}
fi
fi
}
function define()
{
# get definition of a word from the web
if [ "${1}" = "" ] ; then
echo "Usage: define dog"
else
lynx -dump -nonumbers -width=160 "http://dictionary.reference.com/browse/${1}" | grep -A15 "World English Dictionary"
fi
}
function extract()
{
# extract file by extension
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $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 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
function gnomeicons()
{
# turn gnome desktop icons on/off
if [ "${1}" == "" ] ; then
echo "Usage: gnomeicons true|false|on|off"
else
if [ "${1}" == "on" ] || [ "${1}" == "true" ]; then
# Turn desktop icons ON
gsettings set org.gnome.desktop.background show-desktop-icons true
echo "Gnome Desktop Icons: ON"
elif [ "${1}" == "off" ] || [ "${1}" == "false" ]; then
# Turn desktop icons OFF
gsettings set org.gnome.desktop.background show-desktop-icons false
echo "Gnome Desktop Icons: OFF"
else
# Invalid option
echo "Gnome Desktop Icons:"
echo "gnomeicons: Invalid value "${1}
echo "expecting: true, false, on, or off"
fi
fi
}
function ii()
{
# show current internet information
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo -e "\n${RED}Open connections :$NC "; netstat -pan --inet;
echo
}
function kd()
{
# change dir and list contents
if [ "${1}" == "" ] ; then
echo "Usage: kd directory_name"
else
cd "${1}"
pwd
ls -Fa --group-directories-first --color=auto
fi
}
function lowercase()
{
# makes all files in dir lowercase
for file ; do
filename=${file##*/}
case "$filename" in
*/*) dirname==${file%/*} ;;
*) dirname=.;;
esac
nf=$(echo $filename | tr A-Z a-z)
newname="${dirname}/${nf}"
if [ "$nf" != "$filename" ]; then
mv "$file" "$newname"
echo "lowercase: $file --> $newname"
else
echo "lowercase: $file not changed."
fi
done
}
function mkdircd()
{
# make dir and cd to it
# mkdir -p "$@" && eval cd "\"\$$#\""
if [ "${1}" = "" ] ; then
echo "Usage: mkdircd myDir"
else
mkdir -p ${1}
cd ${1}
fi
}
function my_ip()
{
# set MY_IP variable
MY_IP=$(/sbin/ifconfig wlan0 | awk '/inet/ { print $2 } ' | \
sed -e s/addr://)
MY_ISP=$(/sbin/ifconfig wlan0 | awk '/P-t-P/ { print $3 } ' | \
sed -e s/P-t-P://)
}
function showmyip()
{
# shows current IP address
echo "Gathering IP Address..."
my_ip
echo "IP: ${MY_IP}"
}
function spanish()
{
# get spanish equivalent of word
if [ "${1}" = "" ] ; then
echo "Usage: spanish dog"
else
lynx -dump -nonumbers -width=160 "http://spanish.dictionary.com/definition/${1}?src=en" | grep "${1} / "
fi
}
function symlink()
{
# create a symbolic link arg2 = arg1
if [ "${1}" = "" ] ; then
echo "expecting path to linked file! (source)"
echo "usage: symlink sourcefile destfile"
exit
fi
if [ "${2}" = "" ] ; then
echo "expecting path to link! (destination)"
echo "usage: symlink sourcefile destfile"
exit
fi
# Create the link
sudo ln -s "${1}" "${2}"
}
function weather()
{
# display weather per zipcode by christopher welborn.
if [ "${1}" = "" ] ; then
# echo "Usage: weather 90210"
lynx -dump -nonumbers -width=160 "http://weather.unisys.com/forecast.php?Name=35501" | grep -A13 'Latest Observation'
else
lynx -dump -nonumbers -width=160 "http://weather.unisys.com/forecast.php?Name=${1}" | grep -A13 'Latest Observation'
fi
}
function weatherweek()
{
# show weather for the week per zipcode by christopher welborn
if [ "${1}" = "" ] ; then
# echo "Usage: weatherweek [Your ZipCode]"
lynx -dump -nonumbers -width=160 "http://weather.unisys.com/forecast.php?Name=35501" | grep -A30 'Forecast Summary'
else
lynx -dump -nonumbers -width=160 "http://weather.unisys.com/forecast.php?Name=${1}" | grep -A30 'Forecast Summary'
fi
}
function wmswitch()
{
# switch window managers
if [ "${1}" == "" ] ; then
echo "Usage: wmswitch windowmanager"
echo " Like: wmswitch lightdm"
else
sudo dpkg-reconfigure ${1}
fi
}
# Exports:
export aptcheck
export aptinstall
export aptname
export aptsearch
export ask
export b64decode
export b64encode
export camrecord
export debinstall
export define
export extract
export gnomeicons
export ii
export kd
export lowercase
export mkdircd
export my_ip
export showmyip
export spanish
export symlink
export weather
export weatherweek
export wmswitch