Last active
November 3, 2025 08:51
-
-
Save broisnischal/e4976d57c5b37f05d3e88aa5a37a48f6 to your computer and use it in GitHub Desktop.
Zshrx
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
| # If you come from bash you might have to change your $PATH. | |
| # export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH | |
| # Path to your Oh My Zsh installation. | |
| export ZSH="$HOME/.oh-my-zsh" | |
| # Set name of the theme to load --- if set to "random", it will | |
| # load a random theme each time Oh My Zsh is loaded, in which case, | |
| # to know which specific one was loaded, run: echo $RANDOM_THEME | |
| # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes | |
| ZSH_THEME="theunraveler" | |
| # ZSH_THEME="apple" | |
| # Set list of themes to pick from when loading at random | |
| # Setting this variable when ZSH_THEME=random will cause zsh to load | |
| # a theme from this variable instead of looking in $ZSH/themes/ | |
| # If set to an empty array, this variable will have no effect. | |
| # ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) | |
| # Uncomment the following line to use case-sensitive completion. | |
| # CASE_SENSITIVE="true" | |
| # Uncomment the following line to use hyphen-insensitive completion. | |
| # Case-sensitive completion must be off. _ and - will be interchangeable. | |
| # HYPHEN_INSENSITIVE="true" | |
| # Uncomment one of the following lines to change the auto-update behavior | |
| # zstyle ':omz:update' mode disabled # disable automatic updates | |
| # zstyle ':omz:update' mode auto # update automatically without asking | |
| # zstyle ':omz:update' mode reminder # just remind me to update when it's time | |
| # Uncomment the following line to change how often to auto-update (in days). | |
| # zstyle ':omz:update' frequency 13 | |
| # Uncomment the following line if pasting URLs and other text is messed up. | |
| # DISABLE_MAGIC_FUNCTIONS="true" | |
| # Uncomment the following line to disable colors in ls. | |
| # DISABLE_LS_COLORS="true" | |
| # Uncomment the following line to disable auto-setting terminal title. | |
| # DISABLE_AUTO_TITLE="true" | |
| # Uncomment the following line to enable command auto-correction. | |
| # ENABLE_CORRECTION="true" | |
| # Uncomment the following line to display red dots whilst waiting for completion. | |
| # You can also set it to another string to have that shown instead of the default red dots. | |
| # e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f" | |
| # Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765) | |
| # COMPLETION_WAITING_DOTS="true" | |
| # Uncomment the following line if you want to disable marking untracked files | |
| # under VCS as dirty. This makes repository status check for large repositories | |
| # much, much faster. | |
| # DISABLE_UNTRACKED_FILES_DIRTY="true" | |
| # Uncomment the following line if you want to change the command execution time | |
| # stamp shown in the history command output. | |
| # You can set one of the optional three formats: | |
| # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" | |
| # or set a custom format using the strftime function format specifications, | |
| # see 'man strftime' for details. | |
| # HIST_STAMPS="mm/dd/yyyy" | |
| # Would you like to use another custom folder than $ZSH/custom? | |
| # ZSH_CUSTOM=/path/to/new-custom-folder | |
| # Which plugins would you like to load? | |
| # Standard plugins can be found in $ZSH/plugins/ | |
| # Custom plugins may be added to $ZSH_CUSTOM/plugins/ | |
| # Example format: plugins=(rails git textmate ruby lighthouse) | |
| # Add wisely, as too many plugins slow down shell startup. | |
| plugins=( | |
| git | |
| command-not-found | |
| sudo | |
| z | |
| colored-man-pages | |
| zsh-autosuggestions | |
| zsh-syntax-highlighting | |
| fzf | |
| ) | |
| source $ZSH/oh-my-zsh.sh | |
| # User configuration | |
| # export MANPATH="/usr/local/man:$MANPATH" | |
| # You may need to manually set your language environment | |
| # export LANG=en_US.UTF-8 | |
| # Preferred editor for local and remote sessions | |
| # if [[ -n $SSH_CONNECTION ]]; then | |
| # export EDITOR='vim' | |
| # else | |
| # export EDITOR='nvim' | |
| # fi | |
| # Compilation flags | |
| # export ARCHFLAGS="-arch $(uname -m)" | |
| # Set personal aliases, overriding those provided by Oh My Zsh libs, | |
| # plugins, and themes. Aliases can be placed here, though Oh My Zsh | |
| # users are encouraged to define aliases within a top-level file in | |
| # the $ZSH_CUSTOM folder, with .zsh extension. Examples: | |
| # - $ZSH_CUSTOM/aliases.zsh | |
| # - $ZSH_CUSTOM/macos.zsh | |
| # For a full list of active aliases, run `alias`. | |
| # | |
| # Example aliases | |
| alias zshconfig="code ~/.zshrc" | |
| alias ohmyzsh="code ~/.oh-my-zsh" | |
| ## Added by Zinit's installer | |
| if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then | |
| print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})β¦%f" | |
| command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit" | |
| command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \ | |
| print -P "%F{33} %F{34}Installation successful.%f%b" || \ | |
| print -P "%F{160} The clone has failed.%f%b" | |
| fi | |
| source "$HOME/.local/share/zinit/zinit.git/zinit.zsh" | |
| autoload -Uz _zinit | |
| (( ${+_comps} )) && _comps[zinit]=_zinit | |
| # Load a few important annexes, without Turbo | |
| zinit light-mode for \ | |
| zdharma-continuum/zinit-annex-as-monitor \ | |
| zdharma-continuum/zinit-annex-bin-gem-node \ | |
| zdharma-continuum/zinit-annex-patch-dl \ | |
| zdharma-continuum/zinit-annex-rust | |
| ### End of Zinit's installer chunk | |
| . $HOME/.asdf/asdf.sh | |
| . $HOME/.asdf/completions/asdf.bash | |
| source ~/.spaceshiprc.zsh | |
| # π§© Fuzzy copy env var | |
| cenv() { | |
| local value | |
| local name | |
| value=$(grep -v '^#' .env | fzf | cut -d '=' -f2- | tr -d '"') | |
| name=$(grep -v '^#' .env | fzf | cut -d '=' -f1) | |
| if [[ -n "$value" ]]; then | |
| echo -n "$value" | clip | |
| echo "β Copied: $name" | |
| else | |
| echo "β No selection." | |
| fi | |
| } | |
| # Copy text to clipboard (auto-detect backend) | |
| clip() { | |
| if command -v wl-copy &>/dev/null; then | |
| wl-copy | |
| elif command -v xclip &>/dev/null; then | |
| xclip -selection clipboard | |
| elif command -v pbcopy &>/dev/null; then | |
| pbcopy | |
| else | |
| echo "β No clipboard tool found (install wl-clipboard or xclip)" | |
| return 1 | |
| fi | |
| } | |
| # =========================================== | |
| # β‘ FZF Power Aliases & Functions | |
| # =========================================== | |
| # ----- Clipboard Wrapper (Auto Detect) ----- | |
| clip() { | |
| if command -v wl-copy &>/dev/null; then | |
| wl-copy | |
| elif command -v xclip &>/dev/null; then | |
| xclip -selection clipboard | |
| elif command -v pbcopy &>/dev/null; then | |
| pbcopy | |
| else | |
| echo "β No clipboard tool found (install wl-clipboard or xclip)" | |
| return 1 | |
| fi | |
| } | |
| # ----- Fuzzy Open File with Preview ----- | |
| alias f='fzf --preview "bat --style=plain --color=always {} | head -200"' | |
| # ----- Fuzzy Search + Open File in Neovim ----- | |
| alias vf='fd --type f --hidden --exclude .git | fzf --preview "bat --style=plain --color=always {} | head -100" | xargs -r nvim' | |
| # ----- Fuzzy Git Commit Browser ----- | |
| alias gpick='git log --oneline --graph --decorate | fzf --ansi --preview "echo {} | awk '\''{print \$1}'\'' | xargs git show --color=always"' | |
| # ----- Fuzzy Git Branch Checkout ----- | |
| alias gco='git branch | fzf --preview "git log -n 3 --color=always {1}" | xargs -r git checkout' | |
| # ----- Fuzzy K8s Pod Logs ----- | |
| alias klogs='kubectl get pods | fzf --ansi --preview "kubectl describe pod {1}" | awk "{print \$1}" | xargs -r kubectl logs -f' | |
| # ----- Fuzzy Kill Process ----- | |
| alias pkillz='ps -ef | fzf --header-lines=1 --preview "echo {}" | awk "{print \$2}" | xargs -r kill -9' | |
| # ----- Fuzzy .env Variable Copier ----- | |
| envcopy() { | |
| local value | |
| value=$(grep -v '^#' .env | fzf --prompt="Select env var: " --preview "echo {}" | cut -d '=' -f2- | tr -d '"') | |
| if [[ -n "$value" ]]; then | |
| echo -n "$value" | clip | |
| echo "β Copied: $value" | |
| else | |
| echo "β No selection." | |
| fi | |
| } | |
| # ----- Fuzzy directory jump | |
| dj() { | |
| local dir | |
| # Collect upward directories (up to 6 levels) | |
| local ups=() | |
| local i=0 | |
| local p="$PWD" | |
| while [[ "$i" -lt 6 && "$p" != "/" ]]; do | |
| ups+=("$p") | |
| p=$(dirname "$p") | |
| ((i++)) | |
| done | |
| # Collect downward directories (all subdirs) | |
| local downs | |
| downs=$(fd --type d .) | |
| # Combine upward and downward paths | |
| dir=$(printf "%s\n" "${ups[@]}" "$downs" | fzf --height 40% --reverse --preview 'ls -la {}') || return | |
| # Change directory | |
| cd "$dir" || return | |
| } | |
| # ----- Fuzzy History Search (like Ctrl+R, but better) ----- | |
| alias hsearch='history | fzf --preview "echo {}" | awk "{\$1=\"\"; print substr(\$0,2)}" | pbcopy' | |
| alias gf='git fetch --all && git pull --all' | |
| gcc() { | |
| # require git and fzf | |
| command -v git >/dev/null 2>&1 || { echo "git not found"; return 1; } | |
| command -v fzf >/dev/null 2>&1 || { echo "fzf not found"; return 1; } | |
| # build list: local heads + remote heads (strip remotes/ prefix), unique | |
| branches=$(git for-each-ref --format='%(refname:short)' refs/heads refs/remotes 2>/dev/null \ | |
| | sed 's#^remotes/##' \ | |
| | sort -u) | |
| [ -z "$branches" ] && { echo "no branches found"; return 1; } | |
| # pick one with fzf; preview shows recent commits (graph) | |
| picked=$(printf '%s\n' "$branches" \ | |
| | fzf --height 40% --border --ansi --preview 'git --no-pager log -n 20 --graph --pretty=format:"%C(yellow)%h%C(reset) %C(cyan)%an%C(reset) %C(green)%ar%C(reset)%n%s%n%b" -- {+}' \ | |
| --preview-window=right:60%:wrap) || return 0 | |
| # trim whitespace/newlines | |
| branch=$(echo "$picked" | xargs) | |
| # nothing selected | |
| [ -z "$branch" ] && return 0 | |
| # If local exists -> checkout | |
| if git show-ref --verify --quiet "refs/heads/$branch"; then | |
| git checkout "$branch" | |
| return $? | |
| fi | |
| # If a remote has this branch, determine a remote name (first match) and create tracking branch | |
| # remote refs format: <remote>/<branch> | |
| remote_match=$(git for-each-ref --format='%(refname:short)' refs/remotes 2>/dev/null \ | |
| | sed 's#^remotes/##' \ | |
| | grep -xE ".+/$branch" | head -n1) | |
| if [ -n "$remote_match" ]; then | |
| remote_name=$(printf '%s' "$remote_match" | cut -d'/' -f1) | |
| git checkout -b "$branch" --track "$remote_name/$branch" | |
| return $? | |
| fi | |
| # If no remote and no local, create new local branch | |
| git checkout -b "$branch" | |
| return $? | |
| } | |
| gcpull() { | |
| # require git and fzf | |
| command -v git >/dev/null 2>&1 || { echo "git not found"; return 1; } | |
| command -v fzf >/dev/null 2>&1 || { echo "fzf not found"; return 1; } | |
| # get local and remote branches | |
| branches=$(git for-each-ref --format='%(refname:short)' refs/heads refs/remotes 2>/dev/null \ | |
| | sed 's#^remotes/##' \ | |
| | sort -u) | |
| [ -z "$branches" ] && { echo "no branches found"; return 1; } | |
| # pick a branch with fzf | |
| picked=$(printf '%s\n' "$branches" \ | |
| | fzf --height 40% --border --ansi --preview 'git --no-pager log -n 20 --graph --pretty=format:"%C(yellow)%h%C(reset) %C(cyan)%an%C(reset) %C(green)%ar%C(reset)%n%s%n%b" -- {+}' \ | |
| --preview-window=right:60%:wrap) || return 0 | |
| branch=$(echo "$picked" | xargs) | |
| [ -z "$branch" ] && return 0 | |
| # If local branch exists | |
| if git show-ref --verify --quiet "refs/heads/$branch"; then | |
| git checkout "$branch" || return $? | |
| else | |
| # Check if branch exists on remote (origin) | |
| if git ls-remote --exit-code --heads origin "$branch" >/dev/null 2>&1; then | |
| git checkout -b "$branch" --track "origin/$branch" || return $? | |
| else | |
| # create new local branch | |
| git checkout -b "$branch" || return $? | |
| fi | |
| fi | |
| # Pull latest changes from upstream if tracking exists | |
| if git rev-parse --abbrev-ref --symbolic-full-name @{u} >/dev/null 2>&1; then | |
| git pull | |
| fi | |
| } | |
| alias gpo="git push --set-upstream origin $(git branch | awk '/^\* / { print $2 }')" | |
| # ----- Fuzzy Package Search (Arch) ----- | |
| alias pacf='pacman -Q | fzf --preview "pacman -Qi {1}"' | |
| # ----- Universal Dev Control Center ----- | |
| devctl() { | |
| local choice | |
| choice=$(cat <<EOF | fzf --prompt="π§ Dev Control > " --ansi --height=20% | |
| π Search Files | |
| π§© Search Code (ripgrep) | |
| πΏ Git Commit Browser | |
| π± Git Branch Checkout | |
| π Docker Logs | |
| βΈοΈ K8s Pod Logs | |
| π Copy .env Var | |
| π Kill Process | |
| π Open in Neovim | |
| EOF | |
| ) | |
| case "$choice" in | |
| "π Search Files") fd --type f | fzf --preview "bat --color=always {} | head -100" ;; | |
| "π§© Search Code (ripgrep)") fzf --bind "change:reload(rg --color=always -n {q} || true)" --ansi ;; | |
| "πΏ Git Commit Browser") gpick ;; | |
| "π± Git Branch Checkout") gco ;; | |
| "π Docker Logs") dlogs ;; | |
| "βΈοΈ K8s Pod Logs") klogs ;; | |
| "π Copy .env Var") envcopy ;; | |
| "π Kill Process") pkillz ;; | |
| "π Open in Neovim") vf ;; | |
| *) echo "Cancelled." ;; | |
| esac | |
| } | |
| # FZF native keybindings | |
| [ -f /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh | |
| [ -f /usr/share/fzf/completion.zsh ] && source /usr/share/fzf/completion.zsh | |
| # development aliases | |
| alias dev="nr dev" | |
| # docker | |
| dsh() { | |
| local cid | |
| cid=$(docker ps --format '{{.Names}}\t{{.Image}}\t{{.Status}}' | fzf --ansi --preview "docker logs --tail 20 {1}" | awk '{print $1}') | |
| [[ -n "$cid" ]] && docker exec -it "$cid" /bin/bash | |
| } | |
| # Pick a container and view logs | |
| dlogs() { | |
| local cid | |
| cid=$(docker ps --format '{{.Names}}\t{{.Image}}\t{{.Status}}' | fzf --ansi --preview "docker logs --tail 50 {1}" | awk '{print $1}') | |
| [[ -n "$cid" ]] && docker logs -f "$cid" | |
| } | |
| dstop() { | |
| local cid | |
| cid=$(docker ps --format '{{.Names}}\t{{.Image}}\t{{.Status}}' | fzf --ansi | awk '{print $1}') | |
| [[ -n "$cid" ]] && docker stop "$cid" | |
| } | |
| drm() { | |
| local cid | |
| cid=$(docker ps -a --format '{{.Names}}\t{{.Image}}\t{{.Status}}' | fzf --ansi | awk '{print $1}') | |
| [[ -n "$cid" ]] && docker rm "$cid" | |
| } | |
| # Remove Docker image interactively | |
| drmi() { | |
| local img | |
| img=$(docker images --format '{{.Repository}}:{{.Tag}}\t{{.ID}}' | fzf --ansi | awk '{print $1}') | |
| [[ -n "$img" ]] && docker rmi "$img" | |
| } | |
| # Run container from selected image | |
| drun() { | |
| local img | |
| img=$(docker images --format '{{.Repository}}:{{.Tag}}\t{{.ID}}' | fzf --ansi | awk '{print $1}') | |
| [[ -n "$img" ]] && docker run -it --rm "$img" /bin/bash | |
| } | |
| # Search logs interactively with preview | |
| dlogsearch() { | |
| local cid | |
| cid=$(docker ps --format '{{.Names}}' | fzf --prompt="Select container: ") | |
| [[ -n "$cid" ]] && docker logs "$cid" | fzf --preview "echo {}" --bind "enter:execute-silent(echo {} | xargs -I % docker exec -it $cid sh -c 'echo %')" | |
| } | |
| # Remove Docker network interactively | |
| drnet() { | |
| local net | |
| net=$(docker network ls --format '{{.Name}}\t{{.ID}}' | fzf --ansi | awk '{print $1}') | |
| [[ -n "$net" ]] && docker network rm "$net" | |
| } | |
| # Remove Docker volume interactively | |
| drv() { | |
| local vol | |
| vol=$(docker volume ls --format '{{.Name}}' | fzf --ansi) | |
| [[ -n "$vol" ]] && docker volume rm "$vol" | |
| } | |
| doc() { | |
| local choice | |
| choice=$(cat <<EOF | fzf --prompt="π³ Docker Menu > " --ansi | |
| π Attach Shell | |
| π View Logs | |
| π Stop Container | |
| ποΈ Remove Container | |
| πΌοΈ Remove Image | |
| π Run Image | |
| π Remove Network | |
| πΎ Remove Volume | |
| EOF | |
| ) | |
| case "$choice" in | |
| "π Attach Shell") dsh ;; | |
| "π View Logs") dlogs ;; | |
| "π Stop Container") dstop ;; | |
| "ποΈ Remove Container") drm ;; | |
| "πΌοΈ Remove Image") drmi ;; | |
| "π Run Image") drun ;; | |
| "π Remove Network") drnet ;; | |
| "πΎ Remove Volume") drv ;; | |
| *) echo "Cancelled." ;; | |
| esac | |
| } | |
| # clock() { | |
| # local color="\033[1;36m" # cyan | |
| # local reset="\033[0m" | |
| # # hide cursor | |
| # tput civis | |
| # while true; do | |
| # # move cursor to top-left | |
| # tput cup 0 0 | |
| # # print large cool digital clock | |
| # echo -e "${color}" | |
| # date +"%T" | figlet -f big | |
| # echo -e "${reset}" | |
| # sleep 1 | |
| # done | |
| # # show cursor again on exit | |
| # trap 'tput cnorm' EXIT | |
| # } | |
| alias time='watch -t -n 1 "date +%T"' | |
| alias g='git' | |
| alias cm='g add . && g commit -m' | |
| alias fkuc='g add . && g commit -m "chore: some changes" && g push' | |
| alias fuck='sudo shutdown now' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment