Files
scripts/zsh/zshrc
T

180 lines
5.8 KiB
Bash

export ZSH_CONFIG=$HOME/.config/zsh
export OHMYZSH=$ZSH_CONFIG/oh-my-zsh
export OHMYZSH_CUSTOM=$OHMYZSH/custom
export ZSHRC_BRANCH="${ZSHRC_BRANCH:-$(cat "$ZSH_CONFIG/branch" 2>/dev/null || echo master)}"
export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/${ZSHRC_BRANCH}/zsh/"
export ZSHRC_URL="$ZSHRC_GIT/zshrc"
export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh"
export ZSHRC_BOOTSTRAP_VERSION="4"
export ZSHRC_BOOTSTRAP="$ZSH_CONFIG/.bootstrapped"
[[ -d "$HOME/Scripts" ]] && path+=("$HOME/Scripts")
[[ -d "$HOME/.local/bin" ]] && path+=("$HOME/.local/bin")
[[ -d "$HOME/AppImages" ]] && path+=("$HOME/AppImages")
[[ -d "$HOME/.opencode/bin" ]] && path+=("$HOME/.opencode/bin")
[[ -f "$ZSH_CONFIG/zsh-functions.zsh" ]] && source "$ZSH_CONFIG/zsh-functions.zsh"
# Bootstrap: installs missing CLI tools and oh-my-zsh plugins across distros.
if [[ ! -f "$ZSHRC_BOOTSTRAP" || "$(cat "$ZSHRC_BOOTSTRAP" 2>/dev/null)" != "$ZSHRC_BOOTSTRAP_VERSION" || "$BOOTSTRAP" == "true" ]]; then
tmp=/tmp/.zshrc_bootstrap.$$
curl -fsSL --connect-timeout 5 --max-time 10 -o "$tmp" "$ZSHRC_BOOTSTRAP_URL" 2>/dev/null
if [[ -f "$tmp" ]]; then
zsh "$tmp" 2>/dev/null
echo "$ZSHRC_BOOTSTRAP_VERSION" > "$ZSHRC_BOOTSTRAP"
rm -f "$tmp"
fi
fi
TMUXCONF="$HOME/.config/tmux"
BYOBUCONF="$HOME/.config/byobu"
TMUXREMOTE="$ZSHRC_GIT/tmux.conf"
if [ ! -f "$TMUXCONF/tmux.conf" ] && [ ! -f "$BYOBUCONF/.tmux.conf" ]; then
TEMP_TMUXCONF=$(mktemp)
if curl -fsSL --connect-timeout 5 --max-time 10 -o "$TEMP_TMUXCONF" "$TMUXREMOTE"; then
mkdir -p "$TMUXCONF" "$BYOBUCONF"
cp "$TEMP_TMUXCONF" "$TMUXCONF/tmux.conf"
mv "$TEMP_TMUXCONF" "$BYOBUCONF/.tmux.conf"
else
rm -f "$TEMP_TMUXCONF"
echo "Error: Failed to download tmux config from $TMUXREMOTE" >&2
fi
fi
export HISTFILE="$ZSH_CONFIG/history"
export ZSH_COMPDUMP="$ZSH_CONFIG/zcompdump-${HOST}-${ZSH_VERSION}"
export HISTSIZE=10000
export SAVEHIST=10000
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_REDUCE_BLANKS
setopt HIST_FCNTL_LOCK
setopt AUTO_CD
setopt AUTO_LIST
setopt INTERACTIVE_COMMENTS
setopt HIST_VERIFY
setopt EXTENDED_HISTORY
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT
ZSH_THEME=""
ENABLE_CORRECTION="false"
HIST_STAMPS="mm/dd/yyyy"
plugins=(
git
sudo
extract
eza
history
kitty
docker
docker-compose
archlinux
encode64
universalarchive
zsh-autosuggestions
fast-syntax-highlighting
fzf
fzf-tab
systemd
vscode
rsync
starship
)
zstyle ':omz:update' 'mode' auto
zstyle ':omz:plugins:eza' 'dirs-first' yes
zstyle ':omz:plugins:eza' 'git-status' yes
zstyle ':omz:plugins:eza' 'header' yes
zstyle ':omz:plugins:eza' 'show-group' yes
zstyle ':omz:plugins:eza' 'icons' yes
zstyle ':omz:plugins:eza' 'color-scale' all
zstyle ':omz:plugins:eza' 'color-scale-mode' fixed
zstyle ':omz:plugins:eza' 'size-prefix' si
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' special-dirs true
source $OHMYZSH/oh-my-zsh.sh
# eza hyperlink workaround: oh-my-zsh's bare --hyperlink eats the next arg on newer eza.
_hl_flag="--hyperlink"
if command -v eza >/dev/null && eza --help 2>&1 | grep -q -- '--hyperlink.*<WHEN>'; then
_hl_flag="--hyperlink=always"
fi
for _ea in la ldot lD lDD ll ls lsd lsdl lS lT; do
(( $+aliases[$_ea] )) && alias "$_ea"="${aliases[$_ea]} $_hl_flag"
done
unset _ea _hl_flag
# zoxide: frecency-based directory jumping.
command -v zoxide >/dev/null && eval "$(zoxide init zsh)" 2>/dev/null
# bat: colored `cat` and colored man pages.
if command -v bat >/dev/null; then
alias cat='bat'
export BAT_THEME="${BAT_THEME:-Monokai Extended}"
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANROFFOPT='-c'
fi
# delta: prettier git diffs as git's pager.
command -v delta >/dev/null && export GIT_PAGER='delta'
alias c='clear'
alias q="exit"
alias usedev='use_dev_branch'
alias usemaster='use_master_branch'
alias nbstat=$'netbird status --json | jq -r \'.peers.details[]? | [(.hostname // .fqdn), .netbirdIp, .status] | @tsv\' | column -t -s $\'\\t\''
alias open-ports="ss -tulpn | grep LISTEN"
alias yeet='yay -Rcs'
# Auto-update zshrc, zsh-functions, and starship config on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
if [[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]]; then
tmp=/tmp/.zshrc.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_URL" -o "$tmp" 2>/dev/null \
&& [[ -f "$tmp" ]] && zsh -n "$tmp" 2>/dev/null \
&& ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then
echo "Updating zshrc..."
mv "$tmp" "$HOME/.zshrc" && exec zsh
fi
rm -f "$tmp"
# zsh-functions
ftmp=/tmp/.zsh-functions.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-functions.zsh" -o "$ftmp" 2>/dev/null \
&& [[ -f "$ftmp" ]] && ! cmp -s "$ftmp" "$ZSH_CONFIG/zsh-functions.zsh" 2>/dev/null; then
echo "Updating zsh-functions..."
mv "$ftmp" "$ZSH_CONFIG/zsh-functions.zsh"
else
rm -f "$ftmp"
fi
# starship config
if command -v starship >/dev/null; then
stmp=$(mktemp)
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/starship.toml" -o "$stmp" 2>/dev/null \
&& [[ -f "$stmp" ]] && ! cmp -s "$stmp" "$HOME/.config/starship.toml" 2>/dev/null; then
mkdir -p "$HOME/.config"
mv "$stmp" "$HOME/.config/starship.toml"
else
rm -f "$stmp"
fi
fi
fi
[[ -f $HOME/.zshrc.local ]] || touch $HOME/.zshrc.local
source $HOME/.zshrc.local
if [[ $FFENABLED != "false" && ( -o interactive || $(tty) == *"pts"* ) ]] && command -v fastfetch >/dev/null; then
fastfetch --config examples/13
fi