# #!/bin/zsh # ZSH helper functions that are needed to load the config trysource() { # Sources file if it exists [[ -f $1 ]] && source $1 } trypath() { # Adds to $PATH if exists [[ -e $1 ]] && path+=($1) } trysource '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' # Darwin-nix path trypath /run/current-system/sw/bin trysource ${HOME}/.nix-profile/etc/profile.d/nix.sh # Nix home-manager trysource ${HOME}/.nix-profile/etc/profile.d/hm-session-vars.sh trysource /etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh trypath /etc/profiles/per-user/$USER/bin # Zplug trysource ${HOME}/.zplug/init.zsh # Install plugins if there are plugins that have not been installed trysource ${HOME}/.zpackages.zsh if ! zplug check; then printf "Install? [y/N]: " if read -q; then echo; zplug install fi fi zplug load ZSH_THEME="powerlevel10k/powerlevel10k" trysource "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" # If running from tty1 start sway if [ "$(tty)" = "/dev/tty1" ]; then if command -v sway > /dev/null 2>&1; then #exec dbus-launch --sh-syntax --exit-with-session /usr/bin/sway exec sway fi fi # Basic zsh config. ZDOTDIR=${ZDOTDIR:-${HOME}} ZSHDDIR="${HOME}/.config/zsh.d" HISTFILE="${ZDOTDIR}/.zsh_history" HISTSIZE='10000' SAVEHIST="${HISTSIZE}" BROWSER="firefox" # Let jobs continue even if shell exits setopt NO_HUP # https://zsh.sourceforge.io/Doc/Release/Expansion.html setopt NO_CASE_GLOB setopt NUMERIC_GLOB_SORT setopt EXTENDED_GLOB setopt extended_glob # Turn on command substitution in the prompt (and parameter expansion and arithmetic expansion). setopt promptsubst # Completion. autoload -Uz compinit bashcompinit zle -N edit-command-line # Configure completion style zstyle ':completion:*' menu select=2 zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' zstyle ':completion:*' accept-exact '*(N)' zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ${HOME}/.zsh/cache zstyle ':completion:*:descriptions' format '%U%F{cyan}%d%f%u' zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' zstyle ":completion:*:commands" rehash 1 zstyle ':completion:*:sudo:*' environ PATH="$SUDO_PATH:$PATH" # If running as root and nice >0, renice to 0. if [ "$USER" = 'root' ] && [ "$(cut -d ' ' -f 19 /proc/$$/stat)" -gt 0 ]; then renice -n 0 -p "$$" && echo "# Adjusted nice level for current shell to 0." fi # Ignore duplicate in history. setopt hist_ignore_dups # Prevent record in history entry if preceding them with at least one space setopt hist_ignore_space # Nobody need flow control anymore. Troublesome feature. # stty -ixon setopt noflowcontrol # For autocompletion of command line switches for aliases setopt COMPLETE_ALIASES # key binding bindkey "\e[1~" beginning-of-line # Home bindkey "\e[4~" end-of-line # End bindkey "\e[5~" beginning-of-history # PageUp bindkey "\e[6~" end-of-history # PageDown bindkey '\e[H' beginning-of-line # Home bindkey '\e[F' end-of-line # End bindkey "\e[2~" quoted-insert # Ins bindkey "\e[3~" delete-char # Del bindkey "\e[5C" forward-word bindkey "\eOc" emacs-forward-word bindkey "\e[5D" backward-word bindkey "\eOd" emacs-backward-word bindkey "\e\e[C" forward-word bindkey "\e\e[D" backward-word bindkey "\e[Z" reverse-menu-complete # Shift+Tab # for non RH/Debian xterm, can't hurt for RH/Debian xterm bindkey "\eOH" beginning-of-line # Home bindkey "\eOF" end-of-line # End # History bindkey "^[[A" history-beginning-search-backward bindkey "^[[B" history-beginning-search-forward # brings back . bindkey -M viins '\e.' insert-last-word # set backspace=indent,eol,start # but for vi mode bindkey "^?" backward-delete-char (( $+commands[thefuck] )) && eval $(thefuck --alias) (( $+commands[direnv] )) && eval "$(direnv hook zsh)" [[ -f /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv)" # Add local tools to PATH trypath ${HOME}/.scripts trypath ${HOME}/bin trypath ${HOME}/.local/bin trypath ${HOME}/.emacs.d/bin trypath ${HOME}/.config/emacs/bin trypath ${HOME}/src/klipper_estimator/target/release # Dev tools to PATH trypath ${HOME}/src/circuitpython/mpy-cross trypath ${HOME}/.nimble/bin trypath ${HOME}/.cargo/bin trysource ${HOME}/.cargo/env if [ "$OS_DETECTION" = "mac" ]; then trysource ${HOME}/.iterm2_shell_integration.zsh trypath ${HOME}/Library/Python/3.10/bin fi # Make sure and aliases are loaded trysource $HOME/.zsh_aliases # Keep before term colors trysource ${HOME}/.zoxide && eval "$(zoxide init zsh)" trysource ${HOME}/.fzf.zsh # Yadm tab complete fix function _yadm-add(){ yadm_path="$(yadm rev-parse --show-toplevel)" yadm_options=$(yadm status --porcelain=v1 | awk -v yadm_path=${yadm_path} '{printf "%s/\"%s\"\\:\"%s\" ", yadm_path, $2, $1 }' ) _alternative \ "args:custom arg:(($yadm_options))" \ 'files:filename:_files' } # Sets term colors, and fixes problems with SSH for pywal/wpg # Always leave near the end. Disabled on Mac if [[ "$OSTYPE" != "darwin"* ]]; then if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then SESSION_TYPE=remote/ssh else case $(ps -o comm= -p $PPID) in sshd|*/sshd) SESSION_TYPE=remote/ssh;; esac # Only change term colors for local system [[ -f ${XDG_CONFIG_HOME}/wpg/sequences ]] && command cat ${XDG_CONFIG_HOME}/wpg/sequences [[ -f ${HOME}/.cache/wal/sequences ]] && command cat ${HOME}/.cache/wal/sequences fi fi # To customize prompt, run `p10k configure` or edit ${HOME}/.p10k.zsh. trysource ${HOME}/.p10k.zsh