diff --git a/profiles/Microsoft.PowerShell_profile.ps1 b/profiles/pwsh/Microsoft.PowerShell_profile.ps1 similarity index 100% rename from profiles/Microsoft.PowerShell_profile.ps1 rename to profiles/pwsh/Microsoft.PowerShell_profile.ps1 diff --git a/profiles/zsh/.zshrc b/profiles/zsh/.zshrc new file mode 100644 index 0000000..f21618e --- /dev/null +++ b/profiles/zsh/.zshrc @@ -0,0 +1,153 @@ +# This is a Zsh config. If you see this in bash, switch to Zsh: exec zsh +if [ -n "$BASH_VERSION" ]; then + echo "This is a Zsh config. Run: exec zsh" + return 0 2>/dev/null || exit 0 +fi + +# ---------- powerlevel10k instant prompt (must stay near the top) ---------- +if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then + source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" +fi + +# ---------- safety & history ---------- +export ZSH_DISABLE_COMPFIX=true +setopt autocd autopushd pushdignoredups +setopt hist_ignore_all_dups hist_reduce_blanks inc_append_history share_history +setopt no_beep interactive_comments +export HISTSIZE=20000 +export SAVEHIST=20000 +export HISTFILE=$HOME/.zsh_history +bindkey -e + +# ---------- helpers ---------- +_has() { command -v "$1" >/dev/null 2>&1; } + +# cache compinit's security check instead of paying for it on every launch +_compinit_cached() { + autoload -Uz compinit + local dump="${ZDOTDIR:-$HOME}/.zcompdump" + if [[ -n ${dump}(#qN.mh+24) ]]; then + compinit -d "$dump" + else + compinit -C -d "$dump" + fi +} + +# ---------- zinit (plugin manager, auto-install) ---------- +export ZINIT_HOME=${XDG_DATA_HOME:-$HOME/.local/share}/zinit/zinit.git +if [[ ! -d $ZINIT_HOME ]]; then + mkdir -p ${ZINIT_HOME:h} + git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" +fi +source "$ZINIT_HOME/zinit.zsh" + +# ---------- prompt: powerlevel10k ---------- +zinit ice depth=1 +zinit light romkatv/powerlevel10k +POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true +POWERLEVEL9K_INSTANT_PROMPT=quiet +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir vcs) +POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time time) +POWERLEVEL9K_PROMPT_ON_NEWLINE=true +POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%242F╭─" +POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%242F╰▶ " +POWERLEVEL9K_TIME_FORMAT='%D{%H:%M}' +POWERLEVEL9K_DIR_SHOW_WRITABLE=v2 +POWERLEVEL9K_VCS_BRANCH_ICON=' ' +POWERLEVEL9K_MODE=nerdfont-complete + +# ---------- completions & UI polish ---------- +zstyle ':completion:*' menu select +zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} + +# ---------- plugins (deferred via turbo mode for faster startup) ---------- +# fzf-tab needs compinit to have already run, and needs to load before +# anything that wraps completion widgets (autosuggestions, syntax-highlighting). +zinit ice wait lucid atinit'_compinit_cached' +zinit light Aloxaf/fzf-tab + +zinit ice wait lucid +zinit light zsh-users/zsh-autosuggestions + +zinit ice wait lucid +zinit light ajeetdsouza/zoxide +eval "$(zoxide init zsh)" + +# fzf (uses ripgrep or fd if present, else find) +if _has rg; then + export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git"' +elif _has fd; then + export FZF_DEFAULT_COMMAND='fd --hidden --exclude .git' +else + export FZF_DEFAULT_COMMAND='find . -path "*/.git" -prune -o -type f -print' +fi +export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" +export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND" +zinit ice wait lucid +zinit light junegunn/fzf + +# syntax-highlighting must be loaded last, after any plugin that wraps widgets +zinit ice wait lucid +zinit light zsh-users/zsh-syntax-highlighting + +# ---------- aliases with smart fallbacks ---------- +if _has eza; then alias ls='eza --icons=auto --group-directories-first'; else alias ls='ls --color=auto'; fi +alias ll='ls -la' +if _has bat; then + alias cat='bat -pp' +elif _has batcat; then + alias cat='batcat -pp' +fi +if _has rg; then alias grep='rg'; fi +if _has duf; then alias df='duf'; fi +if _has btm; then alias top='btm'; fi +alias gs='git status' +alias gl='git log --oneline --graph --decorate' +alias gp='git pull --rebase' +alias gc='git commit' +alias gco='git checkout' +alias c='clear' +phok() { + cd "$HOME/Coding/jwtf/apps/phokus" || return + if [ "$#" -gt 0 ]; then + "$@" + fi +} + +# ---------- misc helpers ---------- +mkcd(){ mkdir -p "$1" && cd "$1"; } +extract(){ + case "$1" in + *.tar.gz|*.tgz) tar xzf "$1";; + *.tar.bz2|*.tbz2) tar xjf "$1";; + *.tar.xz|*.txz) tar xJf "$1";; + *.tar) tar xf "$1";; + *.gz) gunzip "$1";; + *.zip) unzip "$1";; + *.7z) 7z x "$1";; + *.rar) unrar x "$1";; + *) echo "unknown format";; + esac +} + +# ---------- nvm ---------- +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" +[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" + +# ---------- bun ---------- +export BUN_INSTALL="$HOME/.bun" +[ -s "$BUN_INSTALL/_bun" ] && source "$BUN_INSTALL/_bun" + +# ---------- PATH ---------- +export PNPM_HOME="${PNPM_HOME:-$HOME/.local/share/pnpm}" +export PATH="$HOME/.local/bin:$HOME/bin:/opt/homebrew/bin:$PATH" +case ":$PATH:" in + *":$PNPM_HOME/bin:"*) ;; + *) export PATH="$PNPM_HOME/bin:$PATH" ;; +esac +case ":$PATH:" in + *":$BUN_INSTALL/bin:"*) ;; + *) export PATH="$BUN_INSTALL/bin:$PATH" ;; +esac