blob: e028fe6977f9344eb2a4db69e2d4c08b32e750d3 [file] [log] [blame]
Erich Smith248eb302012-05-08 23:40:24 -04001cite about-plugin
Erich Smith08e439c2012-05-13 08:37:31 -04002about-plugin 'miscellaneous tools'
Robert R Evans2010f012010-10-10 09:24:19 -07003
Erich Smitha3c3caa2012-04-28 00:43:38 -04004ips ()
5{
Erich Smith08e439c2012-05-13 08:37:31 -04006 about 'display all ip addresses for this host'
7 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -04008 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{
Erich Smith08e439c2012-05-13 08:37:31 -040013 about 'checks whether a website is down for you, or everybody'
14 param '1: website url'
Erich Smith5d32cf92012-05-07 12:51:10 -040015 example '$ down4me http://www.google.com'
Erich Smith08e439c2012-05-13 08:37:31 -040016 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -040017 curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
Mark Szymanski63c60e52011-03-11 20:32:46 -060018}
19
Erich Smitha3c3caa2012-04-28 00:43:38 -040020myip ()
21{
Erich Smith08e439c2012-05-13 08:37:31 -040022 about 'displays your ip address, as seen by the Internet'
23 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -040024 res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
25 echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
Robert R Evans2010f012010-10-10 09:24:19 -070026}
Robert R Evansc9da0862010-10-06 17:27:55 -070027
Erich Smithe3011c52012-04-28 10:35:01 -040028
29pickfrom ()
30{
Erich Smith08e439c2012-05-13 08:37:31 -040031 about 'picks random line from file'
32 param '1: filename'
Erich Smith5d32cf92012-05-07 12:51:10 -040033 example '$ pickfrom /usr/share/dict/words'
Erich Smith08e439c2012-05-13 08:37:31 -040034 group 'base'
Erich Smithe3011c52012-04-28 10:35:01 -040035 local file=$1
36 [ -z "$file" ] && reference $FUNCNAME && return
37 length=$(cat $file | wc -l)
38 n=$(expr $RANDOM \* $length \/ 32768 + 1)
Erich Smith2086a052012-04-28 10:40:16 -040039 head -n $n $file | tail -1
Erich Smithe3011c52012-04-28 10:35:01 -040040}
41
Erich Smitha3c3caa2012-04-28 00:43:38 -040042pass ()
43{
Erich Smith08e439c2012-05-13 08:37:31 -040044 about 'generates random password from dictionary words'
45 param 'optional integer length'
46 param 'if unset, defaults to 4'
Erich Smith5d32cf92012-05-07 12:51:10 -040047 example '$ pass'
48 example '$ pass 6'
Erich Smith08e439c2012-05-13 08:37:31 -040049 group 'base'
Erich Smithe3011c52012-04-28 10:35:01 -040050 local i pass length=${1:-4}
51 pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
Erich Smitha3c3caa2012-04-28 00:43:38 -040052 echo "With spaces (easier to memorize): $pass"
53 echo "Without (use this as the pass): $(echo $pass | tr -d ' ')"
Mark Szymanski57643402011-08-10 18:49:20 -050054}
55
Erich Smitha3c3caa2012-04-28 00:43:38 -040056pmdown ()
57{
Erich Smith08e439c2012-05-13 08:37:31 -040058 about 'preview markdown file in a browser'
59 param '1: markdown file'
Erich Smith5d32cf92012-05-07 12:51:10 -040060 example '$ pmdown README.md'
Erich Smith08e439c2012-05-13 08:37:31 -040061 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -040062 if command -v markdown &>/dev/null
63 then
64 markdown $1 | browser
65 else
66 echo "You don't have a markdown command installed!"
67 fi
Mark Szymanski4898fa92011-05-27 11:47:55 -050068}
69
Erich Smitha3c3caa2012-04-28 00:43:38 -040070mkcd ()
71{
Erich Smith08e439c2012-05-13 08:37:31 -040072 about 'make a directory and cd into it'
73 param 'path to create'
Erich Smith5d32cf92012-05-07 12:51:10 -040074 example '$ mkcd foo'
75 example '$ mkcd /tmp/img/photos/large'
Erich Smith08e439c2012-05-13 08:37:31 -040076 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -040077 mkdir -p "$*"
78 cd "$*"
Mark Szymanski123c3be2010-10-18 18:24:15 -050079}
Robert R Evansc9da0862010-10-06 17:27:55 -070080
Erich Smitha3c3caa2012-04-28 00:43:38 -040081lsgrep ()
82{
Erich Smith08e439c2012-05-13 08:37:31 -040083 about 'search through directory contents with grep'
84 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -040085 ls | grep "$*"
Robert R Evans2010f012010-10-10 09:24:19 -070086}
87
88
Erich Smitha3c3caa2012-04-28 00:43:38 -040089pman ()
90{
Erich Smith08e439c2012-05-13 08:37:31 -040091 about 'view man documentation in Preview'
92 param '1: man page to view'
Erich Smith5d32cf92012-05-07 12:51:10 -040093 example '$ pman bash'
Erich Smith08e439c2012-05-13 08:37:31 -040094 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -040095 man -t "${1}" | open -f -a $PREVIEW
Robert R Evans2010f012010-10-10 09:24:19 -070096}
97
Erich Smitha3c3caa2012-04-28 00:43:38 -040098
99pcurl ()
100{
Erich Smith08e439c2012-05-13 08:37:31 -0400101 about 'download file and Preview it'
102 param '1: download URL'
Erich Smith5d32cf92012-05-07 12:51:10 -0400103 example '$ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf'
Erich Smith08e439c2012-05-13 08:37:31 -0400104 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -0400105 curl "${1}" | open -f -a $PREVIEW
Robert R Evans2010f012010-10-10 09:24:19 -0700106}
107
Erich Smitha3c3caa2012-04-28 00:43:38 -0400108pri ()
109{
Erich Smith08e439c2012-05-13 08:37:31 -0400110 about 'display information about Ruby classes, modules, or methods, in Preview'
111 param '1: Ruby method, module, or class'
Erich Smith5d32cf92012-05-07 12:51:10 -0400112 example '$ pri Array'
Erich Smith08e439c2012-05-13 08:37:31 -0400113 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -0400114 ri -T "${1}" | open -f -a $PREVIEW
115}
116
117quiet ()
118{
Erich Smith248eb302012-05-08 23:40:24 -0400119 about 'what *does* this do?'
Erich Smith08e439c2012-05-13 08:37:31 -0400120 group 'base'
Mark Szymanski62295972010-11-20 16:27:47 -0600121 $* &> /dev/null &
122}
123
Erich Smitha3c3caa2012-04-28 00:43:38 -0400124banish-cookies ()
125{
Erich Smith08e439c2012-05-13 08:37:31 -0400126 about 'redirect .adobe and .macromedia files to /dev/null'
127 group 'base'
Mark Szymanski5a7174a2010-11-04 13:09:40 -0500128 rm -r ~/.macromedia ~/.adobe
129 ln -s /dev/null ~/.adobe
130 ln -s /dev/null ~/.macromedia
131}
Robert R Evans2010f012010-10-10 09:24:19 -0700132
Robert R Evans2010f012010-10-10 09:24:19 -0700133usage ()
134{
Erich Smith08e439c2012-05-13 08:37:31 -0400135 about 'disk usage per directory, in Mac OS X and Linux'
136 param '1: directory name'
137 group 'base'
Florian Baumanne45e72e2010-11-02 14:50:45 +0100138 if [ $(uname) = "Darwin" ]; then
139 if [ -n $1 ]; then
140 du -hd $1
141 else
142 du -hd 1
143 fi
144
145 elif [ $(uname) = "Linux" ]; then
146 if [ -n $1 ]; then
147 du -h --max-depth=1 $1
148 else
149 du -h --max-depth=1
150 fi
151 fi
Mark Szymanski123c3be2010-10-18 18:24:15 -0500152}
Mark Szymanski4b26a782010-11-05 15:02:12 -0500153
Erich Smithdd9fb102012-05-17 21:40:08 -0400154if [ ! -e $BASH_IT/plugins/enabled/todo.plugin.bash ]; then
155# if user has installed todo plugin, skip this...
156 t ()
157 {
158 about 'one thing todo'
159 param 'if not set, display todo item'
160 param '1: todo text'
161 if [[ "$*" == "" ]] ; then
162 cat ~/.t
163 else
164 echo "$*" > ~/.t
165 fi
166 }
167fi
Florian Baumanncecbae52010-11-08 21:31:11 +0100168
Erich Smitha3c3caa2012-04-28 00:43:38 -0400169command_exists ()
170{
Erich Smith08e439c2012-05-13 08:37:31 -0400171 about 'checks for existence of a command'
172 param '1: command to check'
Erich Smith5d32cf92012-05-07 12:51:10 -0400173 example '$ command_exists ls && echo exists'
Erich Smith08e439c2012-05-13 08:37:31 -0400174 group 'base'
Jesus de Mula Cano229aa832011-03-07 00:02:43 +0100175 type "$1" &> /dev/null ;
176}
177
jimmynotjimd5bfb7f2013-11-29 14:19:26 -0500178mkiso ()
179{
180
181 about 'creates iso from current dir in the parent dir (unless defined)'
jimmynotjim55a37ad2013-12-19 10:21:55 -0500182 param '1: ISO name'
183 param '2: dest/path'
184 param '3: src/path'
185 example 'mkiso'
186 example 'mkiso ISO-Name dest/path src/path'
jimmynotjimd5bfb7f2013-11-29 14:19:26 -0500187 group 'base'
188
189 if type "mkisofs" > /dev/null; then
190 [ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1
191 [ -z ${2+x} ] && local destpath=../ || local destpath=$2
192 [ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3
193
194 if [ ! -f "${destpath}${isoname}.iso" ]; then
195 echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
196 mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}"
197 else
198 echo "${destpath}${isoname}.iso already exists"
199 fi
200 else
201 echo "mkisofs cmd does not exist, please install cdrtools"
202 fi
203}
204
Florian Baumannab445722010-12-14 14:33:16 +0100205# useful for administrators and configs
Erich Smitha3c3caa2012-04-28 00:43:38 -0400206buf ()
207{
Erich Smith08e439c2012-05-13 08:37:31 -0400208 about 'back up file with timestamp'
209 param 'filename'
210 group 'base'
Erich Smitha3c3caa2012-04-28 00:43:38 -0400211 local filename=$1
212 local filetime=$(date +%Y%m%d_%H%M%S)
Florian Baumannab445722010-12-14 14:33:16 +0100213 cp ${filename} ${filename}_${filetime}
214}