dotfiles/home/.config/sh/aliases

233 lines
10 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 '
2020-10-22 16:00:38 +00:00
2021-02-16 13:33:48 +00:00
# Directories
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-02-16 13:33:48 +00:00
alias mkdir='mkdir -p' # Mkdir with automatic creation of parent directories
2020-10-22 16:00:38 +00:00
2021-01-23 19:31:00 +00:00
# Shortcuts
alias rr='rm -r'
alias sv='systemctl'
2021-02-16 13:33:48 +00:00
alias md='mkdir'
alias massgrep='grep -rni'
2021-01-23 19:31:00 +00:00
# Aliases for piping directly (f.e.: history G ssh)
alias -g G='| grep'
alias -g H='| head'
2020-10-22 16:00:38 +00:00
# Python
alias py3='python3'
alias py2='python2'
alias py='ipython'
alias ipy='ipython'
alias bpy='bpython'
2021-01-23 19:31:00 +00:00
# Exa aliases (replacement for ls, if you are using ls, comment or change this
alias ls='exa'
alias l='exa -glah'
alias ll='exa -glah --classify -s=size --group-directories-first -r'
alias ld='exa -glahD'
alias tree='exa -Tlagh'
alias dotfiles='exa -hula -d .[a-z]* | grep -v ^d' # Show all dotfiles
alias dotdirs='exa -hulaD -d .[a-z]*' # Show all dotdirs
alias dotall='exa -hula -d .[a-z]*' # Show both dotdirs and dotfiles
2020-10-22 16:00:38 +00:00
# Config access shortcuts
alias cfzshrc='vim ~/.zshrc'
alias cfvim='vim ~/.config/vim/vimrc'
alias cfalias='vim ~/.config/sh/aliases'
2021-01-14 12:38:43 +00:00
alias cffunctions='vim ~/.config/sh/functions'
alias cfenviron='vim ~/.config/sh/environ'
2021-02-16 13:33:48 +00:00
alias cfxdg='cfenviron'
2021-01-14 12:38:43 +00:00
alias cfhandlers='vim ~/.config/sh/handlers'
2021-02-16 13:33:48 +00:00
alias cftheme='vim ~/.config/sh/theme'
alias cfprompt='cftheme'
alias cfkeybinds='vim ~/.config/sh/keybinds'
2020-10-22 16:00:38 +00:00
# Replacements
2021-01-14 12:38:43 +00:00
alias wget='wget -c' # Resume wget by default
2020-10-22 16:00:38 +00:00
alias du='du -ach | sort -h' # Sort du by size
2021-01-14 12:38:43 +00:00
alias df='df -H' # Show sizes as powers of 1000
2020-10-22 16:00:38 +00:00
alias tty-clock='tty-clock -Ssc' # Terminal clock screensaver
2021-01-14 12:38:43 +00:00
alias vi='vim' # Nobody uses `vi` anymore, go directly to `vim`
# Fallbacks
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`
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-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
alias grep_email='grep -E `reg_email`'
alias grep_ip='grep -E `reg_ip`'
alias grep_mac='grep -E `reg_mac`'
# Validate things
alias yamlcheck='python -c "import sys, yaml as y; y.safe_load(open(sys.argv[1]))"'
alias jsoncheck='jq "." >/dev/null <'
2021-02-16 13:33:48 +00:00
# Firewall aliases (IPTables/UFW)
command -v ufw > /dev/null && alias firewall='ufw' || alias firewall='iptables'
2021-01-28 22:47:04 +00:00
command -v ufw > /dev/null && alias ufw-log='journalctl -f -n 100 -g ufw' # Show UFW log entries in system journal
2021-02-16 13:33:48 +00:00
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-01-28 22:47:04 +00:00
2021-01-14 12:38:43 +00:00
# Network
alias ip-show='curl https://ipinfo.io/ip' # Show public IP address
alias ip-info='curl https://ipinfo.io/json' # Show public IP info (IP,region,country,timezone,...)
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
alias serve-public='python -m http.server --bind 192.168.0.102' # Serve publically
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-01-14 12:38:43 +00:00
# System info
alias meminfo='free -m -l -t'
alias cpuinfo='lscpu'
alias batinfo='sudo watch -d -n 2 tlp-stat -b'
alias gpumeminfo='frep -i --color memory /var/log/Xorg.0.log'
alias distro="cat /etc/*-release"
# Processes
alias psmem='ps auxf | sort -nr -k 4' # Top memory eaters
alias pscpu='ps auxf | sort -nr -k 3' # Top cpu eaters
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
alias clean-trash='\rm -rf ~/.local/share/Trash/* || echo "Trash already empty"'
alias clean-down='\rm -rf ~/Downloads/* || echo "Downloads directory is already empty"'
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'
alias gs='git status'
alias gc='git commit'
alias gcm='git commit -m'
alias ga='git add'
alias gaa='git add all'
alias gb='git branch'
2021-02-16 13:33:48 +00:00
alias gch='git checkout'
alias gchb='git checkout -b'
2021-01-14 12:38:43 +00:00
alias gcda='git diff --cached' # Diff any files staged for commit
alias gf='git fetch'
alias gm='git merge'
alias gp='git push'
alias glog='git log --oneline --decorate --graph'
alias gundo='git reset HEAD~'
alias gredo="git reset 'HEAD@{1}'"
alias undopush="git push -f origin HEAD^:master"
# Other headless aliases
2020-10-22 16:00:38 +00:00
alias reload="exec \$SHELL" # Reload the shell (i.e. invoke as a login shell
2021-01-23 19:31:00 +00:00
alias vuln='arch-audit' # Show vulnerable packages that can be upgraded (Arch Linux)
2021-01-28 22:47:04 +00:00
alias vuln-upgrade="pacman -Sy \"\$(arch-audit --upgradable --quiet | awk '{sub(/>=.+/, \"\"); print}' | paste -s -d ' ')\"" # Upgrade all vulnerable packages, with released fixes
2021-01-14 12:38:43 +00:00
alias path='echo -e ${PATH//:/\\n}' # Print each PATH entry on a separate line
2020-10-22 16:00:38 +00:00
alias fhere='find . -name' # Find file/dir from currrent dir
alias swapout='sudo swapoff -a; sudo swapon -a' # Reset swap (move everything to RAM)
2021-01-14 12:38:43 +00:00
alias diskspace_report="df -P -kHl"
2020-10-22 16:00:38 +00:00
alias mount-table='df' # Show list of all mounted devices and their mount locations
alias pacman-extract='pacman -Syw --cachedir .' # Extract package/es into current floders
2021-01-14 12:38:43 +00:00
alias mount-ram='mount -t tmpfs tmpfs' # Mount RAM disk for fast filesystem
alias ubu-key='gpg --keyserver keyserver.ubuntu.com --recv-key'
alias colors-256='curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash' # Show color table
alias urlencode='python2 -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' # Encode strings as URLs (space->%20, etc.)
alias mergepdf='gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf' # Usage: `mergepdf input{1,2,3}.pdf`
alias create_mirror_list='reflector --country Slovakia --country Czechia --country Poland --country Hungary --country Ukraine --country Germany --country US --latest 800 --protocol https --sort rate --save mirrorlist'
alias cpu-stress='fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd'
2021-01-28 22:47:04 +00:00
alias metasploit='msfconsole'
2020-10-22 16:00:38 +00:00
2021-01-14 12:38:43 +00:00
# Graphical custom aliases
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$//'\'')"'
alias nvidia='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia' # Run app with nvidia (on hybrid mode with optimus)
alias sound_control='alsamixer' # Sound control tool in alsa_utils package
2021-01-14 12:38:43 +00:00
alias firefox='GTK_USE_PORTAL=1 firefox'
2020-10-22 16:00:38 +00:00
alias pdf-reader='mupdf' # Open pdf file
alias md-to-pdf='pandoc -s -o' # Convert markdown to pdf
# If user is not root, pass all commands via sudo
if [ $UID -ne 0 ]; then
# Enable aliases to be sudoed
## Uncomment if you are using autocompletion (is ZSH)
#alias sudo='nocorrect sudo'
## Comment this if you are not using autocompletion (in ZSH)
alias sudo='sudo '
alias unsudo='sudo -k' # Reset sudo timeout (sudo will require password)
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'
alias cgrep='grep --color=always'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
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
if [ -f ~/.config/sh/functions ]; then
source ~/.config/sh/functions
fi
# Extra
if [ -f ~/.config/sh/extra ]; then
source ~/.config/sh/extra
fi