-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashrc
298 lines (241 loc) · 7.21 KB
/
bashrc
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
# Bash
# https://gnu.org/software/bash/
# https://github.com/alacritty/alacritty/issues/3624
# unset LIBGL_ALWAYS_SOFTWARE
# Starship
# https://starship.rs
eval "$(starship init bash)"
# McFly
# https://github.com/cantino/mcfly
eval "$(mcfly init bash)"
# zoxide
# https://github.com/ajeetdsouza/zoxide
eval "$(zoxide init bash)"
# Aliases ──────────────────────────────────────────────────────────────────────
alias q=exit
alias md='mkdir -p --'
alias _='rm -Rf --'
# Spawns a command.
spawn() {
nohup "$@" < /dev/null > /dev/null 2>&1 &
}
alias @=spawn
# Run `sudo` with aliases
alias sudo='sudo '
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
# NixOS
# https://nixos.org
alias nix-update='sudo nixos-rebuild switch'
alias nix-upgrade='sudo nixos-rebuild switch --upgrade --keep-going --fallback'
alias nix-gc='sudo nix-collect-garbage --delete-old'
# Compiling
alias nix-cargo="nix-shell --run 'cargo build --release' --packages pkg-config openssl rustup"
alias nix-shards="nix-shell --run 'shards build --release --production' --packages pkg-config openssl crystal shards"
# ifconfig.co
# https://ifconfig.co
alias ipd='curl ifconfig.co'
# nginx
# https://nginx.org
alias nginx='sudo nginx -c /etc/nginx/nginx.conf'
# procs
# https://github.com/dalance/procs
alias ps=procs
# htop
# https://htop.dev
alias top=htop
# rsync
# https://rsync.samba.org
alias rsync='rsync -azH --info=progress2 --delete'
alias rsync='rsync --archive --compress --hard-links --info=progress2 --delete'
# tar.xz
txz() {
tar caf "$1.tar.xz" "$1"
}
# bat
# https://github.com/sharkdp/bat
alias cat=bat
# ripgrep
# https://github.com/BurntSushi/ripgrep
alias grep='rg --smart-case'
# curl
# https://curl.haxx.se
alias curl='curl -sSL'
# archiver
# https://github.com/mholt/archiver
alias x='arc unarchive'
# tmux
# https://github.com/tmux/tmux
alias t=tmux
alias ta='tmux attach-session'
alias tl='tmux list-sessions'
# Kakoune
# https://kakoune.org
alias k=kak
alias ke=kak_set_env
alias kE='kak_set_env "$(basename "$PWD")"'
alias ks=kak_server
alias kS='kak_server "$(basename "$PWD")"'
alias ko=kak_open
alias ka='kak -c "$KAKOUNE_SESSION"'
alias kn='kak -n'
alias kl='kak -l'
# Usage:
# kak_set_env [session] [client]
# Sets `KAKOUNE_SESSION` and `KAKOUNE_CLIENT` environment variables.
kak_set_env() {
export KAKOUNE_SESSION=$1 KAKOUNE_CLIENT=$2
}
# Usage:
# kak_server <session>
# Only runs as server.
# Sets `KAKOUNE_SESSION` and `KAKOUNE_CLIENT` environment variables.
kak_server() {
nohup kak -d -s "$1" < /dev/null > /dev/null 2>&1 &
kak_set_env "$1"
}
# Usage:
# kak_open [files]
# Uses `KAKOUNE_SESSION` and `KAKOUNE_CLIENT` environment variables.
kak_open() {
{
for filename do
echo "edit -- %($filename)"
done
echo "evaluate-commands -try-client %($KAKOUNE_CLIENT) -verbatim -- edit %($1)"
} |
kak -p "$KAKOUNE_SESSION"
}
# sidetree
# https://github.com/topisani/sidetree
alias st='sidetree --select'
alias st.=sidetree
# Git
# https://git-scm.com
# https://cli.github.com
# https://github.com/extrawurst/gitui
alias g=git
alias G=gitui
alias gw='git add'
alias gw.='gw .'
alias gl='git log'
alias gst='git status'
# Commit
alias gci='git commit'
alias gcm='git commit --message'
alias greword='git commit --amend'
alias gpick='git commit --amend --no-edit'
alias gsnapshot='date "+%F %T" | git commit --file=-'
# Undo
alias gu='git restore --staged'
alias gD='git restore --staged --worktree'
alias gD.='gD .'
alias grb='git reset --hard'
alias grb^='git reset --hard HEAD^'
alias ggc=git-gc-all-ferocious
# Navigation
alias gco='git checkout -b'
alias gcd='cd "$(git rev-parse --show-toplevel)"'
# Web
alias gv='gh repo view --web'
alias gist='gh gist create --web'
gc() {
[ $# -lt 2 ] && suffix=.git
repository=${1}${suffix}
directory=$1; directory=${directory#https://}; directory=${directory%.git}; directory=~/.local/share/$directory
pastel paint green --bold "Cloning '$repository' into '$directory'"
git clone "$repository" "$directory"
}
gc2() {
gc "$1" ''
}
gg() {
gw.
gD.
ggc
}
GG() {
set -- ~/.local/share/github.com/*/* ~/.local/share/gitlab.com/*/* ~/.local/share/git.sr.ht/*/*
for repository do
pastel paint green --bold "$repository"
cd "$repository"
gw.
gD.
ggc
g pull
done
cd
}
# exa
# https://the.exa.website
alias l='exa --icons'
alias la='exa --icons --all'
alias ll='exa --icons --git --long'
alias lla='exa --icons --git --long --all'
alias L='exa --tree'
alias La='exa --tree --all'
# batch
# https://github.com/taupiqueur/batch
# interactive map
imap() {
batch -f 'iconv -f UTF-8 -t ASCII//TRANSLIT//IGNORE' -f 'tr [:upper:] [:lower:]' -f "tr -s \\'[:blank:] -" -f 'tr -d ?!,' "$@"
}
# auto map
amap() {
imap -E "$@"
}
# interactive mv
imv() {
imap -p : -M 'mkdir -vp -- "$(dirname -- "$2")" && mv -vi -- "$1" "$2"' -d 'rm -vi --' "$@"
}
# File manager
alias o=dolphin
# Web browser
alias b=google-chrome-stable
# mpv
# https://mpv.io
alias @mpv='@ mpv --no-terminal'
alias m=mpv
alias ms='mpv --shuffle'
# yt-dlp
# https://github.com/yt-dlp/yt-dlp
alias y=yt-dlp
# Pandoc
# https://pandoc.org
alias pandoc='pandoc --pdf-engine tectonic'
# Ruby on Rails
# https://rubyonrails.org
alias r=rails
alias rr='rails routes --grep'
# Window managers ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
# Sway
# https://swaywm.org
# https://github.com/swaywm/sway/issues/3851
alias sway='WLR_NO_HARDWARE_CURSORS=1 sway'
# i3
# https://i3wm.org
# https://github.com/alacritty/alacritty/issues/3500
alias i3='startx /usr/bin/i3 -- -maxbigreqsize 127'
# IDEs ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
# IntelliJ IDEA
# https://jetbrains.com/idea/
# https://github.com/swaywm/sway/issues/595
alias idea-community='_JAVA_AWT_WM_NONREPARENTING=1 @ idea-community'
# Android Studio
# https://developer.android.com/studio
# https://github.com/swaywm/sway/issues/595
alias android-studio='_JAVA_AWT_WM_NONREPARENTING=1 @ android-studio'
# Functions ────────────────────────────────────────────────────────────────────
# Reloads bashrc.
reload_bashrc() {
. ~/.bash_profile
}
# RVM
# https://rvm.io
# . ~/.rvm/scripts/rvm
# macOS ────────────────────────────────────────────────────────────────────────
# Sets the PATH environment variable for all services on macOS.
alias set-path='sudo launchctl config user path ~/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/opt/homebrew/sbin:/usr/local/sbin:/usr/sbin:/sbin'
# Erases .DS_Store and .localized files from your home folder.
alias DS_Store="find ~ '(' -name '*.DS_Store' -or -name '*.localized' ')' -print -exec rm -Ri -- {} +"