mirror of
https://github.com/ItsDrike/nixdots
synced 2024-12-28 04:14:34 +00:00
261 lines
12 KiB
Bash
261 lines
12 KiB
Bash
# This file contains all of my custom alias definitions
|
|
# I haven't yet finished moving all of these to nix config, so the rest
|
|
# still live in this file. Aliases that were defined in aliases.nix will
|
|
# be removed from this file.
|
|
|
|
# Replacements (adding flags)
|
|
alias cp='cp -iv' # Ask before overwriting, verbose
|
|
alias mv='mv -iv' # Ask before overwriting, verbose
|
|
alias rmt='trash-put' # Use trash-cli instead of true removal
|
|
alias rm='rm -v' # Verbose rm (asking before deleting is too annoying here)
|
|
alias rmr='rm -r'
|
|
alias rmrf='rm -rf'
|
|
alias wget='wget -c' # Resume wget by default
|
|
alias df='df -H' # Show sizes as powers of 1000
|
|
|
|
# Files/Directories utilities
|
|
alias mkdir='mkdir -p'
|
|
alias md='mkdir'
|
|
alias fhere='find . -name'
|
|
alias rr='rmr -r'
|
|
alias rf='rmr -f'
|
|
alias rrf='rmr -rf'
|
|
alias vimdiff='nvim -d'
|
|
|
|
# Use eza instead of ls, if it's available
|
|
# (the default aliases that use ls are set in aliases.nix)
|
|
if command -v eza > /dev/null; then
|
|
alias ls='eza'
|
|
alias l='eza -glah --classify'
|
|
alias ll='eza -glah --classify -s=size --group-directories-first -r'
|
|
alias ldir='eza -glahD'
|
|
alias tree='eza -Tlagh'
|
|
alias dotall='eza -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
|
|
fi
|
|
|
|
# Config access shortcuts
|
|
# (probably useless in nixos)
|
|
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'
|
|
alias cftodo='vim ~/Personal/vimwiki/todo.md'
|
|
alias cfnvim='vim ~/.config/nvim'
|
|
alias cfvim='cfnvim'
|
|
alias cfgit='vim ~/.config/git/config'
|
|
alias cfhypr='vim ~/.config/hypr'
|
|
alias cfsway='vim ~/.config/sway/config'
|
|
|
|
# zoxide shortcuts
|
|
alias j='z' # for the sake of old habits from autojump
|
|
alias ji='zi' # interactive mode (fzf)
|
|
|
|
# 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`
|
|
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
|
|
command -v vimtutor > /dev/null || alias vimtutor='nvim -c Tutor' # Let vimtutor fallback to nvim's tutor
|
|
|
|
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
|
|
# Wayland clipboard
|
|
alias pbcopy="wl-copy"
|
|
alias pbpaste="wl-paste"
|
|
else
|
|
# 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'
|
|
fi
|
|
|
|
# Regular expressions
|
|
# (I know this is a *little* insane, but it's useful...)
|
|
alias reg_email='echo "[a-Z0-9._%-]+@[a-Z0-9.-]+\.[a-Z]{2,10}"'
|
|
alias reg_mac='echo "([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'
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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
|
|
|
|
# Grep aliases
|
|
alias grep_email='grep -E `reg_email`'
|
|
alias grep_ip='grep -E `reg_ip`'
|
|
alias grep_mac='grep -E `reg_mac`'
|
|
alias massgrep='grep -RHIni'
|
|
|
|
# Network
|
|
alias ip-show='curl https://ifconfig.me' # Get global IP address
|
|
alias ips="ifconfig -a | grep -oE \"inet6? (addr:)?s?\`reg_ip\`\" | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
|
|
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'
|
|
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 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
|
|
|
|
# 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
|
|
alias ufw-log='journalctl -f -n 100 -g ufw' # Show UFW log entries in system journal
|
|
|
|
# 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'
|
|
|
|
# System actions
|
|
alias sv='systemctl'
|
|
alias pacnew="find / -name '*.pacnew' 2>/dev/null" # Search for all new configurations after pacman update
|
|
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' # ix.io was offline for about 10 months now...
|
|
#alias upload='curl -F "sprunge=<-" http://sprunge.us' # sprunge.us was offline for a few weeks now, not sure why
|
|
alias upload='curl -F "file=@-" https://hardfiles.org' # hardfiles.org works, but has 24-hour expiry
|
|
alias upload-journal='sudo journalctl -b -1 | upload' # Upload journalctl from last boot to ix.io
|
|
alias auth-log='journalctl SYSLOG_FACILITY=10 -r'
|
|
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 cpu-power='sudo turbostat --Summary --quiet --show PkgWatt --interval 1'
|
|
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
|
|
alias screenlock='xset s activate' # Use DPMS to trigger xss-lock and handle screen locking
|
|
|
|
# System info
|
|
alias meminfo='free -m -l -t'
|
|
alias cpuinfo='lscpu'
|
|
alias batinfo='sudo watch -d -n 2 tlp-stat -b'
|
|
alias battery='cat /sys/class/power_supply/BAT0/capacity'
|
|
alias gpumeminfo='frep -i --color memory /var/log/Xorg.0.log'
|
|
alias journalerr='sudo journalctl -p 3 -xb'
|
|
alias distro='cat /etc/*-release'
|
|
alias diskspace_report="df -P -kHl"
|
|
alias kernel='uname -r'
|
|
|
|
# System processes
|
|
alias psmem='ps auxf | sort -nr -k 4' # Top memory eaters
|
|
alias psmem10='psmem | head -10' # Top 10 memory eaters
|
|
alias pscpu='ps auxf | sort -nr -k 3' # Top cpu eaters
|
|
alias pscpu10='pscpu | head -10' # Top 10 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"'
|
|
alias nowtime='now'
|
|
alias nowdate='date +"%d-%m-%Y"'
|
|
alias week='date +%V'
|
|
|
|
# Cleanup
|
|
alias clean-trash='rm -rf ~/.local/share/Trash/* || echo "Trash already empty"'
|
|
alias clean-downloads='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'
|
|
|
|
# Git aliases
|
|
alias g='git'
|
|
alias gp='git push'
|
|
alias gpl='git pull'
|
|
alias gf='git fetch'
|
|
alias gs='git status --short --branch'
|
|
alias gss='git status'
|
|
alias ga='git add'
|
|
alias gap='git add --patch'
|
|
alias gc='git commit'
|
|
alias gcm='git commit --message'
|
|
alias gca="git commit --amned"
|
|
alias gb='git branch'
|
|
alias gch='git checkout'
|
|
alias gchb='git checkout -b'
|
|
alias gd='git diff'
|
|
alias gdc='git diff --cached'
|
|
alias gundo='git reset --soft HEAD~'
|
|
alias gredo="git reset 'HEAD@{1}'"
|
|
|
|
# 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'
|
|
|
|
# Hyprland aliases
|
|
alias hyprlog-cur-path='echo "/tmp/hypr/$(exa --sort created --group-directories-first --reverse --oneline --color never --no-icons /tmp/hypr | head -n 1)/hyprland.log"'
|
|
alias hyprlog-last-path='echo "/tmp/hypr/$(exa --sort created --group-directories-first --reverse --oneline --color never --no-icons /tmp/hypr | head -n 2 | tail -n 1)/hyprland.log"'
|
|
alias hyprlog-cur='bat $(hyprlog-cur-path)'
|
|
alias hyprlog-last='bat $(hyprlog-last-path)'
|
|
|
|
# Terminal vim-like exits, in case I think the terminal is vim
|
|
alias :q='exit'
|
|
alias :q!='exit'
|
|
alias :wq='exit'
|
|
alias :wq!='exit'
|
|
|
|
# Shell aliases
|
|
alias reload="exec \$SHELL" # Reload the shell (i.e. invoke as a login shell)
|
|
alias path='echo -e ${PATH//:/\\n}' # Print each PATH entry on a separate line
|
|
alias unsudo='sudo -k' # Reset sudo timeout (sudo will require password)
|
|
alias vimwiki='vim -c VimwikiIndex' # Open vimwiki index
|
|
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 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
|
|
alias nf='neofetch'
|
|
alias hist='fc -lt "$HISTTIMEFORMAT" 1'
|
|
alias sudovim='sudoedit'
|
|
alias cls='clear'
|
|
alias wh='which'
|
|
|
|
# Kitty terminal kitten shorthands
|
|
if [ "$TERM" = "xterm=kitty" ]; then
|
|
alias hls='\ls --hyperlink=auto'
|
|
alias hg='kitty +kitten hyperlinked_grep'
|
|
alias transfer='kitty +kitten transfer'
|
|
alias icat='kitty +kitten icat'
|
|
fi
|
|
|
|
# If user is not root, pass all commands via sudo/doas
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
# Enable aliases to be sudoed/doased
|
|
# with doas having precedence over sudo if found
|
|
|
|
## Uncomment if you are using autocompletion (is ZSH)
|
|
#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 '
|
|
|
|
## if the above is uncommented, comment this
|
|
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 '
|
|
fi
|
|
|
|
# XDG Base Directory fixes
|
|
alias nvidia-settings='nvidia-settings --config=$XDG_CONFIG_HOME/nvidia/settings'
|
|
|
|
# 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'
|
|
|
|
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}"
|
|
fi
|