-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_aliases
320 lines (277 loc) · 11.1 KB
/
.bash_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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/env bash
# No Internal Field Separator. To split spaces, newlines, and tabs: IFS=$' \n\t'
unset IFS
################################################################################
# Preferred editor for local and remote sessions
################################################################################
export EDITOR=nvim
export VISUAL="$EDITOR"
if [[ -v SSH_CONNECTION ]]; then
if [[ $(command -v nvim) ]]; then
export EDITOR=nvim
elif [[ $(command -v vim) ]]; then
export EDITOR=vim
elif [[ $(command -v vi) ]]; then
export EDITOR=vi
fi
fi
if [[ $(command -v nvimpager) ]]; then
export PAGER=nvimpager
elif [[ $(command -v most) ]]; then
export PAGER=most
fi
################################################################################
# Ranger.
################################################################################
# Disable loading Ranger's global configuration files because custom
# configurations are provided.
export RANGER_LOAD_DEFAULT_RC=FALSE
################################################################################
# Node Version Manager.
################################################################################
[[ -f /usr/share/nvm/init-nvm.sh ]] && source /usr/share/nvm/init-nvm.sh
[[ $(command -v npm) ]] && nvm_node_modules=$(npm -g root)/npm/node_modules
################################################################################
# Lynx Browser.
################################################################################
export LYNX_CFG=$HOME/.config/lynx/lynx.cfg
export LYNX_LSS=$HOME/.config/lynx/lynx.lss
################################################################################
# Functions.
################################################################################
say() {
gtts-cli "${*}" | mpv -
}
# Unzip the file to a directory with the same file name minus .zip extension.
unzipd() {
local name="$1"
unzip "$name" -d "$(basename "$name" .zip)"
}
# Go to directory, open file, go to previous directory.
scratchpad() {
cd /tmp && nvim "$@" && { cd - || exit; }
}
repo_git() {
git --git-dir="$1" --work-tree="$2" "${@:3}"
}
repo_ui() {
gitui -d "$1" -w "$2" "${@:3}"
}
lfcd() {
local temporary_directory
temporary_directory=$(mktemp)
lf --last-dir-path "$temporary_directory" "$@"
cd "$(cat "$temporary_directory")" || exit
rm "$temporary_directory"
}
rangercd() {
local temporary_directory
temporary_directory=$(mktemp)
ranger --choosedir="$temporary_directory" -- "${@:-$PWD}"
cd "$(cat "$temporary_directory")" || exit
rm "$temporary_directory"
echo "Level ${RANGER_LEVEL:-0}"
}
joshutocd() {
local id=$$
mkdir -p "/tmp/$USER"
local output_file="/tmp/$USER/joshuto-cwd-$id"
env joshuto --output-file "$output_file" "$@"
local exit_code=$?
case "$exit_code" in
# regular exit
0) ;;
# output contains current directory
101) cd "$(cat "$output_file")" || exit ;;
# output selected files
102) ;;
*) echo "Exit code: $exit_code" ;;
esac
}
# Create a symlink to globally installed node modules for access to Mocha and Chai.
setup_js_scratchpad() {
cd /tmp || exit
if [[ ! -f package.json ]]; then
npm init -f >/dev/null
ln -s "$nvm_node_modules" node_modules
ln -s ~/.config/nvim/templates/.eslintrc.yml .eslintrc.yml
ln -s ~/.config/nvim/templates/.prettierrc.yml .prettierrc.yml
fi
}
jsscratch() {
setup_js_scratchpad
nvim scratchpad.mjs "$@"
cd - || exit
}
jsscratchtest() {
setup_js_scratchpad
nvim scratchpad_test.mjs "$@"
cd - || exit
}
# Create cargo project rather than individual file.
rsscratch() {
cd /tmp || exit
if [[ ! -d rsscratch ]]; then
cargo new rsscratch
fi
nvim /tmp/rsscratch/src/main.rs "$@"
cd - || exit
}
################################################################################
# Aliases.
################################################################################
alias alacrittyconfig='$EDITOR ~/.config/alacritty/alacritty.yml'
alias awesomeconfig='$EDITOR ~/.config/awesome/rc.lua'
alias bashconfig='$EDITOR ~/.bashrc'
alias cppmanconfig='$EDITOR ~/.config/cppman/cppman.cfg'
alias doomconfig='$EDITOR ~/.config/doom/config.el'
alias dwlconfig='$EDITOR ~/.config/dwl/'
alias emacsconfig='$EDITOR ~/.config/doom/init.el'
alias gitconfig='$EDITOR ~/.config/git/config'
alias home-config='$EDITOR ~/.config/home-manager/home.nix'
alias hyprconfig='$EDITOR ~/.config/hypr/hyprland.conf'
alias hypridleconfig='$EDITOR ~/.config/hypr/hypridle.conf'
alias joshutoconfig='$EDITOR ~/.config/joshuto/'
alias lynxconfig='$EDITOR .config/lynx/lynx.cfg'
alias mostconfig='$EDITOR ~/.config/mostrc'
alias mpdconfig='$EDITOR ~/.config/mpd/mpd.conf'
alias mpvconfig='$EDITOR ~/.config/mpv'
alias ncmpcppconfig='$EDITOR ~/.config/ncmpcpp/'
alias neomuttconfig='$EDITOR ~/.config/mutt/'
alias neomuttmsmtpconfig='$EDITOR ~/.config/msmtp/config'
alias newsboatconfig='$EDITOR ~/.config/newsboat/'
alias nixconfig='sudo -E $EDITOR /etc/nixos/configuration.nix'
alias nuconfig='$EDITOR ~/.config/nushell/config.nu'
alias nuconfigenv='$EDITOR ~/.config/nushell/env.nu'
alias nvimconfig='$EDITOR ~/.config/nvim/init.lua'
alias nvimlspconfig='$EDITOR ~/.config/nvim/lua/plugins/lspconfig.lua'
alias nvimnullconfig='$EDITOR ~/.config/nvim/lua/plugins/null-ls.lua'
alias nvimpagerconfig='$EDITOR ~/.config/nvimpager/init.vim'
alias nvimswap='cd ~/.local/share/nvim/swap/'
alias picomconfig='$EDITOR ~/.config/picom/picom.conf'
alias qtileconfig='$EDITOR ~/.config/qtile/config.py'
alias rangercache='cd ~/.cache/ranger/'
alias rangerconfig='$EDITOR ~/.config/ranger/'
alias rifleconfig='$EDITOR ~/.config/ranger/rifle.conf'
alias roficonfig='$EDITOR ~/.config/rofi/config.rasi'
alias scopeconfig='$EDITOR ~/.config/ranger/scope.sh'
alias shellconfig='$EDITOR ~/.bash_aliases && source ~/.bash_aliases'
alias starshipconfig='$EDITOR ~/.config/starship.toml'
alias vimbconfig='$EDITOR ~/.config/vimb/config'
alias vscodiumconfig='$EDITOR ~/.config/VSCodium/User/'
alias waybarconfig='$EDITOR ~/.config/waybar/'
alias wlogoutconfig='$EDITOR ~/.config/wlogout/layout'
alias woficonfig='$EDITOR ~/.config/wofi/config'
alias zathuraconfig='$EDITOR ~/.config/zathura/zathurarc'
alias zictconfig='$EDITOR ~/.config/zict/zict.bash'
alias zshconfig='$EDITOR ~/.config/zsh/.zshrc'
alias zwimconfig='$EDITOR ~/.config/zwim/zwim.mjs'
alias passconfig='cd ~/.local/share/pass'
alias passbackup='cp -viur ~/.local/share/pass/* /run/user/1000/5bfbfc95be7243f8/primary/pass/'
alias passrefresh='kdeconnect-cli --refresh'
# alias passdiff='diff -q -r ~/.local/share/pass/ /run/user/1000/5bfbfc95be7243f8/primary/pass/'
alias awkscratch='scratchpad scratchpad.awk'
alias bashscratch='scratchpad scratchpad.bash'
alias confluencescratch='scratchpad scratchpad.confluencewiki'
alias cppscratch='scratchpad scratchpad.cpp'
alias cscratch='scratchpad scratchpad.c'
alias elscratch='scratchpad scratchpad.el'
alias groovyscratch='scratchpad scratchpad.groovy'
alias javascratch='scratchpad scratchpad.java'
alias luascratch='scratchpad scratchpad.lua'
alias mdscratch='scratchpad scratchpad.md'
alias nuscratch='scratchpad scratchpad.nu'
alias nvimscratch='scratchpad nvim-scratchpad.lua'
alias plscratch='scratchpad scratchpad.pl'
alias pyscratch='scratchpad scratchpad.py'
alias pyscratchtest='scratchpad scratchpad_test.py'
alias sagescratch='scratchpad scratchpad.sage'
alias typscratch='scratchpad scratchpad.typ'
alias zshscratch='scratchpad scratchpad.zsh'
if [[ $(command -v lsd) ]]; then
# Show icons along with files and directories.
alias l='lsd -lah'
alias la='lsd -lAh'
alias ll='lsd -lh'
alias ls='lsd'
alias tree='lsd --tree'
fi
if [[ $(command -v bat) ]]; then
# Add syntax highlighting to printed files.
alias cat='bat --style=plain --paging=never'
fi
alias dotfiles='repo_git ~/.config/dotfiles/ ~'
alias dotfilesui='repo_ui ~/.config/dotfiles/ ~ && git-summary ~/Documents -s'
alias passbgit='repo_git ~/.local/share/pass/.backup/.git ~/.local/share/pass/.backup'
alias passbgui='repo_ui ~/.local/share/pass/.backup/.git ~/.local/share/pass/.backup'
# Zict dictionary aliases.
alias en='zict alter en'
alias ens='zict search en'
alias es='zict alter es'
alias esb='zict search es'
alias it='zict it'
alias ja='zict alter ja'
alias ru='zict alter ru'
alias rus='zict search ru'
alias ан='zict alter en'
alias ани='zict search en' # искать
alias ру='zict alter ru'
alias руи='zict search ru' # искать
# Dictionary aliases.
alias da='sdcv --non-interactive --color' # Dictionary all <word>
alias de='sdcv --non-interactive --color --use-dict --exact-search WordNet' # Dictionary exact <word>
alias di='sdcv --non-interactive --color --use-dict WordNet' # Dictionary <word>
alias th='sdcv --non-interactive --color --use-dict "Moby Thesaurus II"' # Thesaurus <word>
alias e='exit'
alias g='git'
alias j='joshutocd'
alias l='lfcd'
alias m='man -Hlynx'
alias n='nvim'
alias r='rangercd'
alias v='nvim'
alias в='exit'
alias y='yt-dlp --write-thumbnail --extract-audio --sub-langs "en.*,ja,es,ru" --write-subs --audio-format mp3 --paths ~/Music/YouTube'
alias yd='yt-dlp --write-thumbnail --extract-audio --sub-langs "en.*,ja,es,ru" --write-subs --audio-format mp3 --paths'
alias alacrittyx11='WAYLAND_DISPLAY= alacritty'
alias bc='bc --mathlib'
alias cheat='cht.sh'
alias gdiff='git fetch && git diff origin/master HEAD'
alias lf='$HOME/Code/lfimg/lfrun'
alias locksway='swaylock -i /usr/share/backgrounds/suckless-wallpapers/nord_hills.png'
alias lockx='xscreensaver-command -lock'
alias man='man -a'
alias nr='setsid --fork alacritty -e ranger'
alias nt='setsid --fork alacritty'
alias nullls='cd $HOME/.local/share/nvim/lazy/null-ls.nvim/lua/null-ls/builtins'
alias playmusic='mpv --shuffle ~/Music/*'
alias restart-pipewire='systemctl --user restart pipewire.service'
alias rgf='rg --files | rg'
alias rsyncdelete='rsync -arv --delete'
alias rsyncdryrun='rsync -arvn --delete'
cdf(){
[[ -v 1 ]] && {
cd "$1" || exit
}
if git rev-parse --is-inside-work-tree 2> /dev/null; then
cd "$(find "$(git rev-parse --show-toplevel)" -type d -not -path '*/node_modules/*' -not -path '*/.git/*' | fzf)" || exit
else
cd "$(find ./* .config -type d | fzf)" || exit
fi
}
alias mpvh='mpv --config-dir="$HOME/.config/mpv/base"'
alias zathurah='zathura --config-dir="$HOME/.config/zathura/base"'
alias nixadd='nix derivation add'
alias nixadd='nix derivation show'
alias nixedit='nix edit -f "<nixpkgs>"'
alias nixrepl='nix repl --file "<nixpkgs/nixos>" -I nixos-config=/etc/nixos/configuration.nix'
alias nixsearch='nix search nixpkgs --extra-experimental-features flakes'
# XDG-Ninja.
alias wget=wget --hsts-file='$XDG_DATA_HOME/wget-hsts'
# https://unix.stackexchange.com/questions/79112/how-do-i-set-time-and-date-from-the-internet
# sudo ntpd -qg; sudo hwclock -w
alias fixtime='sudo ntpd -qg'
# Only enter SSH password once.
# keychain --quiet --eval id_rsa > /dev/null
# shellcheck source=./.my_aliases
[[ -f ~/.my_aliases ]] && source ~/.my_aliases