diff --git a/.zsh_plugins.txt b/.zsh_plugins.txt deleted file mode 100644 index b867fa8..0000000 --- a/.zsh_plugins.txt +++ /dev/null @@ -1,24 +0,0 @@ -mattmc3/ez-compinit - -# completions -zsh-users/zsh-completions kind:fpath path:src - -loiccoyle/zsh-github-copilot -ohmyzsh/ohmyzsh path:plugins/argocd -ohmyzsh/ohmyzsh path:plugins/common-aliases -ohmyzsh/ohmyzsh path:plugins/git -ohmyzsh/ohmyzsh path:plugins/git-auto-fetch -ohmyzsh/ohmyzsh path:plugins/gh -ohmyzsh/ohmyzsh path:plugins/golang kind:fpath -ohmyzsh/ohmyzsh path:lib/key-bindings.zsh -ohmyzsh/ohmyzsh path:lib/directories.zsh - -# deferred -ohmyzsh/ohmyzsh path:plugins/asdf kind:defer -ohmyzsh/ohmyzsh path:plugins/kubectl kind:defer -zsh-users/zsh-autosuggestions kind:defer -zsh-users/zsh-history-substring-search kind:defer -zsh-users/zsh-syntax-highlighting kind:defer - -# this is last -belak/zsh-utils path:completion diff --git a/.zshenv b/.zshenv index fbd083f..99f499f 100644 --- a/.zshenv +++ b/.zshenv @@ -1 +1,46 @@ -source ~/aliases.sh +# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md. +# +# Do not modify this file unless you know exactly what you are doing. +# It is strongly recommended to keep all shell customization and configuration +# (including exported environment variables such as PATH) in ~/.zshrc or in +# files sourced from ~/.zshrc. If you are certain that you must export some +# environment variables in ~/.zshenv, do it where indicated by comments below. + +if [ -n "${ZSH_VERSION-}" ]; then + # If you are certain that you must export some environment variables + # in ~/.zshenv (see comments at the top!), do it here: + # + # export GOPATH=$HOME/go + # + # Do not change anything else in this file. + source ~/aliases.sh + + : ${ZDOTDIR:=~} + setopt no_global_rcs + [[ -o no_interactive && -z "${Z4H_BOOTSTRAPPING-}" ]] && return + setopt no_rcs + unset Z4H_BOOTSTRAPPING +fi + +Z4H_URL="https://raw.githubusercontent.com/romkatv/zsh4humans/v5" +: "${Z4H:=${XDG_CACHE_HOME:-$HOME/.cache}/zsh4humans/v5}" + +umask o-w + +if [ ! -e "$Z4H"/z4h.zsh ]; then + mkdir -p -- "$Z4H" || return + >&2 printf '\033[33mz4h\033[0m: fetching \033[4mz4h.zsh\033[0m\n' + if command -v curl >/dev/null 2>&1; then + curl -fsSL -- "$Z4H_URL"/z4h.zsh >"$Z4H"/z4h.zsh.$$ || return + elif command -v wget >/dev/null 2>&1; then + wget -O- -- "$Z4H_URL"/z4h.zsh >"$Z4H"/z4h.zsh.$$ || return + else + >&2 printf '\033[33mz4h\033[0m: please install \033[32mcurl\033[0m or \033[32mwget\033[0m\n' + return 1 + fi + mv -- "$Z4H"/z4h.zsh.$$ "$Z4H"/z4h.zsh || return +fi + +. "$Z4H"/z4h.zsh || return + +setopt rcs diff --git a/.zshrc b/.zshrc index 002d189..ed2f2fe 100644 --- a/.zshrc +++ b/.zshrc @@ -1,21 +1,65 @@ -# shellcheck disable=2148,2034,2155,1091,2086,1094 -zmodload zsh/zprof -# ================ # -# Basic ZSH Config # -# ================ # - -[[ -n "$ZSH" ]] || export ZSH="${${(%):-%x}:a:h}" -[[ -n "$ZSH_CUSTOM" ]] || ZSH_CUSTOM="$ZSH/custom" -[[ -n "$ZSH_CACHE_DIR" ]] || ZSH_CACHE_DIR="$ZSH/cache" -if [[ ! -w "$ZSH_CACHE_DIR" ]]; then - ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/antidote" -fi -[[ -d "$ZSH_CACHE_DIR/completions" ]] || mkdir -p "$ZSH_CACHE_DIR/completions" - -# Ensure path arrays do not contain duplicates. -typeset -gU path fpath - -# Additional PATHs +# Personal Zsh configuration file. It is strongly recommended to keep all +# shell customization and configuration (including exported environment +# variables such as PATH) in this file or in files sourced from it. +# +# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md. + +# Periodic auto-update on Zsh startup: 'ask' or 'no'. +# You can manually run `z4h update` to update everything. +zstyle ':z4h:' auto-update 'no' +# Ask whether to auto-update this often; has no effect if auto-update is 'no'. +zstyle ':z4h:' auto-update-days '28' + +# Keyboard type: 'mac' or 'pc'. +zstyle ':z4h:bindkey' keyboard 'mac' + +# Don't start tmux. +zstyle ':z4h:' start-tmux no + +# Mark up shell's output with semantic information. +zstyle ':z4h:' term-shell-integration 'yes' + +# Right-arrow key accepts one character ('partial-accept') from +# command autosuggestions or the whole thing ('accept')? +zstyle ':z4h:autosuggestions' forward-char 'accept' + +# Recursively traverse directories when TAB-completing files. +zstyle ':z4h:fzf-complete' recurse-dirs 'no' + +# Enable direnv to automatically source .envrc files. +# zstyle ':z4h:direnv' enable 'no' +# Show "loading" and "unloading" notifications from direnv. +# zstyle ':z4h:direnv:success' notify 'yes' + +# Enable ('yes') or disable ('no') automatic teleportation of z4h over +# SSH when connecting to these hosts. +# zstyle ':z4h:ssh:example-hostname1' enable 'yes' +# zstyle ':z4h:ssh:*.example-hostname2' enable 'no' +# The default value if none of the overrides above match the hostname. +zstyle ':z4h:ssh:*' enable 'yes' + +# Send these files over to the remote host when connecting over SSH to the +# enabled hosts. +# zstyle ':z4h:ssh:*' send-extra-files '~/.nanorc' '~/.env.zsh' + +zstyle ':z4h:' prompt-at-bottom 'no' + +# Mark up shell's output with semantic information. +zstyle ':z4h:' term-shell-integration 'yes' + +# Clone additional Git repositories from GitHub. +# +# This doesn't do anything apart from cloning the repository and keeping it up-to-date. +z4h install ohmyzsh/ohmyzsh || return +z4h install loiccoyle/zsh-github-copilot || return + +# Install or update core components (fzf, zsh-autosuggestions, etc.) and +# initialize Zsh. After this point console I/O is unavailable until Zsh +# is fully initialized. Everything that requires user interaction or can +# perform network I/O must be done above. Everything else is best done below. +z4h init || return + +# Extend PATH. path=( /opt/homebrew/bin /opt/homebrew/sbin @@ -30,96 +74,80 @@ path=( /usr/local/opt/postgresql@15/bin $path ) -export PATH + +# Export environment variables. +export GPG_TTY=$TTY export XDG_CONFIG_HOME=${HOME}/.config unset ZSH_AUTOSUGGEST_USE_ASYNC +export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -l -g ""' +export FZF_CTRL_T_COMMAND='rg --color=never --files --hidden --follow -g "!.git"' +export FZF_CTRL_T_OPTS='--preview "bat --color=always --style=numbers,changes {}"' + +export EDITOR="nvim" +export AWS_PAGER="" # Set Locale export LANG=en_US export LC_CTYPE=en_US.UTF-8 export LC_ALL=en_US.UTF-8 -# History settings -HISTSIZE=5000 -SAVEHIST=5000 -setopt BANG_HIST # Treat the '!' character specially during expansion. -setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format. -setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. -setopt SHARE_HISTORY # Share history between all sessions. -setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history. -setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again. -setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate. -setopt HIST_FIND_NO_DUPS # Do not display a line previously found. -setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file. -setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry. -setopt HIST_VERIFY # Don't execute immediately upon history expansion. -setopt HIST_BEEP # Beep when accessing nonexistent history. -# setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space. - -# ============= # -# Autoloaders # -# ============= # -fpath+=($ZSH_CACHE_DIR/completions /opt/homebrew/share/zsh/site-functions) -source $HOME/.antidote/antidote.zsh -antidote load -source <(fzf --zsh) +# Source additional local files if they exist. +z4h source ~/.env.zsh -autoload -U +X bashcompinit && bashcompinit +# Use additional Git repositories pulled in with `z4h install`. +# +# This is just an example that you should delete. It does nothing useful. +# z4h source ohmyzsh/ohmyzsh/lib/diagnostics.zsh # source an individual file +z4h load ohmyzsh/ohmyzsh/plugins/gh +z4h load loiccoyle/zsh-github-copilot +z4h source -- $HOME/.asdf/asdf.sh -zsh-defer complete -o nospace -C terraform terraform -zsh-defer complete -o nospace -C terragrunt terragrunt -zsh-defer complete -C 'aws_completer' aws -[[ -f $ZSH_CACHE_DIR/completions/_docker ]] || docker completion zsh > $ZSH_CACHE_DIR/completions/_docker +# Define key bindings. +# z4h bindkey undo Ctrl+/ Shift+Tab # undo the last command line change +# z4h bindkey redo Option+/ # redo the last undone command line change -# ================ # -# PS1 and Random # -# ================ # -# fzf -export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -l -g ""' -export FZF_CTRL_T_COMMAND='rg --color=never --files --hidden --follow -g "!.git"' -export FZF_CTRL_T_OPTS='--preview "bat --color=always --style=numbers,changes {}"' +z4h bindkey z4h-cd-back Shift+Left # cd into the previous directory +z4h bindkey z4h-cd-forward Shift+Right # cd into the next directory +z4h bindkey z4h-cd-up Shift+Up # cd into the parent directory +z4h bindkey z4h-cd-down Shift+Down # cd into a child directory +bindkey '^[|' zsh_gh_copilot_explain # bind Alt+shift+\ to explain +bindkey '^[\' zsh_gh_copilot_suggest # bind Alt+\ to suggest -export EDITOR="nvim" -export AWS_PAGER="" +# Autoload functions. +# autoload -Uz zmv -# zsh -export WORDCHARS="" -setopt menu_complete -unsetopt auto_menu -unsetopt case_glob -setopt glob_complete -setopt multios # enable redirect to multiple streams: echo >file1 >file2 -setopt long_list_jobs # show long list format job notifications -setopt interactivecomments # recognize comments -zstyle ':completion:*:*:*:*:*' menu select - -# asdf -export ASDF_PYTHON_DEFAULT_PACKAGES_FILE=~/Repos/dotfiles/requirements.txt -[[ -f ~/.asdf/plugins/golang/set-env.zsh ]] && { - source ~/.asdf/plugins/golang/set-env.zsh - asdf_update_golang_env - export PATH="$GOPATH/bin:$PATH" - export ASDF_GOLANG_MOD_VERSION_ENABLED=true -} - -# zsh gh copilot configuration -bindkey '^[|' zsh_gh_copilot_explain # bind Alt+shift+\ to explain -bindkey '^[\' zsh_gh_copilot_suggest # bind Alt+\ to suggest - -# ===================== # -# Aliases and Functions # -# ===================== # +# completions +[[ -n "$ZSH_CACHE_DIR" ]] || ZSH_CACHE_DIR="$ZSH/cache" +[[ -d "$ZSH_CACHE_DIR/completions" ]] || mkdir -p "$ZSH_CACHE_DIR/completions" +fpath+=($ZSH_CACHE_DIR/completions /opt/homebrew/share/zsh/site-functions) +complete -o nospace -C terraform terraform +complete -o nospace -C terragrunt terragrunt +complete -C 'aws_completer' aws +[[ -f $ZSH_CACHE_DIR/completions/_docker ]] || docker completion zsh >$ZSH_CACHE_DIR/completions/_docker + +# Define aliases. if [[ -f $HOME/aliases.sh ]]; then source $HOME/aliases.sh fi [[ -f $HOME/corp-aliases.sh ]] && source $HOME/corp-aliases.sh -# ================ # -# Kubectl Contexts # -# ================ # -# Load all contexts -export KUBECONFIG=$HOME/.kube/config -export KUBECTL_EXTERNAL_DIFF="kdiff" -export KUBERNETES_EXEC_INFO='{"apiVersion": "client.authentication.k8s.io/v1beta1"}' +# Add flags to existing aliases. +alias ll="${aliases[ls]:-ls} -la" -eval "$(starship init zsh)" +# Set shell options: http://zsh.sourceforge.net/Doc/Release/Options.html. +setopt glob_dots # no special treatment for file names with a leading dot +# History settings +HISTSIZE=5000 +SAVEHIST=5000 +setopt bang_hist # Treat the '!' character specially during expansion. +setopt extended_history # Write the history file in the ":start:elapsed;command" format. +setopt inc_append_history # Write to the history file immediately, not when the shell exits. +setopt share_history # Share history between all sessions. +setopt hist_expire_dups_first # Expire duplicate entries first when trimming history. +setopt hist_ignore_dups # Don't record an entry that was just recorded again. +setopt hist_ignore_all_dups # Delete old recorded entry if new entry is a duplicate. +setopt hist_find_no_dups # Do not display a line previously found. +setopt hist_save_no_dups # Don't write duplicate entries in the history file. +setopt hist_reduce_blanks # Remove superfluous blanks before recording entry. +setopt hist_verify # Don't execute immediately upon history expansion. +setopt hist_beep # Beep when accessing nonexistent history. diff --git a/aliases.sh b/aliases.sh index 86b1841..047c61b 100755 --- a/aliases.sh +++ b/aliases.sh @@ -1,7 +1,6 @@ #!/bin/zsh function take() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" } -compdef _directories take alias ls='eza --icons --group-directories-first' alias ll='eza --icons --group-directories-first -l' ### Helper functions ###