Eitan Adler | 3fc60b5 | 2012-04-17 00:24:58 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Robert R Evans | a4d0242 | 2010-10-02 15:07:29 -0700 | [diff] [blame] | 2 | |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 3 | # For generic functions. |
| 4 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 5 | ips () |
| 6 | { |
| 7 | about display all ip addresses for this host |
| 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 | { |
| 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 Szymanski | 63c60e5 | 2011-03-11 20:32:46 -0600 | [diff] [blame] | 17 | } |
| 18 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 19 | myip () |
| 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 Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 24 | } |
Robert R Evans | c9da086 | 2010-10-06 17:27:55 -0700 | [diff] [blame] | 25 | |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 26 | |
| 27 | pickfrom () |
| 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) |
Erich Smith | 2086a05 | 2012-04-28 10:40:16 -0400 | [diff] [blame^] | 36 | head -n $n $file | tail -1 |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 39 | pass () |
| 40 | { |
Erich Smith | e3011c5 | 2012-04-28 10:35:01 -0400 | [diff] [blame] | 41 | 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 Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 48 | echo "With spaces (easier to memorize): $pass" |
| 49 | echo "Without (use this as the pass): $(echo $pass | tr -d ' ')" |
Mark Szymanski | 5764340 | 2011-08-10 18:49:20 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 52 | pmdown () |
| 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 Szymanski | 4898fa9 | 2011-05-27 11:47:55 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 65 | mkcd () |
| 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 Szymanski | 123c3be | 2010-10-18 18:24:15 -0500 | [diff] [blame] | 73 | } |
Robert R Evans | c9da086 | 2010-10-06 17:27:55 -0700 | [diff] [blame] | 74 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 75 | lsgrep () |
| 76 | { |
| 77 | about search through directory contents with grep |
| 78 | ls | grep "$*" |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 82 | pman () |
| 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 Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 90 | |
| 91 | pcurl () |
| 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 Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 99 | pri () |
| 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 | |
| 107 | quiet () |
| 108 | { |
Mark Szymanski | 6229597 | 2010-11-20 16:27:47 -0600 | [diff] [blame] | 109 | $* &> /dev/null & |
| 110 | } |
| 111 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 112 | banish-cookies () |
| 113 | { |
| 114 | about redirect .adobe and .macromedia files to /dev/null |
Mark Szymanski | 5a7174a | 2010-11-04 13:09:40 -0500 | [diff] [blame] | 115 | rm -r ~/.macromedia ~/.adobe |
| 116 | ln -s /dev/null ~/.adobe |
| 117 | ln -s /dev/null ~/.macromedia |
| 118 | } |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 119 | |
Robert R Evans | 2010f01 | 2010-10-10 09:24:19 -0700 | [diff] [blame] | 120 | usage () |
| 121 | { |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 122 | about disk usage per directory, in Mac OS X and Linux |
| 123 | param 1: directory name |
Florian Baumann | e45e72e | 2010-11-02 14:50:45 +0100 | [diff] [blame] | 124 | 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 Szymanski | 123c3be | 2010-10-18 18:24:15 -0500 | [diff] [blame] | 138 | } |
Mark Szymanski | 4b26a78 | 2010-11-05 15:02:12 -0500 | [diff] [blame] | 139 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 140 | t () |
| 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 Baumann | cecbae5 | 2010-11-08 21:31:11 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 152 | command_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 Cano | 229aa83 | 2011-03-07 00:02:43 +0100 | [diff] [blame] | 157 | type "$1" &> /dev/null ; |
| 158 | } |
| 159 | |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 160 | plugins-help () |
| 161 | { |
| 162 | about list all plugins and functions defined by bash-it |
Florian Baumann | cecbae5 | 2010-11-08 21:31:11 +0100 | [diff] [blame] | 163 | echo "bash-it Plugins Help-Message" |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 164 | echo |
Florian Baumann | cecbae5 | 2010-11-08 21:31:11 +0100 | [diff] [blame] | 165 | |
| 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 Baumann | 6a890d2 | 2010-11-08 21:40:16 +0100 | [diff] [blame] | 175 | | grep -v "COMPREPLY=()" | sed -e "s/()//" |
Florian Baumann | cecbae5 | 2010-11-08 21:31:11 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Florian Baumann | ab44572 | 2010-12-14 14:33:16 +0100 | [diff] [blame] | 178 | # useful for administrators and configs |
Erich Smith | a3c3caa | 2012-04-28 00:43:38 -0400 | [diff] [blame] | 179 | buf () |
| 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 Baumann | ab44572 | 2010-12-14 14:33:16 +0100 | [diff] [blame] | 185 | cp ${filename} ${filename}_${filetime} |
| 186 | } |