chore(misc): simplify .zshrc and add docker management aliases

This commit is contained in:
sankalp committed 2026-07-05 20:01:02 +05:45
1 parent 5f84a0ce73
commit c03f32e262
1 file changed
+265 -231
+265 -231
View File
@@ -1,27 +1,19 @@
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# =============================================================================
# ENVIRONMENT
# =============================================================================
export EDITOR="nvim"
export VISUAL="$EDITOR"
export BROWSER="zen-browser"
export TERMINAL="kitty"
export BAT_THEME="base16"
# ┬ ┬┌─┐┬─┐┌─┐
# └┐┌┘├─┤├┬┘└─┐
# └┘ ┴ ┴┴└─└─┘
export VISUAL="${EDITOR}"
export EDITOR='nvim'
export BROWSER='zen-browser'
export HISTORY_IGNORE="(ls|cd|pwd|exit|sudo reboot|history|cd -|cd ..)"
export SUDO_PROMPT="Deploying root access for %u. Password pls: "
export BAT_THEME="base16"
export HISTORY_IGNORE="(ls|ll|la|pwd|exit|history|cd|cd -|cd ..)"
# Android SDK
export ANDROID_HOME="$HOME/Android/Sdk"
export ANDROID_SDK_ROOT="$ANDROID_HOME"
# =============================================================================
# PATH
# =============================================================================
typeset -U path PATH
path=(
@@ -35,251 +27,301 @@ path=(
export PATH
# =============================================================================
# ZSH OPTIONS
# =============================================================================
setopt AUTO_CD
setopt AUTO_LIST
setopt AUTO_MENU
setopt AUTO_PUSHD
setopt COMPLETE_IN_WORD
setopt EXTENDED_GLOB
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_REDUCE_BLANKS
setopt HIST_SAVE_NO_DUPS
setopt INC_APPEND_HISTORY
setopt INTERACTIVE_COMMENTS
setopt LIST_PACKED
setopt MENU_COMPLETE
setopt NO_BEEP
setopt NO_CLOBBER
setopt PROMPT_SUBST
setopt PUSHD_IGNORE_DUPS
setopt SHARE_HISTORY
# =============================================================================
# HISTORY
# =============================================================================
HISTFILE="$HOME/.config/zsh/zhistory"
HISTSIZE=100000
SAVEHIST=100000
# =============================================================================
# COMPLETION
# =============================================================================
# ┬ ┌─┐┌─┐┌┬┐ ┌─┐┌┐┌┌─┐┬┌┐┌┌─┐
# │ │ │├─┤ ││ ├┤ ││││ ┬││││├┤
# ┴─┘└─┘┴ ┴─┴┘ └─┘┘└┘└─┘┴┘└┘└─┘
autoload -Uz compinit
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
zmodload zsh/complist
mkdir -p "$HOME/.cache/zsh"
local zcompdump="$HOME/.cache/zsh/zcompdump"
local zcompdump="$HOME/.config/zsh/zcompdump"
if [[ -n "$zcompdump"(#qN.mh+24) ]]; then
compinit -d "$zcompdump"
compinit -i -d "$zcompdump"
else
compinit -C -d "$zcompdump"
compinit -C -d "$zcompdump"
fi
# Compile completion dump
if [[ -s "$zcompdump" ]]; then
zcompile "$zcompdump"
if [[ ! -f "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc" ]]; then
zcompile -U "$zcompdump"
fi
# Completion styles
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list \
'm:{a-z}={A-Z}' \
'+r:|[._-]=* r:|=*' \
'+l:|=*'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:descriptions' format '[%d]'
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
precmd () { vcs_info }
_comp_options+=(globdots)
# =============================================================================
# FZF TAB
# =============================================================================
zstyle ':fzf-tab:*' switch-group ',' '.'
zstyle ':completion:*' menu select
zstyle ':completion:*:descriptions' format '[%d]'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' matcher-list \
'm:{a-zA-Z}={A-Za-z}' \
'+r:|[._-]=* r:|=*' \
'+l:|=*'
zstyle ':vcs_info:*' formats ' %B%s-[%F{magenta}%f %F{yellow}%b%f]-'
zstyle ':fzf-tab:*' fzf-flags --style=full --height=90% --pointer '>' --gutter ' ' \
--color 'pointer:green:bold,bg+:-1:,fg+:green:bold,info:blue:bold,marker:yellow:bold,hl:gray:bold,hl+:gray:bold' \
--input-label ' Search ' --color 'input-border:blue,input-label:blue:bold' \
--list-label ' Results ' --color 'list-border:green,list-label:green:bold' \
--preview-label ' Preview ' --preview-label-pos '27:bottom' --color 'preview-border:magenta,preview-label:magenta:bold'
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --icons=always --color=always -a $realpath'
zstyle ':fzf-tab:complete:eza:*' fzf-preview 'eza -1 --icons=always --color=always -a $realpath'
zstyle ':fzf-tab:complete:bat:*' fzf-preview 'bat --color=always --theme=base16 $realpath'
zstyle ':fzf-tab:*' fzf-bindings 'space:accept'
zstyle ':fzf-tab:*' accept-line enter
zstyle ':fzf-tab:*' fzf-flags \
--height=90% \
--layout=reverse \
--border \
--pointer='>' \
--marker='*' \
--preview-window='right:60%' \
--color='pointer:green:bold' \
--color='marker:yellow:bold' \
--color='hl:blue:bold' \
--color='hl+:magenta:bold'
zstyle ':fzf-tab:complete:cd:*' fzf-preview \
'eza --icons --color=always -1 -a $realpath'
zstyle ':fzf-tab:complete:eza:*' fzf-preview \
'eza --icons --color=always -1 -a $realpath'
zstyle ':fzf-tab:complete:bat:*' fzf-preview \
'bat --color=always --style=numbers --theme=base16 $realpath'
# =============================================================================
# VCS
# =============================================================================
precmd() {
vcs_info
}
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats \
' %B%F{magenta} %b%f'
# =============================================================================
# STARSHIP
# =============================================================================
export STARSHIP_CONFIG="$HOME/.config/starship.toml"
if command -v starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
fi
# =============================================================================
# PLUGINS
# =============================================================================
plugins=(
/usr/share/zsh/plugins/fzf-tab-git/fzf-tab.zsh
/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
/usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
)
for plugin in "${plugins[@]}"; do
[[ -f "$plugin" ]] && source "$plugin"
done
# =============================================================================
# KEYBINDINGS
# =============================================================================
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line
bindkey '^[[3~' delete-char
# Better tab animation
# ┬ ┬┌─┐┬┌┬┐┬┌┐┌┌─┐ ┌┬┐┌─┐┌┬┐┌─┐
# │││├─┤│ │ │││││ ┬ │││ │ │ └─┐
# └┴┘┴ ┴┴ ┴ ┴┘└┘└─┘ ─┴┘└─┘ ┴ └─┘
expand-or-complete-with-dots() {
echo -n "\e[90m…\e[0m"
echo -n "\e[31m…\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey '^I' expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
# =============================================================================
# TERMINAL TITLE
# =============================================================================
# ┬ ┬┬┌─┐┌┬┐┌─┐┬─┐┬ ┬
# ├─┤│└─┐ │ │ │├┬┘└┬┘
# ┴ ┴┴└─┘ ┴ └─┘┴└─ ┴
HISTFILE=~/.config/zsh/zhistory
HISTSIZE=5000
SAVEHIST=5000
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
function set-title-precmd() {
print -Pn -- "\e]2;%n@%m:%~\a"
# ┌─┐┌─┐┬ ┬ ┌─┐┌─┐┌─┐┬ ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
# ┌─┘└─┐├─┤ │ │ ││ ││ │ │├─┘ │ ││ ││││└─┐
# └─┘└─┘┴ ┴ └─┘└─┘└─┘┴─┘ └─┘┴ ┴ ┴└─┘┘└┘└─┘
setopt AUTOCD # change directory just by typing its name
setopt PROMPT_SUBST # enable command substitution in prompt
setopt MENU_COMPLETE # Automatically highlight first element of completion menu
setopt LIST_PACKED # The completion menu takes less space.
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
# ┌┬┐┬ ┬┌─┐ ┌─┐┬─┐┌─┐┌┬┐┌─┐┌┬┐
# │ ├─┤├┤ ├─┘├┬┘│ ││││├─┘ │
# ┴ ┴ ┴└─┘ ┴ ┴└─└─┘┴ ┴┴ ┴
export STARSHIP_CONFIG="$HOME/.config/starship.toml"
if [[ $- == *i* ]] && command -v starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
fi
if [[ $- == *i* ]] && command -v zoxide >/dev/null 2>&1; then
eval "$(zoxide init zsh)"
fi
# ┌─┐┬ ┬ ┬┌─┐┬┌┐┌┌─┐
# ├─┘│ │ ││ ┬││││└─┐
# ┴ ┴─┘└─┘└─┘┴┘└┘└─┘
source /usr/share/zsh/plugins/fzf-tab-git/fzf-tab.zsh
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey '^[[3~' delete-char
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
# ┌─┐┬ ┬┌─┐┌┐┌┌─┐┌─┐ ┌┬┐┌─┐┬─┐┌┬┐┬┌┐┌┌─┐┬ ┌─┐ ┌┬┐┬┌┬┐┬ ┌─┐
# │ ├─┤├─┤││││ ┬├┤ │ ├┤ ├┬┘│││││││├─┤│ └─┐ │ │ │ │ ├┤
# └─┘┴ ┴┴ ┴┘└┘└─┘└─┘ ┴ └─┘┴└─┴ ┴┴┘└┘┴ ┴┴─┘└─┘ ┴ ┴ ┴ ┴─┘└─┘
function xterm_title_precmd () {
print -Pn -- '\e]2;%n@%m %~\a'
[[ "$TERM" == 'screen'* ]] && print -Pn -- '\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-}\e\\'
}
function set-title-preexec() {
print -Pn -- "\e]2;${1:q}\a"
function xterm_title_preexec () {
print -Pn -- '\e]2;%n@%m %~ %# ' && print -n -- "${(q)1}\a"
[[ "$TERM" == 'screen'* ]] && { print -Pn -- '\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-} %# ' && print -n -- "${(q)1}\e\\"; }
}
case "$TERM" in
kitty*|alacritty*|tmux*|screen*|xterm*)
add-zsh-hook precmd set-title-precmd
add-zsh-hook preexec set-title-preexec
;;
esac
if [[ "$TERM" == (kitty*|alacritty*|tmux*|screen*|xterm*) ]]; then
add-zsh-hook -Uz precmd xterm_title_precmd
add-zsh-hook -Uz preexec xterm_title_preexec
fi
# =============================================================================
# ALIASES
# =============================================================================
# Editor
alias vim="$EDITOR"
alias vi="$EDITOR"
alias code="$EDITOR"
# ┌─┐┬ ┬┌─┐┌─┐
# ├─┤│ │├─┤└─┐
# ┴ ┴┴─┘┴┴ ┴└─┘
if command -v trash-put > /dev/null 2>&1; then
alias rm='trash-put'
elif command -v trash > /dev/null 2>&1; then
alias rm='trash -v'
elif command -v gio > /dev/null 2>&1; then
alias rm='gio trash'
else
alias rm='rm -i'
fi
# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias home='cd ~'
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# Clear / Exit
alias c="clear"
alias cls='clear'
alias q="exit"
alias :q="exit"
# File management
alias ls="eza --icons --group-directories-first"
alias l="ls -lh"
alias la="ls -lah"
alias lt="ls --tree"
alias ls='eza --icons --group-directories-first'
alias l='ls -lh'
alias la='ls -lah'
alias ll='ls -lah --git'
alias lla='ls -lah'
alias lls='ls -lh'
alias las='ls -a'
alias lt='eza --tree --icons --group-directories-first'
alias ltr='eza --tree --level=2 --icons --group-directories-first'
alias lx='eza -lh --sort=extension --group-directories-first --icons'
alias lk='eza -lh --sort=size --group-directories-first --icons'
alias lc='eza -lh --sort=changed --group-directories-first --icons'
alias lu='eza -lh --sort=accessed --group-directories-first --icons'
alias labc='eza -lh --sort=name --group-directories-first --icons'
alias ltime='eza -lh --sort=modified --group-directories-first --icons'
alias lr='eza -lh -R --icons'
alias lf='eza -lh --only-files --icons'
alias ldir='eza -lh --only-dirs --icons'
alias lw='eza -1 --icons --group-directories-first'
# Chmod
alias mx='chmod a+x'
alias 000='chmod -R 000'
alias 644='chmod -R 644'
alias 666='chmod -R 666'
alias 755='chmod -R 755'
alias 777='chmod -R 777'
# Overrides
alias cp='cp -i'
alias mv='mv -i'
alias mkdir='mkdir -p'
alias ps='ps auxf'
alias ping='ping -c 10'
alias less='less -R'
alias cat="bat --paging=never --style=plain"
alias grep="grep --color=auto"
alias tree="tree -C"
alias cp="cp -iv"
alias mv="mv -iv"
alias rm="rm -Iv"
alias mkdir="mkdir -pv"
# Archives
alias mtar="tar -czvf"
alias utar="tar -xzvf"
alias z="zip -r"
alias uz="unzip"
# Pacman / Paru
alias pacman="sudo pacman --color auto"
alias i="paru -S"
alias r="paru -Rns"
alias s="paru -Ss"
alias u="paru -Syu"
alias update="paru -Syu"
alias clean="paru -Scc"
alias mktar='tar -cvf'
alias mkbz2='tar -cvjf'
alias mkgz='tar -cvzf'
alias untar='tar -xvf'
alias unbz2='tar -xvjf'
ungz() {
tar -xvzf "$@"
}
# Docker
alias docker-start="sudo systemctl start docker"
alias docker-stop="sudo systemctl stop docker"
docker-clean() {
command -v docker >/dev/null || {
echo "docker is not installed."
return 1
}
# Misc
alias tree="tree -C"
alias sr="source ~/.config/zsh/env.zsh"
docker system prune -af --volumes
}
alias dockerstart="sudo systemctl start docker"
alias dockerstop="sudo systemctl stop docker"
alias dockerrestart='sudo systemctl restart docker'
alias dockerstatus='systemctl status docker'
alias dockerenable='sudo systemctl enable --now docker'
# Extract
extract() {
for archive in "$@"; do
if [ -f "$archive" ]; then
case $archive in
*.tar.bz2) tar xvjf "$archive" ;;
*.tar.gz) tar xvzf "$archive" ;;
*.bz2) bunzip2 "$archive" ;;
*.rar) rar x "$archive" ;;
*.gz) gunzip "$archive" ;;
*.tar) tar xvf "$archive" ;;
*.tbz2) tar xvjf "$archive" ;;
*.tgz) tar xvzf "$archive" ;;
*.zip) unzip "$archive" ;;
*.Z) uncompress "$archive" ;;
*.7z) 7z x "$archive" ;;
*) echo "don't know how to extract '$archive'..." ;;
esac
else
echo "'$archive' is not a valid file!"
fi
done
}
# System
cd() {
builtin cd "${1:-$HOME}" || return
eza --icons --group-directories-first
}
update() {
if command -v paru >/dev/null 2>&1; then
paru -Syu "$@"
elif command -v yay >/dev/null 2>&1; then
yay -Syu "$@"
else
sudo pacman -Syu "$@"
fi
}
clean() {
if command -v paru >/dev/null 2>&1; then
paru -Scc "$@"
elif command -v yay >/dev/null 2>&1; then
yay -Scc "$@"
else
sudo pacman -Scc "$@"
fi
}
# Network
alias whatismyip="whatsmyip"
function whatsmyip () {
# Internal IP Lookup.
echo -n "Internal IP: "
if command -v ip >/dev/null 2>&1; then
ip -o -4 route get 1.1.1.1 2>/dev/null | awk '{for (i=1; i<=NF; i++) if ($i == "src") {print $(i+1); exit}}'
elif command -v ifconfig >/dev/null 2>&1; then
ifconfig | awk '/inet / && $2 != "127.0.0.1" {print $2; exit}'
else
echo "unknown"
fi
# External IP Lookup
echo -n "External IP: "
if command -v curl >/dev/null 2>&1; then
curl -4fsS --max-time 5 https://icanhazip.com || echo "unknown"
else
echo "curl not installed"
fi
}
alias mkgrub="sudo grub-mkconfig -o /boot/grub/grub.cfg"
# =============================================================================
# PYTHON / VENV
# =============================================================================
venv() {
local env_dir=".venv"
@@ -310,25 +352,17 @@ act() {
echo "No virtual environment found"
}
# =============================================================================
# GIT
# =============================================================================
# Package Manager
if command -v fzf >/dev/null 2>&1; then
if command -v yay >/dev/null 2>&1; then
alias yayf="yay -Slq | fzf --multi --preview 'yay -Sii {1}' --preview-window=down:75% | xargs -ro yay -S"
fi
alias gs="git status"
alias ga="git add ."
alias gc="git commit -m"
alias gp="git push"
alias gl="git pull"
if command -v paru >/dev/null 2>&1; then
alias paruf="paru -Slq | fzf --multi --preview 'paru -Sii {1}' --preview-window=down:75% | xargs -ro paru -S"
fi
# =============================================================================
# EXTRA
# =============================================================================
# Auto correct minor typos
ENABLE_CORRECTION="true"
# Better word movement
WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
# alias nvw='NVIM_APPNAME=nvim-new nvim'
export OLLAMA_HOST=http://127.0.0.1:11434
if command -v pacman >/dev/null 2>&1; then
alias pacf="pacman -Slq | fzf --multi --preview 'pacman -Si {1}' --preview-window=down:75% | xargs -ro sudo pacman -S"
fi
fi