Last active
November 4, 2025 20:45
-
-
Save justsml/76458bd5d9a6566e1caa325cbd150ee4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Enhanced Shell Aliases Configuration | |
| # ===================================== | |
| # ============================================================================ | |
| # NETWORK & PORTS | |
| # ============================================================================ | |
| # Port monitoring with improved formatting | |
| alias ports-all='lsof -Pn -i4 -i6' # Include IPv6 | |
| alias ports-open='lsof -Pn -i4 -i6 | grep -E "LISTEN|UDP"' | |
| alias ports-active='lsof -Pn -i4 -i6 | grep ESTABLISHED' | |
| alias ports-tcp='lsof -Pn -iTCP' | |
| alias ports-udp='lsof -Pn -iUDP' | |
| alias ports-process='lsof -Pn -i -c' # Usage: ports-process chrome | |
| # Network listeners and connections | |
| alias netlisteners='lsof -iTCP -sTCP:LISTEN -P -n' | |
| alias netconnections='netstat -pan --inet 2>/dev/null || ss -tunap' | |
| alias netactive='ss -tunap | grep ESTAB' | |
| # IP addresses - improved cross-platform compatibility | |
| alias myip='curl -s https://ipinfo.io/ip 2>/dev/null || curl -s https://api.ipify.org' | |
| alias myips="ifconfig 2>/dev/null | grep -E 'inet6?\\s' | grep -v '127.0.0.1\\|::1' | awk '{print \$2}' | cut -d/ -f1" | |
| alias localip="hostname -I 2>/dev/null | awk '{print \$1}' || ipconfig getifaddr en0 2>/dev/null" | |
| # Network utilities | |
| alias pingg='ping -c 4 google.com' | |
| alias ping8='ping -c 4 8.8.8.8' | |
| alias flushdns='sudo dscacheutil -flushcache 2>/dev/null || sudo systemd-resolve --flush-caches 2>/dev/null || echo "DNS flush not available"' | |
| alias speedtest='curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -' | |
| # ============================================================================ | |
| # PATH MANAGEMENT | |
| # ============================================================================ | |
| # List paths with improved formatting | |
| alias paths='echo -e ${PATH//:/\\n}' | |
| alias paths-sorted='echo -e ${PATH//:/\\n} | sort' | |
| alias paths-unique='echo -e ${PATH//:/\\n} | awk "!seen[\$0]++"' # Better than uniq | |
| alias paths-summary='echo -e ${PATH//:/\\n} | sort -u' | |
| alias paths-check='echo -e ${PATH//:/\\n} | while read p; do [ -d "$p" ] && echo "✓ $p" || echo "✗ $p"; done' | |
| # Find commands in PATH (fixed function-like behavior) | |
| alias whichall='type -a' # Better than which -a | |
| alias whereis='command -v' | |
| # ============================================================================ | |
| # FILE LISTING & NAVIGATION | |
| # ============================================================================ | |
| # Modern ls alternatives (with fallbacks) | |
| if command -v eza &>/dev/null; then | |
| alias ls='eza --icons --group-directories-first' | |
| alias ll='eza -l --icons --git --group-directories-first' | |
| alias la='eza -la --icons --git --group-directories-first' | |
| alias lt='eza -la --icons --git --sort=modified' | |
| alias tree='eza --tree --icons' | |
| elif command -v exa &>/dev/null; then | |
| alias ls='exa --icons --group-directories-first' | |
| alias ll='exa -l --icons --git --group-directories-first' | |
| alias la='exa -la --icons --git --group-directories-first' | |
| alias lt='exa -la --icons --git --sort=modified' | |
| alias tree='exa --tree --icons' | |
| else | |
| # Fallback to standard ls with best options | |
| alias ls='ls --color=auto --group-directories-first 2>/dev/null || ls -G' | |
| alias ll='ls -lhF --time-style=long-iso 2>/dev/null || ls -lhF' | |
| alias la='ls -lahF' | |
| alias l='ls -CF' | |
| fi | |
| # Size and time-based listing | |
| alias lsbig='ls -lahS | head -20' # Top 20 largest files | |
| alias lsnew='ls -laht | head -20' # Top 20 newest files | |
| alias lsold='ls -lahtr | head -20' # Top 20 oldest files | |
| alias lsdir='ls -d */' # List only directories | |
| alias lsfiles='ls -p | grep -v /' # List only files | |
| # Quick directory navigation | |
| alias ..='cd ..' | |
| alias ...='cd ../..' | |
| alias ....='cd ../../..' | |
| alias .....='cd ../../../..' | |
| alias ~='cd ~' | |
| alias -- -='cd -' # Go to previous directory | |
| # Directory stack | |
| alias d='dirs -v' | |
| alias pd='pushd' | |
| alias pop='popd' | |
| # ============================================================================ | |
| # DISK USAGE & SYSTEM INFO | |
| # ============================================================================ | |
| # Disk usage with better defaults | |
| alias df='df -h --total 2>/dev/null || df -h' | |
| alias dfi='df -hi' # Show inode usage | |
| alias dflocal='df -h -x tmpfs -x devtmpfs -x squashfs' # Local filesystems only | |
| # Directory sizes | |
| alias du='du -h -c' | |
| alias du1='du -hc --max-depth=1 2>/dev/null || du -hc -d 1' | |
| alias du2='du -hc --max-depth=2 2>/dev/null || du -hc -d 2' | |
| alias du3='du -hc --max-depth=3 2>/dev/null || du -hc -d 3' | |
| alias dux='du -hxc --max-depth=1' # Same filesystem only | |
| alias dusort='du -hc --max-depth=1 | sort -h' # Sorted by size | |
| alias dubig='du -hsx * | sort -rh | head -20' # Top 20 space users | |
| # Modern disk usage analyzer (if available) | |
| alias ncdu='ncdu --color dark' | |
| # System information | |
| alias meminfo='free -h' | |
| alias cpuinfo='lscpu | grep -E "Model name|CPU\(s\)|Thread|Core|Socket"' | |
| alias diskinfo='lsblk -o NAME,SIZE,TYPE,MOUNTPOINT' | |
| # ============================================================================ | |
| # PROCESS MANAGEMENT | |
| # ============================================================================ | |
| # Process monitoring | |
| alias psg='ps aux | grep -v grep | grep -i' | |
| alias psm='ps aux --sort=-%mem | head -20' # Top memory users | |
| alias psc='ps aux --sort=-%cpu | head -20' # Top CPU users | |
| alias pstree='pstree -p' | |
| alias topmem='ps auxf | sort -nr -k 4 | head -10' | |
| alias topcpu='ps auxf | sort -nr -k 3 | head -10' | |
| # Modern alternatives | |
| alias htop='htop 2>/dev/null || top' | |
| alias btop='btop 2>/dev/null || htop 2>/dev/null || top' | |
| # ============================================================================ | |
| # HISTORY & SEARCH | |
| # ============================================================================ | |
| # History search with better formatting | |
| alias h='history' | |
| alias hs='history | grep -i --color=auto' | |
| alias hsx='history | egrep -i --color=auto' | |
| alias htop20='history | awk "{print \$2}" | sort | uniq -c | sort -rn | head -20' | |
| alias hclear='history -c && history -w' # Clear history | |
| # File search | |
| alias ff='find . -type f -iname' # Find files | |
| alias fd='find . -type d -iname' # Find directories | |
| alias fif='grep -r -n --color=auto' # Find in files | |
| # Modern alternatives if available | |
| alias rg='rg --smart-case 2>/dev/null || grep -r --color=auto' | |
| alias fzfp='fzf --preview "bat --color=always {}" 2>/dev/null || fzf' | |
| # ============================================================================ | |
| # TEXT PROCESSING & MANIPULATION | |
| # ============================================================================ | |
| # Text utilities | |
| alias trim="awk '{\$1=\$1};1'" # Remove leading/trailing spaces | |
| alias unique='sort -u' | |
| alias count='sort | uniq -c | sort -rn' | |
| alias lower='tr "[:upper:]" "[:lower:]"' | |
| alias upper='tr "[:lower:]" "[:upper:]"' | |
| alias jsonpp='python3 -m json.tool' | |
| alias xmlpp='xmllint --format -' | |
| alias urlencode='python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip()))"' | |
| alias urldecode='python3 -c "import sys, urllib.parse; print(urllib.parse.unquote(sys.stdin.read().strip()))"' | |
| # Modern cat alternative | |
| alias cat='bat --style=plain 2>/dev/null || cat' | |
| alias catp='bat 2>/dev/null || cat' # With syntax highlighting | |
| # ============================================================================ | |
| # GIT SHORTCUTS | |
| # ============================================================================ | |
| alias g='git' | |
| alias gs='git status -sb' | |
| alias ga='git add' | |
| alias gaa='git add --all' | |
| alias gc='git commit -v' | |
| alias gcm='git commit -m' | |
| alias gca='git commit -v --amend' | |
| alias gco='git checkout' | |
| alias gcb='git checkout -b' | |
| alias gd='git diff' | |
| alias gds='git diff --staged' | |
| alias gl='git log --oneline --decorate --graph --all' | |
| alias gll='git log --graph --pretty=format:"%C(yellow)%h%Creset %C(blue)%d%Creset %s %C(green)(%cr) %C(magenta)<%an>%Creset"' | |
| alias gp='git push' | |
| alias gpu='git push -u origin $(git branch --show-current)' | |
| alias gpl='git pull' | |
| alias gf='git fetch' | |
| alias gfa='git fetch --all --prune' | |
| alias gb='git branch -vv' | |
| alias gba='git branch -a' | |
| alias gbd='git branch -d' | |
| alias grb='git rebase' | |
| alias grbi='git rebase -i' | |
| alias gst='git stash' | |
| alias gstp='git stash pop' | |
| alias gstl='git stash list' | |
| # Git search | |
| alias gfind='git log --all --grep' # Search commit messages | |
| alias ggrep='git grep -n' # Search file contents | |
| alias gblame='git blame -w -C -C -C' # Ignore whitespace and detect moves | |
| # Git utilities | |
| alias groot='cd $(git rev-parse --show-toplevel)' # Go to git root | |
| alias gclean='git clean -fd' | |
| alias gprune='git remote prune origin' | |
| alias gwip='git add -A && git commit -m "WIP"' | |
| alias gunwip='git reset HEAD~1 --mixed' | |
| alias glast='git log -1 HEAD --stat' | |
| # ============================================================================ | |
| # SAFETY ALIASES | |
| # ============================================================================ | |
| # Confirmation prompts for destructive operations | |
| alias rm='rm -i' | |
| alias mv='mv -i' | |
| alias cp='cp -i' | |
| alias ln='ln -i' | |
| # Safe alternatives | |
| alias rmi='rm -i' # Interactive remove | |
| alias rmf='rm -rf' # Force remove (use with caution) | |
| alias chown='chown --preserve-root' | |
| alias chmod='chmod --preserve-root' | |
| alias chgrp='chgrp --preserve-root' | |
| # ============================================================================ | |
| # DEVELOPMENT TOOLS | |
| # ============================================================================ | |
| # Python | |
| alias py='python3' | |
| alias pyvenv='python3 -m venv' | |
| alias pyserve='python3 -m http.server' | |
| alias pyclean='find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null' | |
| # Node.js | |
| alias npmls='npm list --depth=0' | |
| alias npmg='npm list -g --depth=0' | |
| alias npmclean='rm -rf node_modules package-lock.json && npm install' | |
| # Docker (if available) | |
| alias dk='docker' | |
| alias dkps='docker ps' | |
| alias dkpsa='docker ps -a' | |
| alias dki='docker images' | |
| alias dkrm='docker rm' | |
| alias dkrmi='docker rmi' | |
| alias dkprune='docker system prune -af' | |
| alias dkexec='docker exec -it' | |
| alias dklogs='docker logs -f' | |
| # ============================================================================ | |
| # ARCHIVE & COMPRESSION | |
| # ============================================================================ | |
| # Extract any archive | |
| alias extract='for file in "$@"; do | |
| if [ -f "$file" ]; then | |
| case "$file" in | |
| *.tar.bz2) tar xjf "$file" ;; | |
| *.tar.gz) tar xzf "$file" ;; | |
| *.tar.xz) tar xJf "$file" ;; | |
| *.bz2) bunzip2 "$file" ;; | |
| *.gz) gunzip "$file" ;; | |
| *.tar) tar xf "$file" ;; | |
| *.zip) unzip "$file" ;; | |
| *.7z) 7z x "$file" ;; | |
| *) echo "$file: Unknown archive format" ;; | |
| esac | |
| fi | |
| done' | |
| # Create archives | |
| alias targz='tar -czf' | |
| alias tarbz2='tar -cjf' | |
| alias tarxz='tar -cJf' | |
| # ============================================================================ | |
| # MISCELLANEOUS | |
| # ============================================================================ | |
| # Quick edits | |
| alias ea='${EDITOR:-vim} ~/.bash_aliases && source ~/.bash_aliases' | |
| alias eb='${EDITOR:-vim} ~/.bashrc && source ~/.bashrc' | |
| alias ez='${EDITOR:-vim} ~/.zshrc && source ~/.zshrc' | |
| alias hosts='sudo ${EDITOR:-vim} /etc/hosts' | |
| # System shortcuts | |
| alias reload='exec $SHELL -l' | |
| alias path='echo -e ${PATH//:/\\n}' | |
| alias now='date +"%Y-%m-%d %H:%M:%S"' | |
| alias nowutc='date -u +"%Y-%m-%d %H:%M:%S UTC"' | |
| alias week='date +%V' | |
| alias timestamp='date +%s' | |
| # Clipboard (cross-platform) | |
| if command -v pbcopy &>/dev/null; then | |
| alias clip='pbcopy' | |
| alias paste='pbpaste' | |
| elif command -v xclip &>/dev/null; then | |
| alias clip='xclip -selection clipboard' | |
| alias paste='xclip -selection clipboard -o' | |
| fi | |
| # Weather | |
| alias weather='curl -s wttr.in' | |
| alias weatherfull='curl -s v2.wttr.in' | |
| # ============================================================================ | |
| # ENVIRONMENT VARIABLES | |
| # ============================================================================ | |
| # Better pager settings for git and less | |
| export PAGER='less -RXF --mouse --wheel-lines=3' | |
| export LESS='-R -X --long-prompt --quit-if-one-screen' | |
| export LESSHISTFILE=- # Disable less history | |
| # Better grep defaults | |
| export GREP_OPTIONS='--color=auto --exclude-dir={.git,.svn,node_modules}' | |
| # Editor preference | |
| export EDITOR="${EDITOR:-vim}" | |
| export VISUAL="${VISUAL:-$EDITOR}" | |
| # ============================================================================ | |
| # FUNCTIONS (Better as functions than aliases) | |
| # ============================================================================ | |
| # Create directory and cd into it | |
| mkcd() { mkdir -p "$1" && cd "$1"; } | |
| # Search process and kill | |
| pskill() { ps aux | grep -v grep | grep -i "$1" | awk '{print $2}' | xargs kill -9 2>/dev/null; } | |
| # Backup file with timestamp | |
| backup() { cp "$1" "$1.backup.$(date +%Y%m%d_%H%M%S)"; } | |
| # Show directory tree with limited depth | |
| treex() { tree -L "${1:-2}" -C --dirsfirst; } | |
| # Quick calculator | |
| calc() { echo "scale=2; $*" | bc -l; } | |
| # Show PATH entries on separate lines with numbers | |
| pathshow() { | |
| echo "$PATH" | tr ':' '\n' | nl -v 0 | |
| } | |
| # Find files by content | |
| findcontent() { | |
| find . -type f -exec grep -l "$1" {} \; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ~/.bashrc | |
| # If not running interactively, don't do anything | |
| [ -z "$PS1" ] && return | |
| # don't put duplicate lines in the history. See bash(1) for more options | |
| # ... or force ignoredups and ignorespace | |
| HISTCONTROL=ignoredups:ignorespace | |
| # append to the history file, don't overwrite it | |
| shopt -s histappend | |
| # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) | |
| HISTSIZE=1000000 | |
| HISTFILESIZE=200000 | |
| # check the window size after each command and, if necessary, | |
| # update the values of LINES and COLUMNS. | |
| shopt -s checkwinsize | |
| export PROMPT_COMMAND="history -a; history -n" | |
| # make less more friendly for non-text input files, see lesspipe(1) | |
| [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
| # set variable identifying the chroot you work in (used in the prompt below) | |
| if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then | |
| debian_chroot=$(cat /etc/debian_chroot) | |
| fi | |
| # set a fancy prompt (non-color, unless we know we "want" color) | |
| case "$TERM" in | |
| xterm-color) color_prompt=yes;; | |
| esac | |
| # uncomment for a colored prompt, if the terminal has the capability; turned | |
| # off by default to not distract the user: the focus in a terminal window | |
| # should be on the output of commands, not on the prompt | |
| #force_color_prompt=yes | |
| if [ -n "$force_color_prompt" ]; then | |
| if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
| # We have color support; assume it's compliant with Ecma-48 | |
| # (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
| # a case would tend to support setf rather than setaf.) | |
| color_prompt=yes | |
| else | |
| color_prompt= | |
| fi | |
| fi | |
| if [ "$color_prompt" = yes ]; then | |
| PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
| else | |
| PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
| fi | |
| unset color_prompt force_color_prompt | |
| # If this is an xterm set the title to user@host:dir | |
| case "$TERM" in | |
| xterm*|rxvt*) | |
| PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" | |
| ;; | |
| *) | |
| ;; | |
| esac | |
| # enable color support of ls and also add handy aliases | |
| if [ -x /usr/bin/dircolors ]; then | |
| test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
| alias ls='ls --color=auto' | |
| #alias dir='dir --color=auto' | |
| #alias vdir='vdir --color=auto' | |
| alias grep='grep --color=auto' | |
| alias fgrep='fgrep --color=auto' | |
| alias egrep='egrep --color=auto' | |
| fi | |
| # some more ls aliases | |
| alias ll='ls -alF' | |
| alias la='ls -A' | |
| alias l='ls -CF' | |
| # Alias definitions. | |
| # You may want to put all your additions into a separate file like | |
| # ~/.bash_aliases, instead of adding them here directly. | |
| # See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
| if [ -f ~/.bash_aliases ]; then | |
| . ~/.bash_aliases | |
| fi | |
| # enable programmable completion features (you don't need to enable | |
| # this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
| # sources /etc/bash.bashrc). | |
| if [ -f /etc/bash_completion ] && ! shopt -oq posix; then | |
| . /etc/bash_completion | |
| fi | |
| export PGUSER=postgres | |
| export PGPASSWORD=postgres | |
| export PGDATABASE=postgres | |
| export PGHOST=0.0.0.0 | |
| export PGPORT=5433 | |
| # domainSuffix=".brain.rentals" | |
| domainSuffix="" | |
| if [ "$UID" == "0" ]; then | |
| export PS1="\[\e[31m\]\u\[\e[m\] @ \[\e[33m\]${HOSTNAME}${domainSuffix}\[\e[m\]\[\e[37m\]: \[\e[36m\]\w\[\e[m\] \[\e[31m\]>\[\e[m\] " | |
| else | |
| export PS1="\[\e[36m\]\u\[\e[m\] @ \[\e[37m\]${HOSTNAME}${domainSuffix}\[\e[m\]\[\e[37m\]: \[\e[32m\]\w\[\e[m\] \$ " | |
| fi | |
| [ -f ~/.fzf.bash ] && source ~/.fzf.bash | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
| [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |
| [ -f "$HOME/.local/bin/env" ] && . "$HOME/.local/bin/env" | |
| [[ -f /opt/vultr/vultr_app.sh ]] && . /opt/vultr/vultr_app.sh | |
| # ----- Reliable interactive check ----- | |
| case $- in *i*) ;; *) return ;; esac | |
| # ----- History config ----- | |
| HISTFILE=${HISTFILE:-"$HOME/.bash_history"} | |
| HISTSIZE=1000000 | |
| HISTFILESIZE=1000000 # keep as large as HISTSIZE to avoid surprise truncation | |
| HISTCONTROL=ignoredups:ignorespace | |
| shopt -s histappend # don't overwrite history | |
| shopt -s cmdhist # multiline commands saved as one entry | |
| # ----- Safely append to PROMPT_COMMAND without being clobbered ----- | |
| pc_add() { | |
| local cmd | |
| for cmd in "$@"; do | |
| case ";$PROMPT_COMMAND;" in | |
| *";$cmd;"*) ;; # already present | |
| *) PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND;}$cmd" ;; | |
| esac | |
| done | |
| } | |
| # Append+merge model: append new lines, then reload full file to merge across shells | |
| pc_add 'history -a' 'history -c' 'history -r' | |
| export PROMPT_COMMAND |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment