-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_functions.txt
3317 lines (3140 loc) · 115 KB
/
.bash_functions.txt
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##################################################
# 1 SOPCAST #
##################################################
# #
# http://forum.wiziwig.eu/forums/14-Sopcast
# http://sopcast.ucoz.com/
# google keyword: sop://broker.sopcast
# install sopcast commandline version
# Archlinux: sopcast ( x64 https://www.archlinux.org/packages/multilib/x86_64/sopcast/)
# Archlinux: sopcast ( x32 https://www.archlinux.org/packages/community/i686/sopcast/)
# Ubuntu/Debian: sp-auth (https://launchpad.net/~jason-scheunemann/+archive/ppa)
# choose a players (cvlc is default)
SP_VIDPLAYER=cvlc
# SP_VIDPLAYER=vlc
# SP_VIDPLAYER=(vlc --control=lirc)
# SP_VIDPLAYER=mplayer
# SP_VIDPLAYER=(mplayer -cache 1000)
# wait X seconds to stabilize channel (make it longer if u got slower connection)
SP_SLEEP=15
# sopcast port and player port
SP_LOCAL_PORT=55050
SP_PLAYER_PORT=55051
# manually kill sopcast (sometimes it doesnt exit properly and still uses bandwidth in the background)
sppc-kill() { killall sp-sc ;}
# kills existing connection, starts a new connection, sleep X sec to stabilize the stream, waits to player to exit and kill itself
sppc() {
killall sp-sc &>/dev/null
(sp-sc "$1" $SP_LOCAL_PORT $SP_PLAYER_PORT &>/dev/null &)
sleep $SP_SLEEP
($SP_VIDPLAYER http://localhost:$SP_PLAYER_PORT)
wait
killall sp-sc
}
#### eng = english, ro = romanian, esp = espanol/spanish
# added on February 06, 2014
spp-doc-explorer.eng,ro() { sppc "sop://broker.sopcast.com:3912/149269" ;}
spp-doc-history.eng,ro() { sppc "sop://broker.sopcast.com:3912/148253" ;}
spp-doc-history2.eng,ro() { sppc "sop://broker.sopcast.com:3912/149268" ;}
spp-doc-natgeo.eng,ro() { sppc "sop://broker.sopcast.com:3912/148248" ;}
spp-doc-natgeowild.eng,ro() { sppc "sop://broker.sopcast.com:3912/148259" ;}
spp-doc-nature.eng,ro() { sppc "sop://broker.sopcast.com:3912/149267" ;}
spp-movie-hbo.eng,ro() { sppc "sop://broker.sopcast.com:3912/148883" ;}
spp-movie-hbo2.eng,ro() { sppc "sop://broker.sopcast.com:3912/120702" ;}
spp-tv-universal.eng,ro() { sppc "sop://broker.sopcast.com:3912/148255" ;}
spp-tv-axn.eng,ro() { sppc "sop://broker.sopcast.com:3912/148257" ;}
spp-tv-axncrime.eng,ro() { sppc "sop://broker.sopcast.com:3912/149261" ;}
##################################################
# .. SYSTEM FUNCTIONS #
##################################################
# #
##################################################
# .. DIRECTORY NAVIGATION #
##################################################
# http://dotfiles.org/~wesdeboer/.bashrc
function goto () {
dir=`find ~ -type d -name $1*`
if [ -d "$dir" ]; then
cd $dir
else
echo "Couldn't find $1"
fi
}
##################################################
# Cp with progress bar (using pv) #
##################################################
# #
function cp_p() {
if [ `echo "$2" | grep ".*\/$"` ]
then
pv "$1" > "$2""$1"
else
pv "$1" > "$2"/"$1"
fi
}
##################################################
# .. Mount/unmount CIFS shares; pseudo- #
# replacement for smbmount #
##################################################
## $1 = remote share name in form of //server/share
## $2 = local mount point
function cifsmount() { sudo mount -t cifs -o username=${USER},uid=${UID},gid=${GROUPS} $1 $2; }
function cifsumount() { sudo umount $1; }
##################################################
# Substitutes underscores for blanks in all the #
# filenames in a directory #
##################################################
# #
function blank_rename()
{
ONE=1 # For getting singular/plural right (see below).
number=0 # Keeps track of how many files actually renamed.
FOUND=0 # Successful return value.
for filename in * #Traverse all files in directory.
do
echo "$filename" | grep -q " " # Check whether filename
if [ $? -eq $FOUND ] #+ contains space(s).
then
fname=$filename # Yes, this filename needs work.
n=`echo $fname | sed -e "s/ /_/g"` # Substitute underscore for blank.
mv "$fname" "$n" # Do the actual renaming.
let "number += 1"
fi
done
if [ "$number" -eq "$ONE" ] # For correct grammar.
then
echo "$number file renamed."
else
echo "$number files renamed."
fi
}
##################################################
# Backup a file with a date-time stamp #
##################################################
# Usage "bu filename.txt"
function bu() { cp $1 ${1}-`date +%Y%m%d%H%M`.backup ; }
# #
##################################################
# Creates a backup of the file passed as #
# parameter with the date and time #
##################################################
# #
function bak()
{
cp $1 $1_`date +%H:%M:%S_%d-%m-%Y`
}
##################################################
# Backup .bash* files #
##################################################
# #
function backup_bashfiles()
{
ARCHIVE="$HOME/bash_dotfiles_$(date +%Y%m%d_%H%M%S).tar.gz";
cd ~
tar -czvf $ARCHIVE .bash_profile .bashrc .bash_functions .bash_aliases .bash_prompt
echo "All backed up in $ARCHIVE";
}
##################################################
# Creates an archive from directory #
##################################################
function mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; }
function mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }
function mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
function mkzip() { zip -r "${1%%/}.zip" "${1%%/}/"; }
function mkzip_() { zip -r "${1%%/}.zip" "$1" ; } # Create a ZIP archive of a file or folder.
##################################################
# Pull a single file out of a .tar.gz #
##################################################
##
function pullout() {
if [ $# -ne 2 ]; then
echo "need proper arguments:"
echo "pullout [file] [archive.tar.gz]"
return 1
fi
case $2 in
*.tar.gz|*.tgz)
gunzip < $2 | tar -xf - $1
;;
*)
echo $2 is not a valid archive
return 1
;;
esac
return 0
}
#################################################
# .. Checksum #
#################################################
# #
function checksum()
# copyright 2007 - 2010 Christopher Bratusek
{
action=$1
shift
if [[ ( $action == "-c" || $action == "--check" ) && $1 == *.* ]]; then
type="${1/*./}"
else type=$1
shift
fi
case $type in
md5 )
checktool=md5sum
;;
sha1 | sha )
checktool=sha1sum
;;
sha224 )
checktool=sha224sum
;;
sha256 )
checktool=sha256sum
;;
sha384 )
checktool=sha384sum
;;
sha512 )
checktool=sha512sum
;;
esac
case $action in
-g | --generate )
for file in "${@}"; do
$checktool "${file}" > "${file}".$type
done
;;
-c | --check )
for file in "${@}"; do
if [[ "${file}" == *.$type ]]; then
$checktool --check "${file}"
else $checktool --check "${file}".$type
fi
done
;;
-h | --help )
;;
esac
}
##################################################
# .. MD5 checksum
##################################################
# #
function md5()
{
echo -n $@ | md5sum
}
##################################################
# Encryption / decryption # copyright 2007 - 2010 Christopher Bratusek #
##################################################
## do twice to decrypt
# #
function crypt() {
if [[ -e "$1" ]]; then
tr a-zA-Z n-za-mN-ZA-M < "$1" > "$1".crypt
rm -f "$1"
mv "$1".crypt "$1"
fi
}
####################################################
# .. basic encrypt / decrypt #
# .. example: "encry filename" or "decry filename" #
####################################################
# #
function encry()
{
gpg -ac --no-options "$1"
}
function decry()
{
gpg --no-options "$1"
}
##################################################
##################################################
# Random data overwriting #
##################################################
## #
#function overwriter()
#{
## The author of this script, Elias Amaral,
## claims no copyright over it.
## http://iamstealingideas.wordpress.com/2010/05/20/writing-random-data-to-a-hard-drive-again
#msg() {
# printf "\n - $1\n\n" $2
#}
#mbs=4 # 4mb
#blocksize=$(($mbs * 1024 * 1024))
#dev=$1
#if [[ -z $dev ]]; then
# msg "usage: $0 <device>"; exit
#elif [[ ! -b $dev ]]; then
# msg "$dev: not a block device"; exit
#elif [[ ! -w $dev ]]; then
# msg "$dev: no write permission"; exit
#elif grep -q $dev /etc/mtab; then
# msg "$dev: mounted filesystem on device, omgomg!"; exit
#fi
#cat <<end
#This program writes random data to a hard disk.
#It is intended to be used before storing encrypted data.
#It may contain bugs (but seems to work for me).
#It seems you have chosen to wipe data from the disk $dev.
#Here is the partition table of this disk:
#end
#fdisk -l $dev
#echo
#echo 'Are you sure you want to proceed?'
#msg 'WARNING: IT WILL DESTROY ALL DATA ON THE DISK'
#read -p 'Type uppercase yes if you want to proceed: ' q
#if [[ $q != YES ]]; then
# exit
#fi
#while
# echo $i > step.new
# mv step.new step
# msg 'Writing at offset %s' $(($mbs * $i))M
# openssl rand \
# -rand /dev/urandom \
# $blocksize | \
# dd of=$dev \
# bs=$blocksize \
# seek=$i
#do
# let i++
#done
#msg Finished.
#}
#
#
#
#alias overwriter_='sudo dd if=/dev/zero bs=1M | openssl bf-cbc -pass pass:`cat /dev/urandom | tr -dc [:graph:] | head -c56` | sudo dd of=$dev bs=1M'
##################################################
# DOWLOADING FUN #
##################################################
# #
##################################################
# .. W3M w/ INLINE IMAGES #
##################################################
# #
# W3M Browser with inline images # https://plus.google.com/102499719144563443986/posts/Vja8W69iHoi
#w3mimg() { w3m -o imgdisplay=/usr/lib/w3m/w3mimgdisplay $1 ;}
##################################################
# 2 GOOLGE SEARCH FROM CLI W/ FIREFOX #
################################################## #
# #
function gf {
value="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$*")"
xdg-open "http://www.google.ch/search?q=$value"
}
##################################################
# 3 GOOGLE SEARCH FROM CLI W/ w3M #
##################################################
# #
function gw {
value="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$*")"
w3m "http://www.google.ch/search?q=$value"
}
##################################################
# Search IMDB.COM #
##################################################
function imdb()
{
firefox "http://www.imdb.com/find?s=all&q="${@}"&x=0&y=0" &
}
##################################################
# ThePirateBay.org torrent search #
##################################################
# #
#function piratebay()
#{
#lynx -dump http://thepiratebay.org/search/$@|awk '/TPB.torrent$/ {print $2}'
#}
###########################################################
# .. TRANSMISSION FUNCTIONS (alias these) #
###########################################################
# #
tsm() { transmission-remote --list ;} # numbers of ip being blocked by the blocklist # credit: smw from irc #transmission
tsm-count() { echo "Blocklist rules:" $(curl -s --data \
'{"method": "session-get"}' localhost:9091/transmission/rpc -H \
"$(curl -s -D - localhost:9091/transmission/rpc | grep X-Transmission-Session-Id)" \
| cut -d: -f 11 | cut -d, -f1) ;}
tsm-blocklist() { $PATH_SCRIPTS/ipblist.sh ;} # update blocklist
tsm-daemon() { systemctrl start transmission ;}
tsm-quit() { systemctrl stop transmission ;}
tsm-altspeedenable() { transmission-remote --alt-speed ;} # limit bandwidth
tsm-altspeeddisable() { transmission-remote --no-alt-speed ;} # dont limit bandwidth
tsm-add() { transmission-remote --add "$1" ;}
tsm-askmorepeers() { transmission-remote -t"$1" --reannounce ;}
tsm-pause() { transmission-remote -t"$1" --stop ;} # <id> or all
tsm-start() { transmission-remote -t"$1" --start ;} # <id> or all
tsm-purge() { transmission-remote -t"$1" --remove-and-delete ;} # delete data also
tsm-remove() { transmission-remote -t"$1" --remove ;} # leaves data alone
tsm-info() { transmission-remote -t"$1" --info ;}
tsm-speed() { while true;do clear; transmission-remote -t"$1" -i | grep Speed;sleep 1;done ;}
###########################################################
###### stream YouTube videos directly to your media player
###########################################################
# #
function mtube() {
video_id=$(curl -s $1 | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p");
mplayer -fs $(echo "http://youtube.com/get_video.php?$video_id");
}
##################################################################
###### download YouTube music playlist and convert it to mp3 files
##################################################################
# #
function yt-pl2mp3() { umph -m 50 $1 | cclive -f mp4_720p; IFS=$(echo -en "\n\b"); for track in $(ls | grep mp4 | awk '{print $0}' | sed -e 's/\.mp4//'); do (ffmpeg -i $track.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 $track.mp3); done; rm -f *.mp4 ; }
##################################################
# 4 CONVERT YOU TO MP3 USAGE: yt2mp3 <url> #
##################################################
# #
ytmp3() { youtube-dl -c --restrict-filenames --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" $@ ;}
##################################################
# .. youtube-viewer functions and subs #
##################################################
# #
yt-listen() { youtube-viewer -n $@ ;} # no video, music/audio only
yt-music() { youtube-viewer -n --category=Music --top ;} # show top music list
yts-amcmovietalk() { youtube-viewer -p PLBFB97E5B9494EEBD ;}
yts-amcmovietalk-mailbag() { youtube-viewer -p PLYNW0PN4_jrqlBqzAVRv3rfpo6nhzJnKp ;}
yts-alwayson() { youtube-viewer "Always On" --author=CNETTV --orderby=published --duration=long ;}
yts-btt-beyondthetrailer() { youtube-viewer -u beyondthetrailer ;}
yts-btt-thinkabouttheink() { youtube-viewer -u thinkabouttheink ;}
yts-catherinereitman() { youtube-viewer -u catherinereitman ;}
yts-greentvgreentv() { youtube-viewer -u greentvgreentv ;}
yts-homeorganizing() { youtube-viewer -u homeorganizing ;}
yts-happyconsolegamer() { youtube-viewer -u happyconsolegamer ;}
yts-kirstendirksen() { youtube-viewer -u kirstendirksen ;}
yts-knucklegame() { youtube-viewer -u knucklegame ;}
yts-lifehacker() { youtube-viewer -u lifehacker ;}
yts-jamesnintendonerd() { youtube-viewer -u jamesnintendonerd ;}
yts-midwaysimplicity() { youtube-viewer -u midwaysimplicity ;}
yts-midwaysimplicity-mtohami() { youtube-viewer -u mtohami ;}
yts-mma-arielhelwani() { youtube-viewer -u arielhelwani ;}
yts-mma-fueltv() { youtube-viewer -u fueltv ;}
yts-mma-gracieacademy() { youtube-viewer -u gracieacademy ;}
yts-mma-graciebreakdown() { youtube-viewer -u graciebreakdown ;}
yts-mma-karynbryant() { youtube-viewer -u karynbryant ;}
yts-mma-mmafightingonsbn() { youtube-viewer -u mmafightingonsbn ;}
yts-mma-thefightnetwork() { youtube-viewer -u thefightnetwork ;}
yts-mma-themmanuts() { youtube-viewer -u themmanuts ;}
yts-mma-ufc() { youtube-viewer -u ufc ;}
yts-mma-uncutsports() { youtube-viewer -u uncutsports ;}
yts-rallisp() { youtube-viewer -u rallisp ;}
yts-tmw-askhodgetwins() { youtube-viewer -u askhodgetwins ;}
yts-tmw-fastingtwins() { youtube-viewer -u fastingtwins ;}
yts-tmw-getfit4women() { youtube-viewer -u getfit4women ;}
yts-tmw-hodgetwins() { youtube-viewer -u hodgetwins ;}
yts-tmw-hodgetwinsonsports() { youtube-viewer -u hodgetwinsonsports ;}
yts-tmw-twinmuscleworkout() { youtube-viewer -u twinmuscleworkout ;}
yts-walkingdead() { youtube-viewer -p PLC7EC9FB2E211A261 ;}
yts-walkingdead-talkingdead() { youtube-viewer -p PLP63B9XPsQt3H_5xGXifFxFJE7-RsKFb6 ;}
yts-walkingdead-webisodes() { youtube-viewer -p PLC09448134D906619 ;}
yts-wwefannation() { youtube-viewer -u wwefannation ;}
##################################################
# 5 ls -a AFTER cd #
##################################################
# #
function cd()
{
builtin cd "$*" && ls -a
}
##################################################
# 6 DOWNLOAD ALL IMAGES FROM A 4CHAN THREAD #
##################################################
# #
function 4chanimages()
{
curl -s http://boards.4chan.org/wg/|sed -r 's/.*href="([^"]*).*/\1\n/g'|grep images|xargs wget
}
##################################################
# Download all files of a certain type with wget #
##################################################
###### usage: wgetall mp3 http://example.com/download/
# #
function wgetall() { wget -r -l2 -nd -Nc -A.$@ $@ ; }
##################################################
# Using PIPEs, Execute a command, convert output #
# to .png file, upload file to imgur.com, then #
# returning the address of the .png. #
##################################################
function imgur() { convert label:@- png:-|curl -F "image=@-" -F "key=1913b4ac473c692372d108209958fd15" http://api.imgur.com/2/upload.xml|grep -E -o "<original>(.)*</original>" | grep -E -o "http://i.imgur.com/[^<]*" ; }
##################################################
# 7 NETWORKING CONNECTIONS IP's #
##################################################
#
## check whether or not a port on your box is open
# #
function portcheck() { for i in $@;do curl -s "deluge-torrent.org/test-port.php?port=$i" | sed '/^$/d;s/<br><br>/ /g';done; }
##################################################
# 8 cleanly list available wireless networks (using iwlist)
##################################################
# #
function wscan()
{
iwlist wlan0 scan | sed -ne 's#^[[:space:]]*\(Quality=\|Encryption key:\|ESSID:\)#\1#p' -e 's#^[[:space:]]*\(Mode:.*\)$#\1\n#p'
}
##################################################
# 9 myip - finds your current IP if your connected to the internet
##################################################
# #
function myip()
{
lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g'
}
##################################################
# 10 find the IP addresses that are currently online in your network
##################################################
# #
function localIps()
{
for i in {1..254}; do
x=`ping -c1 -w1 192.168.1.$i | grep "%" | cut -d"," -f3 | cut -d"%" -f1 | tr '\n' ' ' | sed 's/ //g'`
if [ "$x" == "0" ]; then
echo "192.168.1.$i"
fi
done
}
##################################################
# 11 SHOW IP #copyright 2007 - 2010 Christopher Bratusek
##################################################
# #
function show_ip()
{
case $1 in
*help | "" )
echo -e "\n${ewhite}Usage:\n"
echo -e "${eorange}show_ip${ewhite} |${egreen} <interface> ${eiceblue}[show ip-address for <interface>]\
\n${eorange}show_ip${ewhite} |${egreen} external${eiceblue} [show external ip address]\n"
tput sgr0
;;
*external )
wget -q -O - http://showip.spamt.net/
;;
* )
LANG=C /sbin/ifconfig $1 | grep 'inet addr:' | cut -d: -f2 | gawk '{ print $1}'
;;
esac
}
##################################################
# 12 show Url information #
##################################################
# Usage: url-info "ur"
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# Modified by Silviu Silaghi (http://docs.opensourcesolutions.ro) to handle
# more ip adresses on the domains on which this is available (eg google.com or yahoo.com)
# Last updated on Sep/06/2010
# #
function url-info()
{
doms=$@
if [ $# -eq 0 ]; then
echo -e "No domain given\nTry $0 domain.com domain2.org anyotherdomain.net"
fi
for i in $doms; do
_ip=$(host $i|grep 'has address'|awk {'print $4'})
if [ "$_ip" == "" ]; then
echo -e "\nERROR: $i DNS error or not a valid domain\n"
continue
fi
ip=`echo ${_ip[*]}|tr " " "|"`
echo -e "\nInformation for domain: $i [ $ip ]\nQuerying individual IPs"
for j in ${_ip[*]}; do
echo -e "\n$j results:"
whois $j |egrep -w 'OrgName:|City:|Country:|OriginAS:|NetRange:'
done
done
}
##################################################
# Miscellaneous Fun. Some might find useful #
##################################################
# #
##################################################
# Create a new script, automatically populating #
# the shebang line, editing the script, and #
# making it executable. #
##################################################
##
function shebang() { if i=$(which $1); then printf '#!%s\n\n' $i > $2 && vim + $2 && chmod 755 $2; else echo "'which' could not find $1, is it in your \$PATH?"; fi; }
###################################
# 13 print multiplication tables #
###################################
# #
function multitables()
{
for i in {1..9}; do for j in `seq 1 $i`; do echo -ne "${j}x${i}=$((j*i))\t"; done; echo; done
}
################################################
# 14 ruler that stretches across the terminal #
################################################
# #
function ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=$( for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done ); str=$(echo $str | cut -c -$COLUMNS) ; echo $str; done; }
##################################################
# Reminder for whatever whenever #
##################################################
# #
function remindme()
{
sleep $1 && zenity --info --text "$2" &
}
##################################################
# Auto send an attachment from CLI #
##################################################
# #
function send() {
echo "File auto-sent from linux." | mutt -s "See Attached File" -a $1 $2
}
##########################################
# 15 Arch-wiki-docs simple search #
##########################################
# #
function archwikisearch() {
# old version
# cd /usr/share/doc/arch-wiki/html/
# grep -i "$1" index.html | sed 's/.*HREF=.\(.*\.html\).*/\1/g' | xargs opera -newpage
cd /usr/share/doc/arch-wiki/html/
for i in $(grep -li $1 *)
do
STRING=`grep -m1 -o 'wgTitle = "[[:print:]]\+"' $i`
LEN=${#STRING}
let LEN=LEN-12
STRING=${STRING:11:LEN}
LOCATION="/usr/share/doc/arch-wiki/html/$i"
echo -e " \E[33m$STRING \E[37m$LOCATION"
done
}
##################################################
# Weather and stuff #
##################################################
##################################################
# .. GOOGLE WEATHER #
##################################################
# #
myweather() { wget -qO- -U '' 'google.com/search?q=weather' | grep -oP '(-)?\d{1,3}\xB0[FC]' ;}
#################################################
###### 10-day forcast #
#################################################
# USAGE: forecast 50315 #
function forecast() {
_ZIP=$1
if [ $# = 1 ];then
printf "$_ZIP\n" | egrep '^[0-9][0-9][0-9][0-9][0-9]$' >>/dev/null
if [ $? = 0 ];then
printf "Your 10 Day Weather Forecast as follows:\n";
lynx -dump "http://www.weather.com/weather/print/$_ZIP" | sed -n '/%$/s/\[.*\]//p';
printf "\n"
elif [ $? = 1 ];then
printf "Bad ZIP code!\n"
fi
elif [ $# != 1 ];then
printf "You need to supply a ZIP code!\n"
fi
}
##################################################
# 16 temperature conversion #
##################################################
# script that lets the user enter
# a temperature in any of Fahrenheit, Celsius or Kelvin and receive the
# equivalent temperature in the other two units as the output.
# usage: convertatemp F100 (if don't put F,C, or K, default is F)
# #
function convertatemp()
{
if uname | grep 'SunOS'>/dev/null ; then
echo "Yep, SunOS, let\'s fix this baby"
PATH="/usr/xpg4/bin:$PATH"
fi
if [ $# -eq 0 ] ; then
cat << EOF >&2
Usage: $0 temperature[F|C|K]
where the suffix:
F indicates input is in Fahrenheit (default)
C indicates input is in Celsius
K indicates input is in Kelvin
EOF
fi
unit="$(echo $1|sed -e 's/[-[[:digit:]]*//g' | tr '[:lower:]' '[:upper:]' )"
temp="$(echo $1|sed -e 's/[^-[[:digit:]]*//g')"
case ${unit:=F}
in
F ) # Fahrenheit to Celsius formula: Tc = (F -32 ) / 1.8
farn="$temp"
cels="$(echo "scale=2;($farn - 32) / 1.8" | bc)"
kelv="$(echo "scale=2;$cels + 273.15" | bc)"
;;
C ) # Celsius to Fahrenheit formula: Tf = (9/5)*Tc+32
cels=$temp
kelv="$(echo "scale=2;$cels + 273.15" | bc)"
farn="$(echo "scale=2;((9/5) * $cels) + 32" | bc)"
;;
K ) # Celsius = Kelvin + 273.15, then use Cels -> Fahr formula
kelv=$temp
cels="$(echo "scale=2; $kelv - 273.15" | bc)"
farn="$(echo "scale=2; ((9/5) * $cels) + 32" | bc)"
esac
echo "Fahrenheit = $farn"
echo "Celsius = $cels"
echo "Kelvin = $kelv"
}
##################################################
# 18 convert phone numbers to letters/potentially english words
# Creator: asmoore82
##################################################
# #
function phone2text()
{
echo -n "Enter number: "
read num
# Create a list of possibilites for expansion by the shell
# the "\}" is an ugly hack to get "}" into the replacment string -
# this is not a clean escape sequence - the litteral "\" is left behind!
num="${num//2/{a,b,c\}}"
num="${num//3/{d,e,f\}}"
num="${num//4/{g,h,i\}}"
num="${num//5/{j,k,l\}}"
num="${num//6/{m,n,o\}}"
num="${num//7/{p,q,r,s\}}"
num="${num//8/{t,u,v\}}"
num="${num//9/{w,x,y,z\}}"
# cleaup from the hack - remove all litteral \'s
num="${num//\\/}"
echo ""
echo "Possible words are:"
for word in $( eval echo "$num" )
do
echo '>' "$word"
done
# End of File
}
##################################################
# .. SCREENSHOT FUNCTION W/ SCROT #
##################################################
# #
# take screenshot fullscreen, single window or draw a box
# demo video: http://www.youtube.com/watch?v=Hh8G1aBp8gc
pix() { scrot -d 2 "$PATH_SCREENSHOT/fullscr_`date +'%F_%Hh%Ms%S'`.png" ;}
pix-winarea() { sleep 2 && scrot -s "$PATH_SCREENSHOT/windowed_`date +'%F_%Hh%Ms%S'`.png" ;}
# take screenshot ( method 2 )
pixx() { import -pause 2 -window root "$PATH_SCREENSHOT/fullscr_`date +'%F_%Hh%Ms%S'`.png" ; }
pixx-winarea() { import -pause 2 "$PATH_SCREENSHOT/windowed_`date +'%F_%Hh%Ms%S'`.png" ;}
#screenshot-window() { import -pause 2 -frame -strip -quality 75 "$HOME/Pictures/Screenshots/pscreen-win_`date +'%F_%Hh%M'`.png" ;}
##################################################
# Resizing an image #
##################################################
# USAGE: image_resize "percentage of image resize" "input image" "output image"
function image_resize()
{
convert -sample "$1"%x"$1"% "$2" "$3"
}
##################################################
# Resize images #
##################################################
function resizeimg()
{
NAME_="resizeimg"
HTML_="batch resize image"
PURPOSE_="resize bitmap image"
PURPOSE_="resize bitmap image"
SYNOPSIS_="$NAME_ [-hlv] -w <n> <file> [file...]"
REQUIRES_="standard GNU commands, ImageMagick"
VERSION_="1.2"
DATE_="2001-04-22; last update: 2004-10-02"
AUTHOR_="Dawid Michalczyk <[email protected]>"
URL_="www.comp.eonworks.com"
CATEGORY_="gfx"
PLATFORM_="Linux"
SHELL_="bash"
DISTRIBUTE_="yes"
# This program is distributed under the terms of the GNU General Public License
usage () {
echo >&2 "$NAME_ $VERSION_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Options:
-w <n>, an integer referring to width in pixels; aspect ratio will be preserved
-v, verbose
-h, usage and options (this help)
-l, see this script"
exit 1
}
gfx_resizeImage() {
# arg check
[[ $1 == *[!0-9]* ]] && { echo >&2 $1 must be an integer; exit 1; }
[ ! -f $2 ] && { echo >&2 file $2 not found; continue ;}
# scaling down to value in width
mogrify -geometry $1 $2
}
# args check
[ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; }
# var init
verbose=
width=
# option and arg handling
while getopts vhlw: options; do
case $options in
v) verbose=on ;;
w) width=$OPTARG ;;
h) usage ;;
l) more $0; exit 1 ;;
\?) echo invalid argument, type $NAME_ -h for help; exit 1 ;;
esac
done
shift $(( $OPTIND - 1 ))
# check if required command is in $PATH variable
which mogrify &> /dev/null
[[ $? != 0 ]] && { echo >&2 the required ImageMagick \"mogrify\" command \
is not in your PATH variable; exit 1; }
for a in "$@";do
gfx_resizeImage $width $a
[[ $verbose ]] && echo ${NAME_}: $a
done
}
##################################################################
# TV/DVD/Video/Audio/Radio/Streams Copying/ripping/extracting #
##################################################################
#
##################################################################
# AUDIO #
##################################################################
#
##################################################################
# .. rip audio from video ("$1" for output file & "$2" for input file) #
##################################################################
# #
function audioextract()
{
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile "$1" "$2"
}
##################################################################
# .. FIX MP3 TAGS ENCODING (TO UTF-8)
##################################################################
# batch fixes all MP3s in one directory
# #
function mp3_tagging()
{
find . -iname "*.mp3" -execdir mid3iconv -e <encoding> {} \;
}
######################################################################
# .. RECORD AUDIO @ 45 DECIBBLE OGG FILE #
######################################################################
# record audio and use sox to eliminate silence
# outputs an ogg file that only contains the audio signal exceeding -45dB
# useful for recording radio scanner
# #
function audiorecord-45dB()
{
rec -r 44100 -p | sox -p "audio_name-$(date '+%Y-%m-%d').ogg" silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d
}
##################################################################
# .. FLAC2MP3: Author: Josh Bailey Email: jbsnake<at><nospam> usalug.org#
##################################################################
# #
function flac2mp3()
# call this like:
# flac2mp3 /path/to/source/file.flac /path/to/destination
# needs: getFileName function; flac encoder/decoder; lame
{
local old_file="${1}"
local new_dir="${2}"
local short_filename=`getFileName "${old_file}"`
local new_file="${short_filename:0:${#short_filename}-5}.mp3"
flac -d -o - "${old_file}" | lame -b 320 -h - > "${new_dir}/${new_file}"
}
##################################################################
# .. FLAC2OGG: Author: Josh Bailey Email: jbsnake<at><nospam> usalug.org#
##################################################################
#
function flac2ogg()
# call this like:
# flac2ogg /path/to/source/file.flac /path/to/destination
# needs: getFileName function; flac encoder/decoder; oggenc
{
local old_file="${1}"
local new_dir="${2}"
local short_filename=`getFileName "${old_file}"`
local new_file="${short_filename:0:${#short_filename}-5}.ogg"
###### get artist and album before release #########
# flac -d -o - "${old_file}" | oggenc -a "$artist" -l "$album" -t "${title}" - -o "${new_dir}/${new_file}"
####################################################
local title="${short_filename:0:${#short_filename}-4}"
flac -d -o - "${old_file}" | oggenc -t "${title}" - -o "${new_dir}/${new_file}"
}
#alias flvaudio='ffmpeg -i "$1" -f mp3 -vn -acodec copy output.mp3' # extract sound from flv & make mp3
##################################################################
# .. OGG2MP3 Author: Josh Bailey Email: jbsnake<at><nospam> usalug.org#
##################################################################
# #
function ogg2mp3()
# call this like:
# ogg2mp3 /path/to/source/file.flac /path/to/destination
# needs: getFileName function; oggdec; lame
{
local old_file="${1}"
local new_dir="${2}"
local short_filename=`getFileName "${old_file}"`
local new_file="${short_filename:0:${#short_filename}-4}.mp3"
local info_string=`get_ogg_info "$old_file"`
local cartist=`cut -d| -f1 ${info_string}`
local ctitle=`cut -d| -f2 ${info_string}`
local calbum=`cut -d| -f3 ${info_string}`
local cgenre=`cut -d| -f4 ${info_string}`
local cdate=`cut -d| -f5 ${info_string}`
local ctracknumber=`cut -d| -f6 ${info_string}`
oggdec "${old_file}" -o - | lame -b 320 --tt "$ctitle" --ta "$cartist" --tl "$calbum" --ty $cdate --tn $ctracknumber --tg "$cgenre" -h - > "${new_dir}/${new_file}"
sleep .5
}
##################################################################
# .. OGG_INFO Author: Josh Bailey Email: jbsnake<at><nospam> usalug.org#
##################################################################
# #
function ogg_info()
# call this like:
# ogg_info_string=`get_ogg_info "/path/to/file.ogg"`
# ofcourse the string would have to be parsed
# it is pipe | delimited
# in order artist, title, album, genre, date, and track number
# inStr function needed; vorbiscomment (comes with oggenc)
{
local turn=""
local index=0
local item=""
local cartist=""
local ctitle=""
local calbum=""
local cgenre=""
local cdate=""
local ctracknumber=""
vorbiscomment -l "$1" > info.lst
for turn in artist title album genre date tracknumber
do
tmp_comment=`grep -i "$turn" info.lst`
item=`inStr "=" "$tmp_comment"`
comment=${tmp_comment:${item}+1}
((index++))
case $index in
1) cartist="$comment";
;;
2) ctitle="$comment";
;;
3) calbum="$comment";
;;