-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
executable file
·92 lines (75 loc) · 2.47 KB
/
.functions
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
# History
# hgrep() {
# history | sed 's/^ *[0-9]* *//' | grep $1 | sort | uniq -c | sort
#}
hgrep() {
history | grep $1 | sort -k 2 | uniq -c -f 1 | sort
}
# Appends your key to a server's authorized keys file
function authme {
ssh $1 'cat >>.ssh/authorized_keys' <~/.ssh/id_rsa.pub
}
# Create a new directory and enter it
function md() {
mkdir -p "$@" && cd "$@"
}
# Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.
# Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!)
function httpcompression() {
encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding"
}
function json() {
python3 -mjson.tool "$*" | pygmentize -l javascript
}
# Solarized switchers
# tabc changes Terminal settings on the current tab
function tabc {
NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi
osascript -e "tell application \"Terminal\" to set current settings of front window to settings set \"$NAME\""
}
function godark {
tabc "Solarized Dark"
}
function golight {
tabc "Solarized Light"
}
# OS X Terminal, change the tab name
function tabname {
printf "\e]1;$1\a"
}
# OS X Terminal, change the window name
function winname {
printf "\e]2;$1\a"
}
# OS X Terminal, change the tab and window name
function ntw {
tabname $1 && winname $1
}
# Version switchers (Courtesy Matt Lehman https://github.com/mlehman)
# Usage:
# version [software-name, without version], i.e. 'version scala' returns current version
# versions [software-name, without version], i.e. 'versions scala' returns list of installed versions
# swap [software-name, without version] [new-name-with-version], i.e. 'swap scala scala-2.10.1'
function versions() {
ls -d $TOOL_DIR/$1/*/ | xargs basename | sort | grep -v current
}
function version() {
readlink $TOOL_DIR/$1/current | xargs basename
}
function swap() {
rm -f $TOOL_DIR/$1/current
ln -s $TOOL_DIR/$1/$2 $TOOL_DIR/$1/current
}
# Function that takes an array of keys. Called via:
# array=("one" "two" "three")
# addsshkeys "${array[@]}"
function addsshkeys() {
sshkeys=("$@")
currentsshkeys=($(ssh-add -l | awk '{print $3}' | sed 's!.*/!!'))
for i in "${currentsshkeys[@]}"; do
sshkeys=(${sshkeys[@]//*$i*})
done
for i in "${sshkeys[@]}"; do
ssh-add ~/.ssh/$i
done
}