-
Notifications
You must be signed in to change notification settings - Fork 0
/
zsh-handy-helpers.plugin.zsh
77 lines (77 loc) · 1.71 KB
/
zsh-handy-helpers.plugin.zsh
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
#!/usr/bin/env zsh
#
# Aliases
#
alias rf="rm -frd"
#
# Functions
#
clean() {
rf $1 && take $1 ;
}
create_ssh_key() {
KEY_TYPE=${1:-ed25519}
KEY_NAME=${2:-"id_${KEY_TYPE}"}
echo -n "Generating key pair......"
ssh-keygen -q -b 4096 -t "${KEY_TYPE}" -N "" -f ~/.ssh/"${KEY_NAME}"
echo "DONE"
if [[ -e ~/.ssh/"${KEY_NAME}".pub ]]; then
if type xclip >/dev/null 2>&1; then
cat ~/.ssh/"${KEY_NAME}".pub | xclip -sel clip
echo "✔ Public key has been saved to clipboard"
else
cat ~/.ssh/"${KEY_NAME}".pub
fi
else
echo "Something went wrong, please try again."
fi
}
did() {
echo -e "[${2:-"---"}] $(timestamp) / ${1}\n" >> "${HOME}"/did.txt ;
}
dip() {
if type docker >/dev/null 2>&1; then
docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1 ;
else
echo "Please install Docker first"
fi
}
dra() {
if type docker >/dev/null 2>&1; then
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) ;
else
echo "Please install Docker first"
fi
}
fix_ssh_key_permissions() {
chmod 600 "${HOME}"/.ssh/*
}
fix_enospc_issue() {
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p >/dev/null 2>&1
}
iter() {
if [[ -f "$2" ]]; then
while read line; do
$1 "$line"
done < "$2"
else
while read ITEM; do
$1 "$ITEM"
done
fi
}
prevent_user() {
if [[ "$1" == $(whoami) ]]; then
echo "✘ ${2} should NOT be run as ${1}"
exit 0
fi
}
prevent_root() {
prevent_user root "$1"
}
qr() {
echo "$1" | curl -F-=\<- qrenco.de ;
}
timestamp() {
date +%Y%m%d-%T ;
}