forked from atomantic/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.shellfn
123 lines (108 loc) · 4.28 KB
/
.shellfn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#########################################
# Utility Functions
function bot() {
ESC_SEQ="\x1b["
echo
echo -e "$ESC_SEQ"32;01m\[._.]/$ESC_SEQ"39;49;00m - "$1
}
# Create a new git repo with one README commit and CD into it
function gitnr() { mkdir $1; cd $1; git init; touch README; git add README; git commit -mFirst-commit;}
# Do a Matrix movie effect of falling characters
function matrix1() {
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|gawk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'
}
function matrix2() {
echo -e "\e[1;40m" ; clear ; characters=$( jot -c 94 33 | tr -d '\n' ) ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) $characters ;sleep 0.05; done|gawk '{ letters=$5; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'
}
# Use Mac OS Preview to open a man page in a more handsome format
function manp() {
man -t $1 | open -f -a /Applications/Preview.app
}
# Show normally hidden system and dotfile types of files
# in Mac OS Finder
function showhiddenfiles() {
defaults write com.apple.Finder AppleShowAllFiles YES
osascript -e 'tell application "Finder" to quit'
sleep 0.25
osascript -e 'tell application "Finder" to activate'
}
# Hide (back to defaults) normally hidden system and dotfile types of files
# in Mac OS Finder
function hidehiddenfiles() {
defaults write com.apple.Finder AppleShowAllFiles NO
osascript -e 'tell application "Finder" to quit'
sleep 0.25
osascript -e 'tell application "Finder" to activate'
}
## hammer a service with curl for a given number of times
## usage: curlhammer $url
function curlhammer () {
bot "about to hammer $1 with $2 curls ⇒";
echo "curl -k -s -D - $1 -o /dev/null | grep 'HTTP/1.1' | sed 's/HTTP\/1.1 //'"
for i in {1..$2}
do
curl -k -s -D - $1 -o /dev/null | grep 'HTTP/1.1' | sed 's/HTTP\/1.1 //'
done
bot "done"
}
## curlheader will return only a specific response header or all response headers for a given URL
## usage: curlheader $header $url
## usage: curlheader $url
function curlheader() {
if [[ -z "$2" ]]; then
echo "curl -k -s -D - $1 -o /dev/null"
curl -k -s -D - $1 -o /dev/null:
else
echo "curl -k -s -D - $2 -o /dev/null | grep $1:"
curl -k -s -D - $2 -o /dev/null | grep $1:
fi
}
## get the timings for a curl to a URL
## usage: curltime $url
function curltime(){
curl -w " time_namelookup: %{time_namelookup}\n\
time_connect: %{time_connect}\n\
time_appconnect: %{time_appconnect}\n\
time_pretransfer: %{time_pretransfer}\n\
time_redirect: %{time_redirect}\n\
time_starttransfer: %{time_starttransfer}\n\
--------------------------\n\
time_total: %{time_total}\n" -o /dev/null -s "$1"
}
function fixperms(){
find . \( -name "*.sh" -or -type d \) -exec chmod 755 {} \; && find . -type f ! -name "*.sh" -exec chmod 644 {} \;
}
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# Generate Subresource Integrity hashes.
# 1st argument is the filename.
# 2nd argument, optional, is the hash algorithm
# (currently the allowed prefixes are sha256, sha384, and sha512)
# See http://www.w3.org/TR/SRI/ and
# https://developer.mozilla.org/docs/Web/Security/Subresource_Integrity
function sri() {
if [ -z "${1}" ]; then
echo "ERROR: No file specified.";
return 1;
fi;
local algorithm="${2:-sha512}"
if ! echo "${algorithm}" | egrep -q "^sha(256|384|512)$"; then
echo "ERROR: hash algorithm must be sha256, sha384 or sha512.";
return 1;
fi;
local filehash=$(openssl dgst "-${algorithm}" -binary "$1" | openssl base64 -A)
if [ -z "${filehash}" ]; then
return 1;
fi;
echo "${algorithm}-${filehash}";
}
## output directory/file tree, excluding ignorables
function tre(){
tree -aC -I '.git|node_modules|bower_components|.DS_Store' --dirsfirst "$@"
}
## weather seattle
function weather() {
curl wttr.in/$1
}