# Custom Bash Aliases

## system services
alias restart="sudo systemctl restart"
alias status="sudo systemctl status"

## navigation
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'

## system information
alias connections="sudo netstat -tunlp"
alias ports='netstat -tulanp'
alias path='echo -e ${PATH//:/\\n}'
alias free='free -m -l -t'
alias psmem='ps auxf | sort -nr -k 4 | head -10'
alias pscpu='ps auxf | sort -nr -k 3 | head -10'

## system logs
alias logtail="tail -n 200 /var/log/syslog"

## system administration
alias upgrade="sudo apt update && sudo apt upgrade -y"
alias syscat='systemctl cat'
alias sysls='systemctl list-unit-files --type=service --state=enabled'
alias syslsa='systemctl list-unit-files --type=service'

## safe defaults
alias rm='rm -I --preserve-root'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'

## apps
alias g='git'
# enable tab completion for 'g' by marking as alias for 'git'
if type _git &> /dev/null; then
    complete -o default -o nospace -F _git g;
fi

alias bat='batcat'
alias bathelp='bat --plain --language=help'
help() {
    "$@" --help 2>&1 | bathelp
}

## text editing
alias edit="emacs"
alias sedit="sudo emacs"

## ls helpers
alias l="ls -lFh --color"
alias la="ls -AF --color" # exclude . and ..
alias lsd="ls -lFh --color | grep --color=never '^d'" # only directories
alias ls="command ls --color" # always color
alias ll="ls -AlFh --color"

# always enable colored `grep` output
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

## misc utils
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias ping='ping -c 5'
alias reload="exec ${SHELL} -l" # reload the shell
