-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshaliases
185 lines (170 loc) · 6.12 KB
/
.zshaliases
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#OpenSSL
alias openssl_s_client_date='f() { openssl s_client -connect $1:443 </dev/null | openssl x509 -noout -dates };f'
# Docker
## Ansible
if [ $(command -v docker) ]; then
alias ansible-sh='docker run -it --rm \
-v $(readlink -f $SSH_AUTH_SOCK):/ssh-agent \
-v ${PWD}:/ansible \
-e SSH_AUTH_SOCK=/ssh-agent \
cloudtempleinfra/ansible-alpine:latest sh'
alias ansible-sh-2.10.7-2='docker run -it --rm \
-v $(readlink -f $SSH_AUTH_SOCK):/ssh-agent \
-v ${PWD}:/ansible \
-v /etc/ca-certificates/trust-source/anchors:/usr/local/share/ca-certificates:ro \
-e SSH_AUTH_SOCK=/ssh-agent \
pad92/ansible-alpine:2.10.7-2 sh'
alias ansible-playbook='docker run -it --rm \
-v $(readlink -f $SSH_AUTH_SOCK):/ssh-agent \
-v ${PWD}:/ansible \
-e SSH_AUTH_SOCK=/ssh-agent \
pad92/ansible-alpine:latest ansible-playbook'
fi
# Arch
## remove orphans
if [ $(command -v pacman) ] && [ $(command -v yay) ]; then
function clean_arch {
ORPHAN=$(pacman -Qtdq)
if [ -n "${ORPHAN}" ]; then
echo "Remove orphans"
sudo pacman -Rns $(pacman -Qtdq)
fi
yay -Scc --noconfirm
sudo find /etc -regextype posix-extended -regex ".*\.pac(new|save|orig)$" 2> /dev/null
paccache -ruk0
paccache -rk1
}
fi
## get fastest mirrors
if [ $(command -v reflector) ]; then
alias mirror="sudo reflector -c FR -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist"
alias mirrord="sudo reflector -c FR --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist"
alias mirrors="sudo reflector -c FR --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist"
alias mirrora="sudo reflector -c FR --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist"
fi
## Update
function arch_update {
yay -Syu --devel
clean_arch
if [ $(command -v flatpak) ]; then
flatpak update -y
flatpak uninstall --unused -y
fi
}
# Tools
## youtube-dl
if [ $(command -v youtube-dl) ]; then
alias yta-aac="youtube-dl --extract-audio --audio-format aac "
alias yta-best="youtube-dl --extract-audio --audio-format best "
alias yta-flac="youtube-dl --extract-audio --audio-format flac "
alias yta-m4a="youtube-dl --extract-audio --audio-format m4a "
alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 "
alias yta-opus="youtube-dl --extract-audio --audio-format opus "
alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis "
alias yta-wav="youtube-dl --extract-audio --audio-format wav "
alias ytv-best="youtube-dl -f bestvideo+bestaudio "
fi
## Backup
[ -f "${HOME}/.dotfiles/bin/backup.sh" ] && \
alias backup="${HOME}/.dotfiles/bin/backup.sh"
# Archive
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n"
;;
*.lzma)
unlzma ./"$n"
;;
*.bz2)
bunzip2 ./"$n"
;;
*.cbr|*.rar)
unrar x -ad ./"$n"
;;
*.gz)
gunzip ./"$n"
;;
*.cbz|*.epub|*.zip)
unzip ./"$n"
;;
*.z)
uncompress ./"$n"
;;
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n"
;;
*.xz)
unxz ./"$n"
;;
*.exe)
cabextract ./"$n"
;;
*.cpio)
cpio -id < ./"$n"
;;
*.cba|*.ace)
unace x ./"$n"
;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
# Lsmod all with pararms
function lsmodp {
cat /proc/modules | cut -f 1 -d " " | while read module; do
echo "Module: $module"
if [ -d "/sys/module/$module/parameters" ]; then
ls /sys/module/$module/parameters/ | while read parameter; do
echo -n "Parameter: $parameter --> "
sudo cat /sys/module/$module/parameters/$parameter
done
fi
echo
done
}
if [ -S "${HOME}/.1password/agent.sock" ]; then
[ -z "${SSH_CONNECTION}" ] && export SSH_AUTH_SOCK=$HOME/.1password/agent.sock
#elif [ -S "$XDG_RUNTIME_DIR/gcr/ssh" ]; then
# [ -z "${SSH_CONNECTION}" ] && export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/gcr/ssh"
#else
# [ -z "${SSH_CONNECTION}" ] && export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
fi
# WSL with 1Password
if [ $(command -v npiperelay.exe) ] && [ ! -z ${WSL_DISTRO_NAME+x} ]; then
# Code extracted from https://stuartleeks.com/posts/wsl-ssh-key-forward-to-windows/
if [ ! -d "${HOME}/.1password" ]; then
mkdir "${HOME}/.1password"
fi
# Configure ssh forwarding
# need `ps -ww` to get non-truncated command for matching
# use square brackets to generate a regex match for the process we want but that doesn't match the grep command running it!
ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?)
if [[ $ALREADY_RUNNING != "0" ]]; then
if [[ -S $SSH_AUTH_SOCK ]]; then
# not expecting the socket to exist as the forwarding command isn't running (http://www.tldp.org/LDP/abs/html/fto.html)
echo "removing previous socket..."
rm $SSH_AUTH_SOCK
fi
echo "Starting SSH-Agent relay..."
# setsid to force new session to keep running
# set socat to listen on $SSH_AUTH_SOCK and forward to npiperelay which then forwards to openssh-ssh-agent on windows
(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1
fi
fi