-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.shell_aliases
More file actions
283 lines (260 loc) · 8.08 KB
/
Copy path.shell_aliases
File metadata and controls
283 lines (260 loc) · 8.08 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# -*- mode: shell-script; sh-shell: zsh -*-
# Globals {{{
local loc=$(readlink ~/.zshrc)
export DOTFILES_HOME=$(dirname $loc)
export PATH=$DOTFILES_HOME/scripts:$PATH
# }}}
# Convenience {{{
alias update-grub="sudo grub-mkconfig -o /boot/grub/grub.cfg"
function edit() {
what=${1:-.}
if [ -d "$what" ]; then
# `ccd` is a custom function/command that I made to make sure nyaatree and my custom affe commands actually run
# in the actual project root, and not the root according to emacs' neat but infuriatingly shit root detection
# system. It fails to deal with projects that have multiple roots (and that should have multiple roots for the
# sake of LSPs), but that still needs to allow for a single, user-selected root for navigation and similar.
emacs --eval="(ccd \"$what\")" & disown
else
# We still run `ccd` if a file (or something that doesn't exist) is specified with the cwd set to ., so nyaatree
# pops up automagically
emacs --eval="(ccd \".\")" "$what" & disown
fi
}
# }}}
# Arch {{{
# Yay does not handle CC and CXX being set
# if CC and CXX are set, firefox-nightly breaks
alias yay="CC= CXX= command yay"
# }}}
# Builtins {{{
# ls without colors for dipshit 777 disks
alias lsn="ls --color=no"
alias open="xdg-open"
alias igrep="grep -i"
alias lsg="ls -la | grep -i"
# }}}
# Git {{{
alias gi="git init"
alias subclone="git submodule update --init --recursive"
alias gitdeep="git clone --recursive"
alias gitgraph="git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all"
alias gitsign="git config commit.gpgsign true"
alias gsi="git submodule update --init"
alias gcget="git config --get"
alias grhu='git reset --hard origin/$(git branch --show-current)'
alias grh="git reset --hard"
alias gra="git commit --amend --no-edit"
alias gai="git add -i"
alias ga="git add -A"
alias groot="git rev-parse --show-toplevel"
alias gcd='cd $(groot)'
alias git-log-oneline-author='git log --format="%Cgreen%h%Creset %<(25)%an (%<(50)%ae) %ad%x09%s"'
function ghsclone() {
if [[ "$1" == "" ]]; then
echo "Clone what?"
return -1
fi;
git clone "git@github.com:$1"
}
function git-mirror-config-cb-source() {
codebergUrl=$(git remote get-url --push origin)
ghUrl=${codebergUrl/codeberg.org/github.com}
git remote set-url --add --push origin ${codebergUrl}
git remote set-url --add --push origin ${ghUrl}
}
function git-mirror-config-gh-source() {
ghUrl=$(git remote get-url --push origin)
codebergUrl=${ghUrl/github.com/codeberg.org}
git remote set-url --add --push origin ${ghUrl}
git remote set-url --add --push origin ${codebergUrl}
}
function git-apply-clipboard() {
if [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then
wl-paste | git apply
else
xclip -selection clipboard -o | git apply
fi
}
# }}}
# Hardware {{{
alias noiturbo="echo '1' | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo"
alias iturbo="echo '0' | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo"
alias pulsenodio="pulseaudio -k && sudo alsa force-reload"
alias pipenodio="systemctl --user restart pipewire"
alias fix-bluetooth="pactl unload-module module-bluetooth-discover && pactl load-module module-bluetooth-discover"
# }}}
# Tmux {{{
# **tmux n**ame
alias tmuxn="tmux new-session -t"
# }}}
# Zellij {{{
alias zn="zellij --session "
# }}}
# ffmpeg {{{
# convert standalone MP3s to spotify-compatible audio levels
alias normalize-all-audio="ffmpeg-normalize *.mp3 -c:a libmp3lame -ext mp3 -b:a 320k -f -t -14"
alias normalize-audio="ffmpeg-normalize -c:a libmp3lame -ext mp3 -b:a 320k -f -t -14"
function mkv2mp3() {
if [[ "$1" == "" || "$2" == "" ]]; then
echo "Usage: mkv2mp3 src.mkv dest.mp3"
return -2
fi
ffmpeg -i $1 -map 0:a:0 -b:a 320k $2
}
# }}}
# asciinema extensions {{{
function asciinemaProfile() {
if [[ -n "$1" ]]; then
ln -sf $HOME/.config/asciinema/install-id-$1 $HOME/.config/asciinema/install-id
else
echo "Specify which profile to use"
fi
}
# }}}
# sshd aliases {{{
alias sshd-auths="cat /var/log/auth.log | grep sshd"
# Stats on usernames
alias sshd-auth-bad="cat /var/log/auth.log | grep sshd | grep 'invalid user'"
# No need to check root, the config has it as an invalid user
# }}}
# ssh {{{
alias sshd-restart="sudo systemctl restart ssh"
# }}}
# Command shortening {{{
function mkcd() {
if [[ "$1" != "" ]]; then
mkdir -p $1 && cd $1
else
echo "Create what?"
fi
}
function cleanmk() {
if [[ "$1" != "" && "$1" != "/" ]]; then
rm -rf $1 && mkdir $1 && cd $1
else
echo "Invalid path, or path was root (rm-ing root is bad!)"
fi
}
# }}}
# Utility {{{
function notify-me() {
umbra pty -- "$@"
if [[ $? == 0 ]]; then
notify-send "Done"
else
notify-send "Failed!"
fi
}
# }}}
# CMake/make {{{
alias cmaker="echo Deprecated: use 'ccmake Release'"
alias cmaked="echo Deprecated: use 'ccmake'"
alias fmake='make -j $(nproc)'
function testmake() {
# I am so fucking happy about this
umbra watch -c "catch2-parse" -- ../src ../tests ../CMakeLists.txt
}
# }}}
# Network fuckery {{{
# Only enabled on pihole-enabled devices or my devices in general, because this is aimed at my home network only,
# and remoting into my home network.
#
# TODO merge these into a single function
if [[ `( nmcli dev list || nmcli dev show ) 2>/dev/null | grep IP4.DNS | grep 192.168.0.179` != '' ]]; then
function nasmountall() {
sshfs olivia@nova.lan:/media/NAS /media/NAS
}
else
function nasmountall() {
sshfs olivia@nova.remote:/media/NAS /media/NAS
}
fi
if [[ $USER == "olivia" ]]; then
# Equivalent to nasmountall, but takes a single IP as input
# The IP has to be manually configured in ~/.ssh/config first.
function nasmountremote() {
sshfs olivia@${1:-nova.remote}:/media/NAS /media/NAS
#sshfs olivia@${1:-nova.remote}:/media/NAS1 /media/NAS1
}
function nasumount() {
umount /media/NAS
}
fi
# }}}
# WSL bullshit {{{
if [[ $(grep -i Microsoft /proc/version) ]]; then
# No automatic services (TODO: outdated?)
function bootstrapenv() {
sudo service postgresql start
}
fi
# }}}
# Gpg {{{
alias gpgsign="gpg --clearsign "
function gpgsend() {
if [[ $1 == "" || $2 == "" || $1 == "--help" ]]; then
echo "Usage: gpgsend email message-file"
return 0
fi
gpg --sign --encrypt --recipient $1 $2
}
function gpgexport() {
if [[ $1 == "" || $2 == "" || $1 == "--help" ]]; then
echo "Usage: gpgexport output-path email"
return 0
fi
gpg --output $1 --armor --export $2
}
# }}}
# Ssh keygen and key admin {{{
function ssh-fixperms() {
chmod 600 ~/.ssh/*
chmod 700 ~/.ssh
}
function o-ssh-keygen() {
if [[ "$1" == "" || "$2" == "" ]]; then
echo "Usage: o-ssh-keygen [email] [file name]"
return -1
fi
ssh-keygen -t ed25519 -C $1 -f ~/.ssh/$2
echo "Copy this line to whereever you need access:"
cat ~/.ssh/$2.pub
}
# }}}
# Pass-cli {{{
alias work-agent="pass-cli ssh-agent start --vault-name Work"
alias ssh-agent="pass-cli ssh-agent start --vault-name 'SSH Keys'"
# }}}
# Project utilities {{{
alias open-doxygen="open ./html/index.html"
# }}}
# Testing utils {{{
function display-wrap() {
Xvfb :10 -ac -screen 0 1280x1024x24 >/dev/null 2>&1 &
mockDisplayPid=$!
DISPLAY=:10 zsh -ic "$*"
kill $mockDisplayPid
}
# }}}
# Ubuntu stuff {{{
alias pbi="pip3 install --break-system-packages "
alias pbu="pip3 uninstall --break-system-packages "
# }}}
# PSQL {{{
alias psql-update='sudo -u postgres psql -c "ALTER DATABASE postgres REFRESH COLLATION VERSION"'
alias spsql='sudo -u postgres psql '
# }}}
# yt-dlp {{{
alias ytmp3="yt-dlp -x --audio-format mp3 "
# }}}
# gdb {{{
# alias gdb="gdb --tui "
# }}}
# Gradle {{{
function gw() {
umbra pty -- ./gradlew "$@" | less -r
}
# }}}
if [ -f "${DOTFILES_HOME}/scripts/homelab.zsh" ]; then
source "${DOTFILES_HOME}/scripts/homelab.zsh"
fi