-
Notifications
You must be signed in to change notification settings - Fork 2
/
.functions
117 lines (101 loc) · 2.77 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
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
# vi:syntax=sh
docked () {
# Connect to monitor
xrandr --output HDMI1 --auto --same-as eDP1
# Set laptop backlight to 0
xbacklight -set 0
# Swap capslock and escape (called again incase a new keyboard is plugged in)
setxkbmap -option caps:swapescape
# Tell acpi we are now mirroring, so the laptop won't go to sleep when you
# shut it. Effectively "clamshell" mode.
echo 1 > /home/benp/mirroring
}
undock () {
# Disconnect the monitor
xrandr --output HDMI1 --off
# Set the laptop backlight to 70
xbacklight -set 70
# Tell acpi we are no longer mirroring so the laptop will sleep when you shut it.
echo 0 > /home/benp/mirroring
}
# grep shorthands
psgrep () { ps aux | grep -i $@ }
hgrep () { history | grep -i $@ }
# find shorthand
f () {
find . -name "$1"
}
# Create a new directory and enter it
md () {
mkdir -p "$@" && cd $_
}
# Create a git.io short URL
gitio () {
if [ -z "${1}" -o -z "${2}" ]; then
echo "Usage: \`gitio slug url\`"
return 1
fi
curl -i http://git.io/ -F "url=${2}" -F "code=${1}"
}
# Copy with progress
cp_p () {
rsync -WavP --human-readable --progress $1 $2
}
# get gzipped size
gz () {
echo "orig size (bytes): "
cat "$1" | wc -c
echo "gzipped size (bytes): "
gzip -c "$1" | wc -c
}
# All the dig info
digga () {
dig +nocmd "$1" any +multiline +noall +answer
}
# Escape UTF-8 characters into their 3-byte format
escape () {
printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u)
echo
}
# Decode \x{ABCD}-style Unicode escape sequences
unidecode () {
perl -e "binmode(STDOUT, ':utf8'); print \"$@\""
echo
}
# `v` with no arguments opens the current directory in Vim, otherwise opens the
# given location
v () {
if [ $# -eq 0 ]; then
if [ -f "$PWD/Session.vim" ]; then
nvim -S
else
nvim .
fi
else
nvim "$@"
fi
}
# Build the clock wiki into a tree of HTML documents using marked
buildWiki () {
cd ~/clock/wiki
git pull origin master
find ./ -name "*.md" -type f -exec sh -c 'mkdir -p ./build/$(dirname "$0") && marked "$0" > ./build/"${0%.md}.html"' {} \;
cd -
}
# password protect a file with zip, using a password generated with openssl
# arguments in the same order as the zip command, <output file name> <input file>
zipp () {
local password=$(openssl rand -base64 8)
zip -j -P $password $1 $2 > /dev/null
echo $password | clip
}
# Connect to the local MongoDB server using fzf to select which db to connect to
# Optionally takes an argument to start the selection with
mo () {
mongo $(mongo --quiet --eval 'db.getMongo().getDBNames().join("\n")' | grep -v '^test' | sort | fzf --query=$1)
}
# Checkout a git branch using fzf to select the branch
# Optionally takes an argument to start the selection with
fco () {
git checkout $(git branch | grep -v "^*" | fzf --query=$1)
}