/
.aliases
230 lines (187 loc) · 5.68 KB
/
.aliases
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
#!/bin/bash
alias shutdown="sudo shutdown"
alias reboot="sudo reboot"
alias suspend="systemctl suspend"
alias s="sudo"
if [ -e /usr/bin/yay ]; then
alias inst="yay -S"
else
alias inst="sudo pacman -S"
fi
alias prog="cd /data/programming"
alias start="sudo systemctl start"
alias stop="sudo systemctl stop"
alias status="sudo systemctl status"
alias restart="sudo systemctl restart"
alias enable="sudo systemctl enable"
alias disable="sudo systemctl disable"
alias ustart="systemctl --user start"
alias ustop="systemctl --user stop"
alias ustatus="systemctl --user status"
alias urestart="systemctl --user restart"
alias uenable="systemctl --user enable"
alias udisable="systemctl --user disable"
if which zathura >/dev/null 2>&1; then
zathura() {
/usr/bin/zathura "${@}" &!
}
fi
if [[ -n "$DISPLAY" ]]; then
ec() {
setopt local_options bash_rematch re_match_pcre
if [[ "$1" =~ '^(.+?):([0-9]+(:[0-9]+)?)$' ]]; then
local file="${BASH_REMATCH[2]}"
local line="${BASH_REMATCH[3]}"
emacsclient -nc "+$line" "$file"
else
emacsclient -nc "${@}"
fi
}
else
alias ec='vim'
fi
alias sec='sudoedit'
if which hub >/dev/null 2>&1; then
alias git=hub
else
echo "Install hub!"
fi
alias aoe="zathura /data/bible.pdf &!"
if which bat >/dev/null 2>&1; then
alias cat=bat
else
echo "Install bat!"
fi
alias icat='kitty +kitten icat'
alias pping='prettyping --nolegend'
alias cwt="git worktree prune"
twt() {
local branch="${2:-feature/$1}"
if git rev-parse --verify "$branch" >/dev/null 2>/dev/null; then
git worktree add /tmp/$1 "$branch"
else
git worktree add /tmp/$1 -b "$branch"
fi
cd /tmp/$1
}
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
alias ll="ls -laF"
alias dc='docker-compose'
alias ip='ip -color=auto'
alias mpv-pl='mpv --no-resume-playback --profile=audio'
function _play_transform () {
if [[ "${_play_files_local}" == "true" ]]; then
sed 's|/media/|/data/|' | sed 's/flac/ogg/'
else
cat
fi
}
function play() {
local mpvargs=()
_play_files_local=false
while [[ "$1" == "--"* ]]; do
if [[ "$1" == "--local" ]]; then
_play_files_local=true
else
mpvargs+="$1"
fi
shift
done
local playlist=$1
shift
if [[ "$playlist" == "albums" ]]; then
while true; do
mpv-pl "${mpvargs[@]}" --playlist=<(beet ls -p album_id:$(beet ls -a -f '$id' "${@}" | shuf -n 1) track+ | _play_transform)
done
elif [[ "$playlist" == "albums_ordered" ]]; then
beet ls -a -f '$id' "${@}" | while read -r albumid; do
mpv-pl "${mpvargs[@]}" --playlist=<(beet ls -p album_id:"$albumid" track+ | _play_transform)
done
elif [[ "$playlist" == "songs" ]]; then
mpv-pl "${mpvargs[@]}" --playlist=<(beet ls -p "$@" | _play_transform)
elif [[ -f "/media/media/Music/Playlists/$playlist.url" ]]; then
mpv-pl "${mpvargs[@]}" $(cat "/media/media/Music/Playlists/$playlist.url") "$@"
elif [[ -f "/media/media/Music/Playlists/$playlist.m3u" ]]; then
mpv-pl "${mpvargs[@]}" "/media/media/Music/Playlists/$playlist.m3u" "$@"
elif [[ -d "/media/media/Music/Playlists/$playlist" ]]; then
mpv-pl "${mpvargs[@]}" "/media/media/Music/Playlists/$playlist" "$@"
fi
}
function mpv-gjm() {
local filename="$1"
mpv "$filename" --sub-file <(mkvextract -r /dev/stderr "$filename" tracks 2:/dev/stdout | sed 's/sparky/biribiri/; s/Sparky/Biribiri/; s/milady/onee-sama/; s/Milady/Onee-sama/')
}
function mkcd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
function cdtmp() {
if [[ "$#" = 0 ]]; then
mkcd "/tmp/$(pwgen 10 1)"
else
local IFS="-"
mkcd "/tmp/${*}-$(pwgen 10 1)"
fi
}
function cp-base() {
local dest
local dest_opt_index="${argv[(ie)--dest]}"
if [ "$dest_opt_index" -lt "${#argv}" ]; then
# We got a match
dest="${argv[$((dest_opt_index + 1))]}"
# Delete --dest
argv[$dest_opt_index]=()
# Delete dest arg
argv[$dest_opt_index]=()
fi
local base="$1"
shift
local this_dest
for src in "${@}"; do
if [ -n "$dest" ]; then
this_dest="$dest"/"$src"
else
this_dest="$src"
fi
mkdir -p "$(dirname "$this_dest")"
cp "$base"/"$src" "$this_dest"
done
}
function spectrum() { sox $1 -n spectrogram -o - | feh -. - }
function update() {
setopt local_options err_return
yay -Syu --repo "${@}"
$ZDOTDIR/archlinux-update-modules/archlinux-update-modules --dont-ask || true
yay -Qu --aur --devel
yay -Quq --aur --devel | xargs -n 1 yay -S --noconfirm
yay -Sc --aur --noconfirm
sudo pkgcacheclean -v 2
rustup update
antigen selfupdate
antigen update
}
# This is a function to avoid completion
function dotfiles() {
if [ -d ~/.local/share/dotfiles ]; then
local dotfiles_dir=$HOME/.local/share/dotfiles
else
local dotfiles_dir=/data/programming/dotfiles/master
fi
git --git-dir="$dotfiles_dir" --work-tree="$HOME" "${@}"
}
function gwt() {
cdpath=$(~/.local/bin/gwt ${@}) || return $?
test -n "$cdpath" && cd "$cdpath"
return 0
}
function fork() {
kitty --detach
}
if which kitty >/dev/null 2>&1 && [[ "$TERM" == "xterm-kitty" ]]; then
alias ssh="kitty +kitten ssh"
alias sssh="TERM=xterm-256color \ssh"
fi