Erich Smith | 248eb30 | 2012-05-08 23:40:24 -0400 | [diff] [blame] | 1 | cite about-plugin |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 2 | about-plugin 'miscellaneous tools' |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 3 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 4 | ips () |
| 5 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 6 | about 'display all ip addresses for this host' |
| 7 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 8 | ifconfig | grep "inet " | awk '{ print $2 }' |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 9 | } |
| 10 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 11 | down4me () |
| 12 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 13 | about 'checks whether a website is down for you, or everybody' |
| 14 | param '1: website url' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 15 | example '$ down4me http://www.google.com' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 16 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 17 | curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' |
Mark Szymanski | 63c60e5 | 2011-03-11 20:32:46 -0600 | [diff] [blame] | 18 | } |
| 19 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 20 | myip () |
| 21 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 22 | about 'displays your ip address, as seen by the Internet' |
| 23 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 24 | 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 Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 26 | } |
Robert R Evans | c9da086 | 2010-10-06 17:27:55 -0700 | [diff] [blame] | 27 | |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 28 | |
| 29 | pickfrom () |
| 30 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 31 | about 'picks random line from file' |
| 32 | param '1: filename' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 33 | example '$ pickfrom /usr/share/dict/words' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 34 | group 'base' |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 35 | local file=$1 |
| 36 | [ -z "$file" ] && reference $FUNCNAME && return |
| 37 | length=$(cat $file | wc -l) |
| 38 | n=$(expr $RANDOM \* $length \/ 32768 + 1) |
Erich Smith | 2086a05 | 2012-04-28 10:40:16 -0400 | [diff] [blame] | 39 | head -n $n $file | tail -1 |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 42 | pass () |
| 43 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 44 | about 'generates random password from dictionary words' |
| 45 | param 'optional integer length' |
| 46 | param 'if unset, defaults to 4' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 47 | example '$ pass' |
| 48 | example '$ pass 6' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 49 | group 'base' |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 50 | local i pass length=${1:-4} |
| 51 | pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done)) |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 52 | echo "With spaces (easier to memorize): $pass" |
| 53 | echo "Without (use this as the pass): $(echo $pass | tr -d ' ')" |
Mark Szymanski | 5764340 | 2011-08-10 18:49:20 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 56 | pmdown () |
| 57 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 58 | about 'preview markdown file in a browser' |
| 59 | param '1: markdown file' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 60 | example '$ pmdown README.md' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 61 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 62 | 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 Szymanski | 4898fa9 | 2011-05-27 11:47:55 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 70 | mkcd () |
| 71 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 72 | about 'make a directory and cd into it' |
| 73 | param 'path to create' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 74 | example '$ mkcd foo' |
| 75 | example '$ mkcd /tmp/img/photos/large' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 76 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 77 | mkdir -p "$*" |
| 78 | cd "$*" |
Mark Szymanski | 123c3be | 2010-10-18 18:24:15 -0500 | [diff] [blame] | 79 | } |
Robert R Evans | c9da086 | 2010-10-06 17:27:55 -0700 | [diff] [blame] | 80 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 81 | lsgrep () |
| 82 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 83 | about 'search through directory contents with grep' |
| 84 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 85 | ls | grep "$*" |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 89 | pman () |
| 90 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 91 | about 'view man documentation in Preview' |
| 92 | param '1: man page to view' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 93 | example '$ pman bash' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 94 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 95 | man -t "${1}" | open -f -a $PREVIEW |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 98 | |
| 99 | pcurl () |
| 100 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 101 | about 'download file and Preview it' |
| 102 | param '1: download URL' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 103 | example '$ pcurl http://www.irs.gov/pub/irs-pdf/fw4.pdf' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 104 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 105 | curl "${1}" | open -f -a $PREVIEW |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 108 | pri () |
| 109 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 110 | about 'display information about Ruby classes, modules, or methods, in Preview' |
| 111 | param '1: Ruby method, module, or class' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 112 | example '$ pri Array' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 113 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 114 | ri -T "${1}" | open -f -a $PREVIEW |
| 115 | } |
| 116 | |
| 117 | quiet () |
| 118 | { |
Erich Smith | 248eb30 | 2012-05-08 23:40:24 -0400 | [diff] [blame] | 119 | about 'what *does* this do?' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 120 | group 'base' |
Mark Szymanski | 6229597 | 2010-11-20 16:27:47 -0600 | [diff] [blame] | 121 | $* &> /dev/null & |
| 122 | } |
| 123 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 124 | banish-cookies () |
| 125 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 126 | about 'redirect .adobe and .macromedia files to /dev/null' |
| 127 | group 'base' |
Mark Szymanski | 5a7174a | 2010-11-04 13:09:40 -0500 | [diff] [blame] | 128 | rm -r ~/.macromedia ~/.adobe |
| 129 | ln -s /dev/null ~/.adobe |
| 130 | ln -s /dev/null ~/.macromedia |
| 131 | } |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 132 | |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 133 | usage () |
| 134 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 135 | about 'disk usage per directory, in Mac OS X and Linux' |
| 136 | param '1: directory name' |
| 137 | group 'base' |
Florian Baumann | e45e72e | 2010-11-02 14:50:45 +0100 | [diff] [blame] | 138 | 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 Szymanski | 123c3be | 2010-10-18 18:24:15 -0500 | [diff] [blame] | 152 | } |
Mark Szymanski | 4b26a78 | 2010-11-05 15:02:12 -0500 | [diff] [blame] | 153 | |
Erich Smith | dd9fb10 | 2012-05-17 21:40:08 -0400 | [diff] [blame] | 154 | if [ ! -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 | } |
| 167 | fi |
Florian Baumann | cecbae5 | 2010-11-08 21:31:11 +0100 | [diff] [blame] | 168 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 169 | command_exists () |
| 170 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 171 | about 'checks for existence of a command' |
| 172 | param '1: command to check' |
Erich Smith | 5d32cf9 | 2012-05-07 12:51:10 -0400 | [diff] [blame] | 173 | example '$ command_exists ls && echo exists' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 174 | group 'base' |
Jesus de Mula Cano | 229aa83 | 2011-03-07 00:02:43 +0100 | [diff] [blame] | 175 | type "$1" &> /dev/null ; |
| 176 | } |
| 177 | |
jimmynotjim | d5bfb7f | 2013-11-29 14:19:26 -0500 | [diff] [blame] | 178 | mkiso () |
| 179 | { |
| 180 | |
| 181 | about 'creates iso from current dir in the parent dir (unless defined)' |
jimmynotjim | 55a37ad | 2013-12-19 10:21:55 -0500 | [diff] [blame^] | 182 | 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' |
jimmynotjim | d5bfb7f | 2013-11-29 14:19:26 -0500 | [diff] [blame] | 187 | 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 Baumann | ab44572 | 2010-12-14 14:33:16 +0100 | [diff] [blame] | 205 | # useful for administrators and configs |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 206 | buf () |
| 207 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 208 | about 'back up file with timestamp' |
| 209 | param 'filename' |
| 210 | group 'base' |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 211 | local filename=$1 |
| 212 | local filetime=$(date +%Y%m%d_%H%M%S) |
Florian Baumann | ab44572 | 2010-12-14 14:33:16 +0100 | [diff] [blame] | 213 | cp ${filename} ${filename}_${filetime} |
| 214 | } |