-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_alias
396 lines (289 loc) · 8.76 KB
/
base_alias
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# base_alias
# vim: ft=sh
# __| \ _ \ | _ \ __| __ __| __ __|
# ( _ \ / | ( | (_ | | |
# \___| _/ _\ _|_\ ____| \___/ \___| _| _|
# -------------------------------------------
# Description: carlogtt personal aliases base
# -------------------------------------------
# -----
# Shell
# -----
if [[ "${SHELL}" == *"zsh"* ]]; then
# Reload ~/.zshrc file
alias src='source ~/.zshrc'
elif [[ "${SHELL}" == *"bash"* ]]; then
# Reload ~/.bashrc file
alias src='source ~/.bashrc'
# Make tab-completion case-insensitive
alias cicbash='bind "set completion-ignore-case on"'
else
# Reload error
alias src='echo -e "[ERROR] Could not detect shell for \`${0}\`. Please reload your shell manually."'
fi
# Clear terminal display
alias c='clear'
# Echo shell and path
alias shell='echo -e "\
\033[1;33mSHELL info:\033[0m \n\
\033[1;33m|--\033[0m Shell in Use: $0 \n\
\033[1;33m|--\033[0m Shell Levels: $SHLVL \n\n\
\033[1;33mPATH directories:\033[0m \n\
\033[1;33m|-- \033[0m${PATH//:/\\n\033[1;33m|-- \033[0m} \n\n\
\033[1;33mFPATH directories:\033[0m \n\
\033[1;33m|-- \033[0m${FPATH//:/\\n\033[1;33m|-- \033[0m}"'
# Same as shell
alias path='shell'
# Check terminal supports 24-bit colors
alias truecolor='printf "\x1b[38;2;255;100;0mTRUECOLOR (should be red)\x1b[0m\n"'
# Restore terminal settings when screwed up
alias fixstty='stty sane'
# ----------------
# General Commands
# ----------------
# Change directories
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias ......='cd ../../../../../'
alias .......='cd ../../../../../../'
alias ........='cd ../../../../../../../'
alias .........='cd ../../../../../../../../'
# Check if 'bat' is installed and configure 'cat' alias
if bat --version >/dev/null 2>&1; then
# Preferred 'cat' implementation
alias cat='bat'
# Get handle on the real 'cat' command
alias realcat='/bin/cat'
fi
# Preferred 'tree' implementation
alias tree='tree -Capugh --du'
# Preferred 'vi' implementation
alias vi='vim'
# Sudo vim
alias svim='sudo vim'
# Preferred 'less' implementation
alias less='less -FRXc'
# Preferred 'wget' implementation
alias wget='wget -c'
# Quickly search for file in current directory
alias ff='sudo find . -iname'
# Preferred 'yazi' implementation
alias y='yazi_cd_into_dir'
# ----
# Grep
# ----
# Colorize the grep command output
alias grep='grep --color=auto'
# Colorize the grep command output
alias egrep='egrep --color=auto'
# Colorize the grep command output
alias fgrep='fgrep --color=auto'
# -----------------------
# ls Command Enhancements
# -----------------------
# Preferred 'ls' implementation
alias ll='ls --color=auto -laFhv'
# Only hidden files - .*
alias llh='ll -d .*'
# Recurve ls
alias llr='ll -R'
# Sort by newest to oldest
alias llt='ll -t'
# Sort by oldest to newest
alias lltr='ll -tr'
# Sort by size largest to smallest
alias lls='ll -S'
# Sort by size smallest to largest
alias llsr='ll -Sr'
# ----------
# Disk Usage
# ----------
# Short and human-readable summarize listing
alias du0='sudo du -h -d 0'
# Short and human-readable directory listing
alias du1='sudo du -h -d 1'
# ------------------
# Process Management
# ------------------
# Preferred 'ps' implementation
alias psa='sudo ps -e -o "pid,ppid,stat,uid,user,pri,ni,tty,%cpu,%mem,rss,vsz,start,time,command"'
# Find process matching string
alias fps='psa | head -n 1; psa | grep -F -i'
# Display open sockets
alias lsock='sudo lsof -i'
# Display only open UDP sockets
# -P and -n to improve performance as we only need the first line
alias lsocku='sudo lsof -i -P -n | head -n 1; lsock | grep -F "UDP"'
# Display only open TCP sockets
# -P and -n to improve performance as we only need the first line
alias lsockt='sudo lsof -i -P -n | head -n 1; lsock | grep -F "TCP"'
# All listening sockets
# -P and -n to improve performance as we only need the first line
alias lsockl='sudo lsof -i -P -n | head -n 1; lsock | grep -F "LISTEN"'
# Find open sockets matching string
# -P and -n to improve performance as we only need the first line
alias fsock='sudo lsof -i -P -n | head -n 1; lsock | grep -F -i'
# ------------------
# Network Management
# ------------------
# My external ip
alias ipext='echo -e "$(curl -s http://ipinfo.io/ip)"'
# ------------------------------
# File and Directory Permissions
# ------------------------------
if [[ $(uname -s) == "Darwin" ]]; then
# Show permission of target in number (macOS)
alias shmod='stat -f "%N %Sp %Lp"'
else
# Show permission of target in number (Linux)
alias shmod='stat --printf="%n %A %a \n"'
fi
# ---------- (nobody)
alias m000='chmod 000'
# -rw------- (user: rw, group: -, other: -)
alias m600='chmod 600'
# -rw-r----- (user: rw, group: r, other: -)
alias m640='chmod 640'
# -rw-r--r-- (user: rw, group: r, other: r)
alias m644='chmod 644'
# -rwxr-xr-x (user: rwx, group: rx, other: rx)
alias m755='chmod 755'
# -rwxrwxr-x (user: rwx, group: rwx, other: rx)
alias m775='chmod 775'
# ---x--x--x (user: --x, group: --x, other: --x)
alias mx='chmod a+x'
# -----------------
# System Management
# -----------------
# exit like vim
alias :q='exit'
# Save Session, detach tmux and disconnect remote host
alias drop='[[ "${-}" =~ i ]] && [[ -n "${SSH_TTY}" ]] && [[ -n "${TMUX}" ]] && \
'"${HOME}/.config/tmux/plugins/tmux-resurrect/scripts/save.sh quiet"' && \
kill -HUP $(ps -eo pid,tty,command | grep -v "grep" | grep "ssh" | grep $(tty | sed "s|/dev/||" | sed "s|/[^/]*$||") | awk "{print \$1}")'
# System reboot
alias reboot='sudo /sbin/reboot'
# System shutdown
alias shutdown='sudo /sbin/shutdown'
# ---------------
# Package Manager
# ---------------
# this cmds need sudo to run
if [ "$(id -u)" -ne 0 ]; then
# yum always as sudo
alias yum='sudo yum'
# dnf always as sudo
alias dnf='sudo dnf'
# apt always as sudo
alias apt='sudo apt'
fi
# ---
# Git
# ---
# lazygit
alias lg='lazygit'
#
alias gs='git status'
#
alias gd='git diff'
#
alias gl='git log --oneline'
#
alias gall='git add .'
#
alias gc='git commit -m'
#
alias gfch='git fetch'
#
alias gps='git push origin HEAD'
#
alias gpl='git pull origin HEAD'
# -------------------
# Brazil Build System
# -------------------
# brazil-build
alias bb='brazil-build'
# brazil-build apollo-pkg
alias bba='brazil-build apollo-pkg'
# brazil-recursive-cmd
alias brc='brazil-recursive-cmd'
# brazil-recursive-cmd --allPackages
alias brcall='brazil-recursive-cmd --allPackages'
# brazil-recursive-cmd brazil-build
alias brcbb='brazil-recursive-cmd brazil-build'
# brazil-recursive-cmd brazil-build apollo-pkg
alias brcbba='brazil-recursive-cmd brazil-build apollo-pkg'
# brazil-recursive-cmd --allPackages brazil-build
alias brcbball='brazil-recursive-cmd --allPackages brazil-build'
# brazil-recursive-cmd <custom_command>
# <custom_command> i.e. "git pull"
alias brccustom='BRAZIL_VERBOSE=true brazil-recursive-cmd --allPackages'
# brazil-runtime-exec
alias bre='brazil-runtime-exec'
# brazil-test-exec
alias bte='brazil-test-exec'
# brazil ws
alias bws='brazil ws'
# brazil ws use --package
alias bwsuse='brazil ws use --package'
# brazil ws create --root
alias bwscreate='brazil ws create --root'
# brazil vs removemajorversions -vs
alias bvsclean='brazil vs removemajorversions --versionSet'
# -------
# RIP CLI
# -------
# Find AWS region info
alias freg='ripcli regions | command grep -F -i'
# ---------------
# Tmux Management
# ---------------
# tmux
alias tm='tmux'
# Attach to a tmux session
alias tma='tm attach-session'
# Attach to a tmux session with name
alias tman='tma -t'
# List tmux sessions
alias tmls='tm list-sessions'
# Start a new tmux session
alias tms='tm new-session'
# Start a new tmux session with name
alias tmsn='tms -s'
# ---------
# Scripting
# ---------
# shfmt - a shell parser, formatter, and interpreter
# check format
alias shfmtc='shfmt -d -i 4 -bn -kp ./'
# run formatter
alias shfmtf='shfmt -l -i 4 -bn -kp -w ./'
# -------------
# Date and Time
# -------------
# Preferred now format
alias now='date "+%a, %b %d %Y %T %Z, WeekNum %V"'
# Epoch time
alias timestamp='date +%s'
# Calendar for 3 months
alias cal3='cal -3'
if [[ $(uname -s) == "Darwin" ]]; then
# Days left in year (macOS)
alias daysleft='echo -e "There are $(($(date -jf "%b %d %Y" "Dec 31 $(date +%Y)" +%j) - $(date +%j))) days left in year $(date +%Y)."'
else
# Days left in year (Linux)
alias daysleft='echo -e "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) days left in year $(date +%Y)."'
fi
# ---------
# FUNCTIONS
# ---------
function yazi_cd_into_dir() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="${tmp}"
if cwd="$(command cat -- "${tmp}")" && [ -n "${cwd}" ] && [ "${cwd}" != "${PWD}" ]; then
builtin cd -- "${cwd}"
fi
rm -f -- "${tmp}"
}