-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.sh
64 lines (56 loc) · 1.57 KB
/
functions.sh
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
# Remove vim swp files
vimclean () {
rm -rf ~/.vim/tmp
mkdir -p ~/.vim/tmp
rm -rf ~/.cache/ctrlp
find . -name "*.sw*" -exec rm {} \;
}
# Print the directory of a Python module.
pymod () {
# FIXME: could replace in the middle of a path
python -c "import $1; print $1.__file__.replace('.pyc', '.py')"
}
alias_if_exists () {
which $1 &> /dev/null
if [ $? -eq 0 ]
then
alias $2="$1"
fi
}
camera_reset() {
sudo killall VDCAssistant
sudo killall AppleCameraAssistant
}
youtube_to_mp3() {
yt-dlp --extract-audio --audio-format mp3 $1:x
}
etchost_block () {
if [[ $# -eq 0 ]]; then
# no args == show list of already-blocked hosts
grep --color=never --ignore-case --extended-regexp "^##\s+block" /etc/hosts | cut -d" " -f 3-
else
# loop through hosts and block each one on ipv4 + ipv6
while (($#)); do
if ! grep -q "## block $1" /etc/hosts; then
echo "echo \"\n## block $1\" >> /etc/hosts" | sudo sh
echo "echo \"127.0.0.1 $1 www.$1\" >> /etc/hosts" | sudo sh
echo "echo \"::1 $1 www.$1\" >> /etc/hosts" | sudo sh
echo "echo \"## /block $1\" >> /etc/hosts" | sudo sh
fi
shift
done
fi
}
etchost_unblock () {
while (($#)); do
# remove specified hosts and squash multiple empty lines
newContents=$(sed "/## block $1/,/## \/block/d" /etc/hosts | sed '/./,/^$/!d')
echo "echo \"$newContents\" > /etc/hosts" | sudo sh
shift
done
}
etchost_block_blackholes() {
while read b; do
etchost_block $b
done < ~/.blackholes
}