dotfiles/home/.config/shell/aliases

303 lines
13 KiB
Plaintext
Raw Normal View History

2021-01-28 22:47:04 +00:00
#!/usr/bin/env zsh
2020-10-22 16:00:38 +00:00
2021-01-14 12:38:43 +00:00
# I'm not the greatest typist
alias sl='ls'
alias mdkir='mkdir'
alias soruce='source'
alias souce='source'
2021-02-16 13:33:48 +00:00
alias suod='sudo '
2021-05-01 19:41:02 +00:00
alias sduo='sudo '
2020-10-22 16:00:38 +00:00
2021-11-14 19:58:43 +00:00
# Replacements (adding flags)
alias cp='cp -iv' # Ask before overwriting, verbose
alias mv='mv -iv' # Ask before overwriting, verbose
alias rm='trash-put' # Use trash-cli instead of true removal
alias rmr='\rm -v' # True rm, verbose (asking here is too annoying)
alias wget='wget -c' # Resume wget by default
alias df='df -H' # Show sizes as powers of 1000
2021-05-10 17:03:18 +00:00
# Directory changing
2020-10-22 16:00:38 +00:00
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias .2='cd ../../'
alias .3='cd ../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../../'
2021-05-10 17:03:18 +00:00
# Files/Directories utilities
2021-04-01 20:25:38 +00:00
alias mkdir='mkdir -p'
2021-02-16 13:33:48 +00:00
alias md='mkdir'
2021-05-10 17:03:18 +00:00
alias fhere='find . -name'
2021-11-14 19:58:43 +00:00
alias rr='rmr -r'
alias rf='rmr -f'
alias rrf='rmr -rf'
alias vimdiff='nvim -d'
2021-01-23 19:31:00 +00:00
2021-04-19 17:27:12 +00:00
# Directory listing aliases, defaults to exa, if aviable
if command -v exa > /dev/null; then
alias ls='exa'
alias l='exa -glah --classify'
alias ll='exa -glah --classify -s=size --group-directories-first -r'
alias ldir='exa -glahD'
2021-04-19 17:27:12 +00:00
alias tree='exa -Tlagh'
2021-05-10 17:03:18 +00:00
alias dotall='exa -hulad .[a-z]*' # Show both dotdirs and dotfiles
alias dotfiles='dotall | grep -v ^d' # Show all dotfiles
alias dotdirs='dotall | grep --color=never ^d' # Show all dotdirs
2021-04-19 17:27:12 +00:00
else
alias ls='ls --color=auto'
alias l='ls -lahX --classify'
alias ll='ls -lahX --classify --group-directories-first'
alias ldir='ls -lahX --classify | grep --color=never ^d'
2021-05-10 17:03:18 +00:00
alias dotall='ls -lahXd .[a-z]*'
alias dotfiles='dotall | grep -v ^d'
alias dotdirs='dotall | grep --color=never ^d'
2021-04-19 17:27:12 +00:00
fi
2021-01-23 19:31:00 +00:00
2020-10-22 16:00:38 +00:00
# Config access shortcuts
alias cfzsh='vim ~/.config/zsh/.zshrc'
alias cfalias='vim ~/.config/shell/aliases'
alias cffunctions='vim ~/.config/shell/functions'
alias cfprofile='vim ~/.config/shell/profile'
alias cfenvironment='vim ~/.config/shell/environment'
alias cfenv='cfenvironment'
alias cfhandlers='vim ~/.config/shell/handlers'
alias cfprompt='vim ~/.config/shell/prompt'
alias cfkeybinds='vim ~/.config/shell/keybinds'
2021-08-19 21:26:06 +00:00
alias cfxprofile='vim ~/.config/x11/xprofile'
2021-07-19 23:35:11 +00:00
alias cfxmonad='vim ~/.config/xmonad/xmonad.hs && xmonad --recompile && xmonad --restart'
2021-07-14 13:34:45 +00:00
alias cfxmobar='vim ~/.config/xmobar/xmobarrc.hs && ~/.config/xmobar/multi_mon.sh 2'
2021-11-14 19:57:43 +00:00
alias cftodo='vim ~/Personal/vimwiki/todo.md'
2021-12-18 02:02:26 +00:00
alias cfnvim='vim ~/.config/nvim'
alias cfvim='cfnvim'
2020-10-22 16:00:38 +00:00
2021-11-14 19:58:43 +00:00
# z.lua shortcuts
alias j='z' # for the sake of autojump old habits
alias zz='z -c' # restrict matches to subdirs of $PWD
alias zb='z -b' # restrict matches to parent directories
alias zi='z -I' # cd with interactive fzf selection
alias zbi='z -b -I' # pick parent directory to cd into with fzf
2021-04-01 20:14:40 +00:00
# Python
alias ipy='ipython'
alias bpy='bpython'
2021-05-01 19:41:02 +00:00
command -v ipython > /dev/null && alias py='ipython' || alias py='python'
2021-12-18 02:10:16 +00:00
for version in 2 3 3.6 3.7 3.8 3.9 3.10; do # Make aliases for py3.6,py3.7,...
if ! command -v "python$version" > /dev/null; then
continue
fi
if command -v "ipython$version" > /dev/null; then
alias "py$version"="ipython$version"
alias "ipy$version"="ipython$version"
alias "ppy$version"="python$version"
else
alias "py$version"="python$version"
alias "ppy$version"="python$version"
fi
done
2021-04-01 20:14:40 +00:00
2021-01-14 12:38:43 +00:00
# Fallbacks
2021-05-10 17:03:18 +00:00
command -v hd > /dev/null || alias hd='hexdump -C' # Cannonical hex dump; some systems have this symlinked
command -v md5sum > /dev/null || alias md5sum='md5' # Fallback from `md5sum` to `md5`
command -v sha1sum > /dev/null || alias sha1sum='shasum' # Fallback from `sha1sum` to `shasum`
command -v vim > /dev/null && alias vi='vim' # Let vim take precedence over vi
command -v nvim > /dev/null && alias vi='nvim' && alias vim='nvim' # Let nvim take precedence over vi/vim
2021-12-18 02:02:39 +00:00
command -v vimtutor > /dev/null || alias vimtutor='nvim -c Tutor' # Let vimtutor fallback to nvim's tutor
2021-01-14 12:38:43 +00:00
2021-01-23 19:31:00 +00:00
# X11 clipboard (either using xclip or xsel, xsel takes precedence if both)
command -v xclip > /dev/null && alias pbcopy='xclip -selection clipboard'
command -v xclip > /dev/null && alias pbpaste='xclip -selection clipboard -o'
command -v xsel > /dev/null && alias pbcopy='xsel --clipboard --input'
command -v xsel > /dev/null && alias pbpaste='xsel --clipboard --output'
2021-06-05 01:15:23 +00:00
# File validation and manipulation
2021-04-01 20:14:40 +00:00
alias yamlcheck='python -c "import sys, yaml as y; y.safe_load(open(sys.argv[1]))"' # Validate YAML
alias jsoncheck='jq "." >/dev/null <' # Validate JSON
alias urlencode='python2 -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' # Encode strings as URLs (space->%20, etc.)
2021-06-05 01:15:23 +00:00
alias mergepdf='gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf' # Usage: `mergepdf input{1,2,3}.pdf``
alias encrypt='gpg -c --no-symkey-cache --cipher-algo AES256' # Encrypt file with AES256 symetric encryption
alias decrypt='gpg' # For the sake of completeness, include decrypt command to the above, though it's only just gpg alias
2021-04-01 20:14:40 +00:00
# Terminal window swallowing for blocking programs (devour)
alias xdg-open='devour xdg-open'
alias mpv='devour mpv'
alias nomacs='devour nomacs'
alias pcmanfm='devour pcmanfm'
alias spotify='devour spotify'
2021-01-14 12:38:43 +00:00
# Regular expressions
2021-01-23 19:31:00 +00:00
alias reg_email='echo "[a-Z0-9._%-]+@[a-Z0-9.-]+\.[a-Z]{2,10}"'
2021-01-14 12:38:43 +00:00
alias reg_mac='echo "([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'
alias reg_ipv4='echo "([0-9]{1,3}\.){3}[0-9]{1,3}"'
alias reg_ipv6='echo "\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*"' # Also catches loopbacks (::1), (for valid matching, it needs to be this long...)
alias reg_ip='echo "(`reg_ipv4`|`reg_ipv6`)"' # Match both IPv4 and IPv6
2021-04-01 20:25:38 +00:00
# Grep aliases
2021-01-14 12:38:43 +00:00
alias grep_email='grep -E `reg_email`'
alias grep_ip='grep -E `reg_ip`'
alias grep_mac='grep -E `reg_mac`'
2021-04-19 17:27:12 +00:00
alias massgrep='grep -RHIni'
2021-01-14 12:38:43 +00:00
# Network
2021-10-22 11:19:20 +00:00
alias ip-show='curl https://ifconfig.co' # Get global IP address
2021-01-14 12:38:43 +00:00
alias ips="ifconfig -a | grep -oE \"inet6? (addr:)?s?\`reg_ip\`\" | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
2021-02-16 13:33:48 +00:00
alias lan-device-scan='nmap -T5 -sP 192.168.0.0-255'
alias lan-vuln-scan='nmap -sT -O --script vuln 192.168.0.0-255'
2021-01-14 12:38:43 +00:00
alias ports='netstat -tulanp'
alias listening-ports='netstat -vtlnp --listening'
alias ssh-list='ss | grep ssh' # List all SSH connections
alias serve='python -m http.server' # Serve current directorty as HTTP
2021-01-28 22:47:04 +00:00
alias reverse-dns='host' # It might be easier to just use `host` though
alias torify='source torsocks on' # Pass every command via torsocks
alias untorify='source torsocks off' # Stop passing commands via torsocks
2020-10-22 16:00:38 +00:00
2021-04-01 20:14:40 +00:00
# Firewall aliases (IPTables/UFW)
alias ipt='iptables' # Shortcut
alias iptlist='iptables -L -n -v --line-numbers' # All rules
alias iptlistin='iptables -L INPUT -n -v --line-numbers' # IN rules
alias iptlistout='iptables -L OUTPUT -n -v --line-numbers' # OUT rules
alias iptlistfw='iptables -L FORWARD -n -v --line-numbers' # FORWARD rules
2021-05-10 17:03:18 +00:00
alias ufw-log='journalctl -f -n 100 -g ufw' # Show UFW log entries in system journal
2021-04-01 20:14:40 +00:00
2021-07-20 21:19:46 +00:00
# Kernel actions
alias kernel-recompile='cd /usr/src/linux && make -j7 && make -j7 modules_install && make install'
alias kernel-oldconfig='cd /usr/src/linux && make oldconfig'
alias kernel-configure='cd /usr/src/linux && make menuconfig'
2021-05-10 17:03:18 +00:00
# System actions
alias sv='systemctl'
alias backup="rsync -avHAXS --delete --filter='dir-merge /.rsync-filter'" # Make full rsync backup, respecting .rsync-filter files for exclusions
alias upload='curl -F "f:1=<-" ix.io'
alias upload-journal='sudo journalctl -b -1 | upload' # Upload journalctl from last boot to ix.io
2021-12-03 13:49:02 +00:00
alias auth-log='journalctl SYSLOG_FACILITY=10 -r'
2021-05-10 17:03:18 +00:00
alias cpu-stress='for i in $(seq $(getconf _NPROCESSORS_ONLN)); do yes > /dev/null & done' # Run `yes > /dev/null` on all cores as stress test
alias nvidia='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia' # Run app with nvidia (on hybrid mode with optimus)
alias swapout='sudo swapoff -a; sudo swapon -a' # Reset swap (move everything to RAM)
alias mount-ram='mount -t tmpfs tmpfs' # Mount RAM disk for fast filesystem
2021-08-19 21:26:06 +00:00
alias screenlock='xset s activate' # Use DPMS to trigger xss-lock and handle screen locking
2021-05-10 17:03:18 +00:00
# System info
2021-01-14 12:38:43 +00:00
alias meminfo='free -m -l -t'
alias cpuinfo='lscpu'
alias batinfo='sudo watch -d -n 2 tlp-stat -b'
2021-07-19 23:35:11 +00:00
alias battery='cat /sys/class/power_supply/BAT0/capacity'
2021-01-14 12:38:43 +00:00
alias gpumeminfo='frep -i --color memory /var/log/Xorg.0.log'
2021-05-10 17:03:18 +00:00
alias journalerr='sudo journalctl -p 3 -xb'
alias distro='cat /etc/*-release'
2021-04-01 20:14:40 +00:00
alias diskspace_report="df -P -kHl"
2021-05-10 17:03:18 +00:00
alias kernel='uname -r'
2021-01-14 12:38:43 +00:00
2021-05-10 17:03:18 +00:00
# System processes
2021-01-14 12:38:43 +00:00
alias psmem='ps auxf | sort -nr -k 4' # Top memory eaters
2021-05-10 17:03:18 +00:00
alias psmem10='psmem | head -10' # Top 10 memory eaters
2021-01-14 12:38:43 +00:00
alias pscpu='ps auxf | sort -nr -k 3' # Top cpu eaters
2021-05-10 17:03:18 +00:00
alias pscpu10='pscpu | head -10' # Top 10 cpu eaters
2021-01-14 12:38:43 +00:00
alias psg='ps aux | grep -v grep | grep -i -e VSZ -e' # Get searchable process with nice output
# Time info
alias now='date +"%T"'
2021-01-23 19:31:00 +00:00
alias nowtime='now'
2021-01-14 12:38:43 +00:00
alias nowdate='date +"%d-%m-%Y"'
alias week='date +%V'
2021-01-28 22:47:04 +00:00
# Cleanup
2021-04-01 20:14:40 +00:00
alias clean-trash='rm -rf ~/.local/share/Trash/* || echo "Trash already empty"'
alias clean-downloads='rm -rf ~/Downloads/* || echo "Downloads directory is already empty"'
2021-01-28 22:47:04 +00:00
alias clean-journal='journalctl --vacuum-size=200M || echo "You have to be root to clean journal"'
alias clean-pacman='pacman -Sc || echo "You have to be root to clean pacman cache"'
alias cleanup='clean-trash && clean-down && clean-journal && clean-pacman'
2021-01-14 12:38:43 +00:00
# Git aliases
alias g='git'
2021-12-01 18:58:56 +00:00
alias gp='git push'
alias gpl='git pull'
alias gf='git fetch'
alias gs='git status --short --branch'
alias gss='git status'
2021-01-14 12:38:43 +00:00
alias ga='git add'
2021-12-01 18:58:56 +00:00
alias gap='git add --patch'
2021-05-10 17:03:18 +00:00
alias gc='git commit'
2021-12-01 18:58:56 +00:00
alias gcm='git commit --message'
alias gb='git branch'
alias gch='git checkout'
alias gchb='git checkout --branch'
alias gd='git diff'
alias gdc='git diff --cached'
alias gundo='git reset --soft HEAD~'
2021-01-14 12:38:43 +00:00
alias gredo="git reset 'HEAD@{1}'"
2021-04-01 20:14:40 +00:00
2021-05-10 17:03:18 +00:00
# Youtube-dl aliases
alias ytv-best='youtube-dl -f bestvideo+bestaudio'
alias yta-best='youtube-dl --extract-audio --audio-format best'
alias yta-mp3='youtube-dl --extract-audio --audio-format mp3'
alias yta-wav='youtube-dl --extract-audio --audio-format wav'
2021-04-01 20:14:40 +00:00
2021-11-14 19:54:54 +00:00
# Terminal vim-like exits, in case I think the terminal is vim
alias :q='exit'
alias :q!='exit'
alias :wq='exit'
alias :wq!='exit'
2021-04-01 20:25:38 +00:00
# Shell aliases
alias reload="exec \$SHELL" # Reload the shell (i.e. invoke as a login shell)
2021-01-14 12:38:43 +00:00
alias path='echo -e ${PATH//:/\\n}' # Print each PATH entry on a separate line
2021-04-01 20:25:38 +00:00
alias unsudo='sudo -k' # Reset sudo timeout (sudo will require password)
2021-08-15 22:37:04 +00:00
alias vimwiki='vim -c VimwikiIndex' # Open vimwiki index
2020-10-22 16:00:38 +00:00
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
2021-05-10 17:03:18 +00:00
alias tty-clock='tty-clock -Ssc' # Terminal clock screensaver
alias rick='curl -s -L https://raw.githubusercontent.com/ItsDrike/rickrollrc/master/roll.sh| bash' # Terminal rickroll
2020-10-22 16:00:38 +00:00
2021-06-05 01:15:23 +00:00
# If user is not root, pass all commands via sudo/doas
2020-10-22 16:00:38 +00:00
if [ $UID -ne 0 ]; then
2021-06-05 01:15:23 +00:00
# Enable aliases to be sudoed/doased
# with doas having precedence over sudo if found
2020-10-22 16:00:38 +00:00
## Uncomment if you are using autocompletion (is ZSH)
2021-06-05 01:15:23 +00:00
#command -v /usr/bin/sudo > /dev/null && alias doas='nocorrect sudo ' && alias sudo='nocorrect sudo '
#command -v /usr/bin/doas > /dev/null && alias doas='nocorrect doas ' && alias sudo='nocorrect doas '
2021-04-01 20:14:40 +00:00
## if the above is uncommented, comment this
2021-06-05 01:15:23 +00:00
command -v /usr/bin/sudo > /dev/null && alias doas='sudo ' && alias sudo='sudo '
command -v /usr/bin/doas > /dev/null && alias doas='doas ' && alias sudo='doas '
2020-10-22 16:00:38 +00:00
fi
2021-01-14 12:38:43 +00:00
# enable color support
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
2021-03-23 20:19:01 +00:00
alias cgrep='grep --color=always'
2021-01-14 12:38:43 +00:00
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
2021-03-23 20:19:01 +00:00
alias diff='diff --color=auto'
alias ip='ip --color=auto'
# Take advantage of $LS_COLORS for completion as well
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
2021-01-14 12:38:43 +00:00
fi
2020-10-22 16:00:38 +00:00
# Normalize `open` across Linux, macOS, and Windows.
# This is needed to make `open` function (see below) cross-platform
if [ ! $(uname -s) = 'Darwin' ]; then
if grep -q Microsoft /proc/version; then
# Ubuntu on Windows using the Linux subsystem
alias open='explorer.exe'
else
alias open='xdg-open'
fi
fi
# Functions
2021-07-19 23:35:11 +00:00
if [ -f ~/.config/shell/functions ]; then
source ~/.config/shell/functions
2020-10-22 16:00:38 +00:00
fi
# Extra
2021-07-19 23:35:11 +00:00
if [ -f ~/.config/shell/extra ]; then
source ~/.config/shell/extra
2020-10-22 16:00:38 +00:00
fi