blob: 137b8120eded5e64d27e85ca8a03679075098b97 [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
Erich Smith5d32cf92012-05-07 12:51:10 -040015 example '$ down4me http://www.google.com'
Erich Smitha3c3caa2012-04-28 00:43:38 -040016 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
Erich Smith5d32cf92012-05-07 12:51:10 -040031 example '$ pickfrom /usr/share/dict/words'
Erich Smithe3011c52012-04-28 10:35:01 -040032 local file=$1
33 [ -z "$file" ] && reference $FUNCNAME && return
34 length=$(cat $file | wc -l)
35 n=$(expr $RANDOM \* $length \/ 32768 + 1)
Erich Smith2086a052012-04-28 10:40:16 -040036 head -n $n $file | tail -1
Erich Smithe3011c52012-04-28 10:35:01 -040037}
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
Erich Smith5d32cf92012-05-07 12:51:10 -040044 example '$ pass'
45 example '$ pass 6'
Erich Smithe3011c52012-04-28 10:35:01 -040046 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
Erich Smith5d32cf92012-05-07 12:51:10 -040056 example '$ pmdown README.md'
Erich Smitha3c3caa2012-04-28 00:43:38 -040057 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
Erich Smith5d32cf92012-05-07 12:51:10 -040069 example '$ mkcd foo'
70 example '$ mkcd /tmp/img/photos/large'
Erich Smitha3c3caa2012-04-28 00:43:38 -040071 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
Erich Smith5d32cf92012-05-07 12:51:10 -040086 example '$ pman bash'
Erich Smitha3c3caa2012-04-28 00:43:38 -040087 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
Erich Smith5d32cf92012-05-07 12:51:10 -040095 example '$ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf'
Erich Smitha3c3caa2012-04-28 00:43:38 -040096 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
Erich Smith5d32cf92012-05-07 12:51:10 -0400103 example '$ pri Array'
Erich Smitha3c3caa2012-04-28 00:43:38 -0400104 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 Smithdd9fb102012-05-17 21:40:08 -0400140if [ ! -e $BASH_IT/plugins/enabled/todo.plugin.bash ]; then
141# if user has installed todo plugin, skip this...
142 t ()
143 {
144 about 'one thing todo'
145 param 'if not set, display todo item'
146 param '1: todo text'
147 if [[ "$*" == "" ]] ; then
148 cat ~/.t
149 else
150 echo "$*" > ~/.t
151 fi
152 }
153fi
154
Erich Smitha3c3caa2012-04-28 00:43:38 -0400155command_exists ()
156{
157 about checks for existence of a command
158 param 1: command to check
Erich Smith5d32cf92012-05-07 12:51:10 -0400159 example '$ command_exists ls && echo exists'
Jesus de Mula Cano229aa832011-03-07 00:02:43 +0100160 type "$1" &> /dev/null ;
161}
162
Erich Smitha3c3caa2012-04-28 00:43:38 -0400163plugins-help ()
164{
165 about list all plugins and functions defined by bash-it
Florian Baumanncecbae52010-11-08 21:31:11 +0100166 echo "bash-it Plugins Help-Message"
Erich Smitha3c3caa2012-04-28 00:43:38 -0400167 echo
Florian Baumanncecbae52010-11-08 21:31:11 +0100168
169 set | grep "()" \
170 | sed -e "/^_/d" | grep -v "BASH_ARGC=()" \
171 | sed -e "/^\s/d" | grep -v "BASH_LINENO=()" \
172 | grep -v "BASH_ARGV=()" \
173 | grep -v "BASH_SOURCE=()" \
174 | grep -v "DIRSTACK=()" \
175 | grep -v "GROUPS=()" \
176 | grep -v "BASH_CMDS=()" \
177 | grep -v "BASH_ALIASES=()" \
Florian Baumann6a890d22010-11-08 21:40:16 +0100178 | grep -v "COMPREPLY=()" | sed -e "s/()//"
Florian Baumanncecbae52010-11-08 21:31:11 +0100179}
180
Florian Baumannab445722010-12-14 14:33:16 +0100181# useful for administrators and configs
Erich Smitha3c3caa2012-04-28 00:43:38 -0400182buf ()
183{
184 about back up file with timestamp
185 param filename
186 local filename=$1
187 local filetime=$(date +%Y%m%d_%H%M%S)
Florian Baumannab445722010-12-14 14:33:16 +0100188 cp ${filename} ${filename}_${filetime}
189}