-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.aliases
More file actions
172 lines (144 loc) · 7.2 KB
/
Copy path.aliases
File metadata and controls
172 lines (144 loc) · 7.2 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
#-----------------------------------------------------------------------
# File: ~/.aliases
# Description: Bash/Zsh aliases — dirs, listings, grep, IPs, trash, DNS (cross-platform: Linux + macOS)
# Compatibility: Debian, Ubuntu, Armbian, macOS
# Version: 0.4.2
# Author: Aamnah
# Link: https://aamnah.com
# Date: 2020-07-15
# Lastmod: 2026-05-05
#-----------------------------------------------------------------------
# Cross-platform (sourced in .bash_profile and .zshrc)
# More ideas: http://alias.sh/ and http://www.commandlinefu.com/commands/
# OS detection
# ---------------------------------------------------------------
# set once, used by aliases that differ between Linux (GNU) and macOS (BSD).
# Skip the ~1-5ms uname subprocess if .zshenv (or another caller) already set the flags.
# "$IS_MACOS$IS_LINUX" is a concatenated string, will result in 1 if either one is present
# on Linux only IS_LINUX is set, on macOS only IS_MACOS is set
if [[ -z "$IS_MACOS$IS_LINUX" ]]; then
case "$(uname -s)" in
Darwin) IS_MACOS=1 ;;
Linux) IS_LINUX=1 ;;
esac
fi
## DIRs (HOME-relative — work on any box)
# ---------------------------------------------------------------
alias desk="cd $HOME/Desktop"
alias dl="cd $HOME/Downloads"
# COMMANDS
# ---------------------------------------------------------------
# -a for all (including hidden and .files)
# -l for detailed
# -h for human readable, print sizes like 1K 234M 2.3G etc.
# -A List all entries except for . and ... Always set for the super-user.
# -F Display indicators. a slash (`/') immediately after each pathname that is a directory,
# an asterisk (`*') after each that is executable, an at sign (`@') after
# each symbolic link, an equals sign (`=') after each socket, a percent sign
# (`%') after each whiteout, and a vertical bar (`|') after each that is a FIFO.
# Colorized output for ls colorflag differs: GNU (Ubuntu) uses --color=, BSD (macOS) uses -G
# -x for line based listing instead of columns. the multi-column output is produced with entries sorted across, rather than down, the columns
if [[ -n "$IS_MACOS" ]]; then
alias ls='ls -hFG' # BSD `-G` is auto-only by design
alias ll='ls -alhFG'
alias l='ls -aFxG'
else
alias ls='ls -hF --color=auto'
alias ll='ls -alhF --color=auto'
alias l='ls -aFx --color=auto'
fi
alias la='ls -A'
# Only list directories (including hidden, excluding . and ..)
# Cross-platform: portable across BSD/GNU
alias lsd='ls -dl */ .[^.]*/ 2>/dev/null'
# Use --color=auto, NOT =always: `always` injects ANSI escapes even when piped,
# breaking `grep foo file | awk ...`, `grep foo | wc`, etc. `auto` only colors a TTY.
alias grep='grep --color=auto'
alias egrep='grep -E --color=auto'
alias fgrep='grep -F --color=auto'
# tree colorizes by default when stdout is a TTY — no alias needed for the common case.
# If you want forced color through a pager: `tree -C | less -R`
# Tools (universal — work on any box where the tool is installed)
alias cc="claude"
alias kkk="tmux kill-session"
alias peaclock="peaclock --config-dir ~/.config/peaclock"
# Copy over Kitty's terminfo when using SSH
# https://wiki.archlinux.org/title/Kitty#Terminal_issues_with_SSH
[ "$TERM" = "xterm-kitty" ] && alias ssh="kitty +kitten ssh"
# MISC.
# ---------------------------------------------------------------
## IP addresses
alias myip='curl ifconfig.me'
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
# localip differs: macOS uses `ipconfig getifaddr`; Linux uses `hostname -I`
if [[ -n "$IS_MACOS" ]]; then
alias localip='ipconfig getifaddr en0'
else
alias localip="hostname -I | awk '{print \$1}'"
fi
## Empty the Trash
# macOS: trash lives in /Volumes/*/.Trashes (per-mount) and ~/.Trash
# Linux: XDG trash spec is ~/.local/share/Trash/{files,info}
if [[ -n "$IS_MACOS" ]]; then
alias emptytrash='sudo rm -rfv /Volumes/*/.Trashes; rm -rfv ~/.Trash'
else
alias emptytrash='rm -rfv ~/.local/share/Trash/files/* ~/.local/share/Trash/info/* 2>/dev/null'
fi
## Recursively delete `.DS_Store` files (macOS leftovers, harmless on Linux)
alias cleanup="find . -type f -name '*.DS_Store' -ls -delete"
## Kill Chrome renderer tabs to free up memory (preserves extensions)
# Cross-platform: matches both "Chrome Helper --type=renderer" (macOS)
# and "chrome --type=renderer" (Linux). Uses [Cc] bracket trick so grep
# doesn't match itself in the ps output.
alias chromekill="ps ux | grep -E '[Cc]hrome( Helper)? --type=renderer' | grep -v extension-process | awk '{print \$2}' | xargs kill 2>/dev/null"
## Lock the screen (when going AFK)
if [[ -n "$IS_MACOS" ]]; then
alias afk='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
else
# Try systemd's loginctl first, then xdg-screensaver. Keyboard shortcut on most desktops is Super+L.
alias afk='loginctl lock-session 2>/dev/null || xdg-screensaver lock'
fi
## Reload the shell (i.e. invoke as a login shell)
# Single quotes so $SHELL resolves at run time, not when the alias is defined.
alias reload='exec $SHELL -l'
# SUDO
# $ZSH_VERSION & $BASH_VERSION are set by the shell itself at startup
# and aren't exported, so they don't leak between shells
# If .aliases is sourced from .zshrc, only $ZSH_VERSION is defined.
# And if .aliases is sourced from .bash_profile, then only $BASH_VERSION is defined
if [[ -n "$ZSH_VERSION" ]]; then
alias dang='sudo $(fc -ln -1)'
elif [[ -n "$BASH_VERSION" ]]; then
alias dang='sudo $(history -p \!\!)'
fi
## DISK USAGE
# ---------------------------------------------------------------
# List top ten largest files/directories in current directory
# alias ducks='du -cks *|sort -rn|head -11'
# du -cks : -c for grand total , -k for 1-Kbyte blocks, -s for displaying entries for each file
# sort -rn : -r for reverse order, -n for numeric sort
# head -11 : display first 11 lines
# NOTE: `sort -h` (human-numeric) is GNU-only on older macOS. Modern macOS (Mojave+)
# supports it. On older macOS, `brew install coreutils` and use `gsort -rh` instead.
alias ducks='du -chs * | sort -rh | head -11' # human-readable
# Find the biggest in a folder
alias ds='du -ks * | sort -n'
## MEMORY
# ---------------------------------------------------------------
# What's gobbling the memory? (cross-platform: BSD and GNU ps both accept these column names)
alias wotgobblemem='ps -o time,ppid,pid,nice,pcpu,pmem,user,comm -A | sort -n -k 6 | tail -15'
## DNS
# ---------------------------------------------------------------
# Flush DNS cache
if [[ -n "$IS_MACOS" ]]; then
# On modern macOS, flushing requires both dscacheutil and an mDNSResponder reload
alias flushdns='sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder'
else
# systemd-resolved is the modern default; resolvectl is the current command, systemd-resolve is the older one
alias flushdns='sudo resolvectl flush-caches 2>/dev/null || sudo systemd-resolve --flush-caches 2>/dev/null || echo "no known resolver to flush — check your distro"'
fi
## SECURITY
# ---------------------------------------------------------------
# Show active network listeners (cross-platform: lsof works on both)
alias netlisteners='lsof -i -P | grep LISTEN'
# spy() and sniff() have been added to .bash_functions