Skip to content

Instantly share code, notes, and snippets.

@rishi23root
Last active May 2, 2026 17:52
Show Gist options
  • Select an option

  • Save rishi23root/0466f74befff198f3184762d99232ca3 to your computer and use it in GitHub Desktop.

Select an option

Save rishi23root/0466f74befff198f3184762d99232ca3 to your computer and use it in GitHub Desktop.
zsh setup and customizations
#!/bin/bash
# can just past it in terminal and run or create a file both works
# script to install all the deps, run with sudo [:)]
set -e # Exit on any error
# ─── System Update ────────────────────────────────────────
sudo apt update && sudo apt upgrade -y
# ─── Install dependencies ─────────────────────────────────
sudo apt install -y xclip zsh git curl
# ─── Install Oh-My-Zsh if not present ─────────────────────
if [ ! -d "$HOME/.oh-my-zsh" ]; then
echo "Installing Oh-My-Zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
fi
# ─── Set ZSH_CUSTOM path ──────────────────────────────────
ZSH_CUSTOM=${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}
# ─── Install ZSH plugins (skip if already installed) ──────
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]; then
echo "Installing zsh-autosuggestions..."
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
else
echo "✅ zsh-autosuggestions already installed"
fi
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]; then
echo "Installing zsh-syntax-highlighting..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
else
echo "✅ zsh-syntax-highlighting already installed"
fi
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autocomplete" ]; then
echo "Installing zsh-autocomplete..."
git clone --depth 1 https://github.com/marlonrichert/zsh-autocomplete.git "$ZSH_CUSTOM/plugins/zsh-autocomplete"
else
echo "✅ zsh-autocomplete already installed"
fi
echo ""
echo "✅ All done! Run: source ~/.zshrc"
# ── Oh My Zsh ─────────────────────────────────────────────────────────────────
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(
git
npm
zsh-syntax-highlighting
zsh-autosuggestions
)
# Install plugins:
# git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
source $ZSH/oh-my-zsh.sh
# ── PATH ───────────────────────────────────────────────────────────────────────
export PATH="$HOME/.local/bin:$PATH"
export PNPM_HOME="/home/rishi/.local/share/pnpm"
export PATH="$PNPM_HOME:$PATH"
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# ── Aliases ────────────────────────────────────────────────────────────────────
if [ $UID -ne 0 ]; then
alias reboot='sudo reboot'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get upgrade -y'
alias uptodate='update && upgrade'
fi
alias nd="pn run"
alias pn="pnpm"
alias dc="docker compose"
alias build="source ~/.zshrc"
alias bk="cd ../"
alias ..="cd ../"
alias h='history'
alias j='jobs -l'
alias c="clear"
alias e='exit'
alias q='exit'
alias wget='wget -c'
alias zshrc='cursor ~/.zshrc'
alias dowork='cursor && eval $( Spotify.exe > /dev/null ) && clear'
alias copy="xclip -selection clipboard"
alias bcwd="cd -"
alias gac="git add . && git commit -m "
alias gp="git push"
alias open="explorer.exe"
# ── SSH Agent (persistent, reuse across terminals) ────────────────────────────
_ssh_agent_env="$HOME/.ssh/agent.env"
_start_agent() {
ssh-agent > "$_ssh_agent_env"
chmod 600 "$_ssh_agent_env"
source "$_ssh_agent_env" > /dev/null
}
if [[ -f "$_ssh_agent_env" ]]; then
source "$_ssh_agent_env" > /dev/null
kill -0 "$SSH_AGENT_PID" 2>/dev/null || _start_agent
else
_start_agent
fi
# ── gitssh: load a key and remember it (per terminal) ────────────────────────
_CURRENT_GIT_KEY="personal"
_autoload_default_key() {
ssh-add -l 2>/dev/null | grep -q "$(ssh-keygen -lf ~/.ssh/$_CURRENT_GIT_KEY 2>/dev/null | awk '{print $2}')" \
|| ssh-add ~/.ssh/"$_CURRENT_GIT_KEY" > /dev/null 2>&1
}
_autoload_default_key
# Switch SSH key and remember it for this terminal session
gitssh() {
local key="${1:-personal}"
ssh-add ~/.ssh/"$key" && {
_CURRENT_GIT_KEY="$key"
echo "✓ Loaded ~/.ssh/$key"
}
}
# Test GitHub auth with the currently loaded key
gittest() {
if [[ -z "$_CURRENT_GIT_KEY" ]]; then
echo "✗ No key loaded yet. Run: gitssh <keyname>"
return 1
fi
echo "Testing GitHub auth with key: $_CURRENT_GIT_KEY"
ssh -T git@github.com
[[ $? -le 1 ]] && echo "✓ Auth OK ($_CURRENT_GIT_KEY)" || echo "✗ Auth failed"
}
# Tab completion for gitssh
_gitssh_complete() {
local keys
keys=($(ls ~/.ssh/ | grep -v '\.pub$\|known_hosts\|config\|authorized_keys\|agent\.env'))
compadd -a keys
}
compdef _gitssh_complete gitssh
# Show all aliases and functions with descriptions
shorts() {
echo ""
printf " %-4s %-20s %s\n" "No." "Name" "Command"
printf " %-4s %-20s %s\n" "───" "──────────────────" "───────────────────────────"
{
# Aliases - handle both single and double quoted
grep -e '^\s*alias' ~/.zshrc \
| sed "s/^\s*alias //" \
| sed "s/='\(.*\)'$/\t\1/" \
| sed "s/=\"\(.*\)\"$/\t\1/" \
| while IFS=$'\t' read -r name cmd; do
echo "alias|$name|$cmd"
done
# Public functions (exclude internal _ functions)
grep -B1 '^[a-zA-Z][a-zA-Z0-9_]*()' ~/.zshrc \
| awk '
/^--$/ { next }
/^#/ { desc = substr($0, 3) }
/\(\)/ {
split($0, a, "()")
print "func|" a[1] "|" (desc ? desc : "function")
desc = ""
}
'
} | nl -w2 | while IFS=$'\t' read -r num rest; do
IFS='|' read -r type name cmd <<< "$rest"
printf " %-4s %-20s %s\n" "$num" "$name" "$cmd"
done
echo ""
}
# ── Keybindings ────────────────────────────────────────────────────────────────
# Delete word before cursor on Ctrl+Backspace
bindkey '^H' backward-kill-word
# ── Tools ──────────────────────────────────────────────────────────────────────
# bun
[ -s "/home/rishi/.bun/_bun" ] && source "/home/rishi/.bun/_bun"
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# zoxide (smart cd)
eval "$(zoxide init zsh)"
# ── Conda ──────────────────────────────────────────────────────────────────────
__conda_setup="$('/home/rishi/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/rishi/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/rishi/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/rishi/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# ── History behaviour ──────────────────────────────────────────────────────────
unsetopt SHARE_HISTORY # up arrow = only THIS terminal's history
setopt INC_APPEND_HISTORY # still save commands to global file immediately
setopt HIST_IGNORE_DUPS # skip duplicate consecutive commands
setopt HIST_IGNORE_SPACE # skip commands starting with a space
PROMPT="%{$fg_bold[green]%}@%{$fg_bold[blue]%}$USER %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%3d%{$reset_color%}$(git_prompt_info) %(?:😏:😬) %{$fg_bold[green]%}|%{$reset_color%} '
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}%1{✗%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment