blob: 441b3ff20931cf35a2420bbe44c8dfcdcc9a77ce [file] [log] [blame]
Eitan Adler3fc60b52012-04-17 00:24:58 -04001#!/usr/bin/env bash
Robert R Evansa4d02422010-10-02 15:07:29 -07002
Robert R Evans2010f012010-10-10 09:24:19 -07003# For generic functions.
4
Erich Smitha3c3caa2012-04-28 00:43:38 -04005ips ()
6{
7 about display all ip addresses for this host
8 ifconfig | grep "inet " | awk '{ print $2 }'
Robert R Evans2010f012010-10-10 09:24:19 -07009}
10
Erich Smitha3c3caa2012-04-28 00:43:38 -040011down4me ()
12{
13 about checks whether a website is down for you, or everybody
14 param 1: website url
15 example $ down4me http://www.google.com
16 curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
Mark Szymanski63c60e52011-03-11 20:32:46 -060017}
18
Erich Smitha3c3caa2012-04-28 00:43:38 -040019myip ()
20{
21 about displays your ip address, as seen by the Internet
22 res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
23 echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
Robert R Evans2010f012010-10-10 09:24:19 -070024}
Robert R Evansc9da0862010-10-06 17:27:55 -070025
Erich Smithe3011c52012-04-28 10:35:01 -040026
27pickfrom ()
28{
29 about picks random line from file
30 param 1: filename
31 example $ pickfrom /usr/share/dict/words
32 local file=$1
33 [ -z "$file" ] && reference $FUNCNAME && return
34 length=$(cat $file | wc -l)
35 n=$(expr $RANDOM \* $length \/ 32768 + 1)
36 head -n $n $f | tail -1
37}
38
Erich Smitha3c3caa2012-04-28 00:43:38 -040039pass ()
40{
Erich Smithe3011c52012-04-28 10:35:01 -040041 about generates random password from dictionary words
42 param optional integer length
43 param if unset, defaults to 4
44 example $ pass
45 example $ pass 6
46 local i pass length=${1:-4}
47 pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
Erich Smitha3c3caa2012-04-28 00:43:38 -040048 echo "With spaces (easier to memorize): $pass"
49 echo "Without (use this as the pass): $(echo $pass | tr -d ' ')"
Mark Szymanski57643402011-08-10 18:49:20 -050050}
51
Erich Smitha3c3caa2012-04-28 00:43:38 -040052pmdown ()
53{
54 about preview markdown file in a browser
55 param 1: markdown file
56 example $ pmdown README.md
57 if command -v markdown &>/dev/null
58 then
59 markdown $1 | browser
60 else
61 echo "You don't have a markdown command installed!"
62 fi
Mark Szymanski4898fa92011-05-27 11:47:55 -050063}
64
Erich Smitha3c3caa2012-04-28 00:43:38 -040065mkcd ()
66{
67 about make a directory and cd into it
68 param path to create
69 example $ mkcd foo
70 example $ mkcd /tmp/img/photos/large
71 mkdir -p "$*"
72 cd "$*"
Mark Szymanski123c3be2010-10-18 18:24:15 -050073}
Robert R Evansc9da0862010-10-06 17:27:55 -070074
Erich Smitha3c3caa2012-04-28 00:43:38 -040075lsgrep ()
76{
77 about search through directory contents with grep
78 ls | grep "$*"
Robert R Evans2010f012010-10-10 09:24:19 -070079}
80
81
Erich Smitha3c3caa2012-04-28 00:43:38 -040082pman ()
83{
84 about view man documentation in Preview
85 param 1: man page to view
86 example $ pman bash
87 man -t "${1}" | open -f -a $PREVIEW
Robert R Evans2010f012010-10-10 09:24:19 -070088}
89
Erich Smitha3c3caa2012-04-28 00:43:38 -040090
91pcurl ()
92{
93 about download file and Preview it
94 param 1: download URL
95 example $ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf
96 curl "${1}" | open -f -a $PREVIEW
Robert R Evans2010f012010-10-10 09:24:19 -070097}
98
Erich Smitha3c3caa2012-04-28 00:43:38 -040099pri ()
100{
101 about display information about Ruby classes, modules, or methods, in Preview
102 param 1: Ruby method, module, or class
103 example $ pri Array
104 ri -T "${1}" | open -f -a $PREVIEW
105}
106
107quiet ()
108{
Mark Szymanski62295972010-11-20 16:27:47 -0600109 $* &> /dev/null &
110}
111
Erich Smitha3c3caa2012-04-28 00:43:38 -0400112banish-cookies ()
113{
114 about redirect .adobe and .macromedia files to /dev/null
Mark Szymanski5a7174a2010-11-04 13:09:40 -0500115 rm -r ~/.macromedia ~/.adobe
116 ln -s /dev/null ~/.adobe
117 ln -s /dev/null ~/.macromedia
118}
Robert R Evans2010f012010-10-10 09:24:19 -0700119
Robert R Evans2010f012010-10-10 09:24:19 -0700120usage ()
121{
Erich Smitha3c3caa2012-04-28 00:43:38 -0400122 about disk usage per directory, in Mac OS X and Linux
123 param 1: directory name
Florian Baumanne45e72e2010-11-02 14:50:45 +0100124 if [ $(uname) = "Darwin" ]; then
125 if [ -n $1 ]; then
126 du -hd $1
127 else
128 du -hd 1
129 fi
130
131 elif [ $(uname) = "Linux" ]; then
132 if [ -n $1 ]; then
133 du -h --max-depth=1 $1
134 else
135 du -h --max-depth=1
136 fi
137 fi
Mark Szymanski123c3be2010-10-18 18:24:15 -0500138}
Mark Szymanski4b26a782010-11-05 15:02:12 -0500139
Erich Smitha3c3caa2012-04-28 00:43:38 -0400140t ()
141{
142 about one thing todo
143 param if not set, display todo item
144 param 1: todo text
145 if [[ "$*" == "" ]] ; then
146 cat ~/.t
147 else
148 echo "$*" > ~/.t
149 fi
Florian Baumanncecbae52010-11-08 21:31:11 +0100150}
151
Erich Smitha3c3caa2012-04-28 00:43:38 -0400152command_exists ()
153{
154 about checks for existence of a command
155 param 1: command to check
156 example $ command_exists ls && echo 'exists'
Jesus de Mula Cano229aa832011-03-07 00:02:43 +0100157 type "$1" &> /dev/null ;
158}
159
Erich Smitha3c3caa2012-04-28 00:43:38 -0400160plugins-help ()
161{
162 about list all plugins and functions defined by bash-it
Florian Baumanncecbae52010-11-08 21:31:11 +0100163 echo "bash-it Plugins Help-Message"
Erich Smitha3c3caa2012-04-28 00:43:38 -0400164 echo
Florian Baumanncecbae52010-11-08 21:31:11 +0100165
166 set | grep "()" \
167 | sed -e "/^_/d" | grep -v "BASH_ARGC=()" \
168 | sed -e "/^\s/d" | grep -v "BASH_LINENO=()" \
169 | grep -v "BASH_ARGV=()" \
170 | grep -v "BASH_SOURCE=()" \
171 | grep -v "DIRSTACK=()" \
172 | grep -v "GROUPS=()" \
173 | grep -v "BASH_CMDS=()" \
174 | grep -v "BASH_ALIASES=()" \
Florian Baumann6a890d22010-11-08 21:40:16 +0100175 | grep -v "COMPREPLY=()" | sed -e "s/()//"
Florian Baumanncecbae52010-11-08 21:31:11 +0100176}
177
Florian Baumannab445722010-12-14 14:33:16 +0100178# useful for administrators and configs
Erich Smitha3c3caa2012-04-28 00:43:38 -0400179buf ()
180{
181 about back up file with timestamp
182 param filename
183 local filename=$1
184 local filetime=$(date +%Y%m%d_%H%M%S)
Florian Baumannab445722010-12-14 14:33:16 +0100185 cp ${filename} ${filename}_${filetime}
186}