Skip to content

Instantly share code, notes, and snippets.

@Menchen
Last active April 2, 2025 13:24
Show Gist options
  • Save Menchen/13b931ed9c0175c13c840b7e5513af93 to your computer and use it in GitHub Desktop.
Save Menchen/13b931ed9c0175c13c840b7e5513af93 to your computer and use it in GitHub Desktop.
Zsh config
#!/usr/bin/env zsh
# Use the following command to initialize the first time
# curl "https://gist.githubusercontent.com/Menchen/13b931ed9c0175c13c840b7e5513af93/raw/.zshconf.zsh" -s -o ~/.zshconf.zsh && zsh -d -f -i -l -c "source ~/.zshconf.zsh" && exec zsh -i -l
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
# ZDOTDIR="$HOME/.zshconf.zsh zsh"
if [[ ! -f $HOME/.zshrc ]];then
echo "source ~/.zshconf.zsh" > $HOME/.zshrc
fi
# Auto zinit installer
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma/zinit%F{220})…%f"
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.zinit/bin" && \
print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi
if [[ -f $HOME/.zinit/bin/zmodules/Src/zdharma/zplugin.bundle ]]; then
module_path+=( "$HOME/.zinit/bin/zmodules/Src" )
zmodload zdharma/zplugin
fi
ZSH="$HOME/.zinit/plugins/robbyrussell---oh-my-zsh/"
function addToPATH {
PATH="$1:$PATH"
}
# Add PATH for personal utils, it should be fine in zshrc as it's only for interactive use
addToPATH "$HOME/.bin/"
addToPATH "$HOME/.local/bin/"
[[ -d ~/.pixi/bin ]] && addToPATH "$HOME/.pixi/bin/"
source ~/.zinit/bin/zinit.zsh
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
zmodload -i zsh/complist
# OMZ things to source
local _ZSHRC_OMZ_SOURCES=(
lib/clipboard.zsh
lib/compfix.zsh
lib/directories.zsh
lib/functions.zsh
lib/grep.zsh
lib/history.zsh
lib/key-bindings.zsh
lib/misc.zsh
lib/spectrum.zsh
lib/termsupport.zsh
plugins/extract/extract.plugin.zsh
lib/completion.zsh
)
for p in ${_ZSHRC_OMZ_SOURCES[@]};do
zinit ice; zinit snippet OMZ::${p}
done
#zinit ice lucid wait"0"; zinit light mafredri/zsh-async
zinit ice lucid wait"5"; zinit snippet 'https://gist.githubusercontent.com/Menchen/47ec8382a95980d660c5850d6a1c058e/raw/imgur.zsh'
zinit ice lucid wait"0"; zinit light zdharma-continuum/history-search-multi-word
zinit ice lucid wait"0"; zinit light zsh-users/zsh-history-substring-search
#zsh history search fix
bindkey '\eOA' history-substring-search-up # or ^[OA
bindkey '\eOB' history-substring-search-down # or ^[OB
zinit ice lucid wait"0" has'zoxide'; zinit light ajeetdsouza/zoxide
zinit ice lucid wait"0"; zinit light hlissner/zsh-autopair
# Use my own fork with Async race condition patched
ZSH_AUTOSUGGEST_USE_ASYNC=1
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=500
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
zinit wait lucid for \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
zdharma-continuum/fast-syntax-highlighting \
blockf \
zsh-users/zsh-completions \
atload"!_zsh_autosuggest_start" \
Menchen/zsh-autosuggestions
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
# powerlevel10k
zinit ice depth=1; zinit light romkatv/powerlevel10k
ZSH_THEME="romkatv/powerlevel10k"
if [[ "$TERM" == "linux" ]] || zmodload zsh/terminfo && (( terminfo[colors] < 256 )); then
# Use 16 color for compatibility
export POWERLEVEL9K_CONFIG_FILE="${HOME}/.p10k-16bit.zsh"
[[ -f ~/.p10k-16bit.zsh ]] && source ~/.p10k-16bit.zsh
else
# Use 256 color
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
fi
# Bitwarden SSH Agent support
[[ -S "${HOME}/.bitwarden-ssh-agent.sock" ]] && export SSH_AUTH_SOCK="${HOME}/.bitwarden-ssh-agent.sock"
# Ghostty
if [[ -n $GHOSTTY_RESOURCES_DIR ]]; then
source "$GHOSTTY_RESOURCES_DIR"/shell-integration/zsh/ghostty-integration
fi
# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
# Command execution time stamp shown in the history command output.
HIST_STAMPS="mm/dd/yyyy"
# Enable Shared History
setopt SHARE_HISTORY
setopt autocd
setopt nonomatch
export GPG_TTY=$TTY
if type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files'
export FZF_DEFAULT_OPTS='-m --height 50% --border'
fi
#fzf plugin
[[ -f ~/.fzf.zsh ]] && source ~/.fzf.zsh
# Alias
alias sudo='sudo '
alias setuslocale="export LANG=en_US.UTF-8"
if [[ -n "$commands[jenv]" ]]; then
alias jenv_set_java_home='export JAVA_HOME="$(jenv javahome)"'
alias java='export JAVA_HOME="$(jenv javahome)";java'
alias javac='export JAVA_HOME="$(jenv javahome)";javac'
alias javadoc='export JAVA_HOME="$(jenv javahome)";javadoc'
fi
if [[ -n "$commands[eza]" ]]; then
# general use
alias ls='eza' # ls
alias l='eza -lbF --icons --git' # list, size, type, git
alias ll='eza -lbGF --icons --git' # long list
alias llm='eza -lbGd --icons --git --sort=modified' # long list, modified date sort
alias la='eza -lbhHigUmuSa --icons --time-style=long-iso --git --color-scale' # all list
alias lx='eza -lbhHigUmuSa@ --icons --time-style=long-iso --git --color-scale' # all + extended list
# specialty views
alias lS='eza -1' # one column, just names
alias lt='eza --tree --level=2 --icons' # tree
else
alias ls='ls --color=auto'
fi
# Alias
if [[ -n "$commands[lvim]" ]]; then
alias vim=lvim
alias nvim=lvim
export EDITOR=lvim
export VISUAL=lvim
if [[ -n "$commands[nvr]" ]];then
export NVR_CMD=lvim
fi
elif [[ -n "$commands[nvim]" ]]; then
alias vim=nvim
export EDITOR=nvim
export VISUAL=nvim
fi
if [[ -n "$commands[lazygit]" ]]; then
alias lg=lazygit
if [[ -n "$commands[yadm]" ]];then
alias ly='lazygit -ucd ~/.local/share/yadm/lazygit -w ~ -g ~/.local/share/yadm/repo.git'
fi
fi
if [[ -n "$commands[youtube-dl]" ]];then
alias youtube-dl='yt-dlp'
fi
# Askpass
if [[ $(uname) == "Darwin" ]] && [[ -x "/Applications/ssh-askpass.app/Contents/MacOS/ssh-askpass" ]];then
export SSH_ASKPASS="/Applications/ssh-askpass.app/Contents/MacOS/ssh-askpass"
fi
# streamlink iina
if [[ $(uname) == "Darwin" ]] && [[ -n "$commands[iina]" ]] && [[ -n "$commands[streamlink]" ]];then
alias twitchstream='function __twitchstream() { streamlink --twitch-low-latency https://www.twitch.tv/$1 best --stdout 2>/dev/null | iina --stdin &>/dev/null &; unset -f __twitchstream; }; __twitchstream'
fi
# Merge duplicate PATH entry's
typeset -U path
# smart case tab completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# function zvm_after_init() {
# insert-user-host-cwd() LBUFFER+=${(%):-%n@%m:%~}
# zle -N insert-user-host-cwd
# # bindkey '^T' insert-user-host-cwd
# # bindkey '^T' insert-user-host-cwd
# zvm_bindkey viins '^T' insert-user-host-cwd
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment