Skip to content

Commit

Permalink
Update Zsh: update p10k, move to z4h, more tidying
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Hoekstra <[email protected]>
  • Loading branch information
shoekstra committed May 18, 2023
1 parent fd0a601 commit 42ab3cd
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 282 deletions.
13 changes: 0 additions & 13 deletions files/zsh/fzf.zsh

This file was deleted.

131 changes: 101 additions & 30 deletions files/zsh/p10k.zsh

Large diffs are not rendered by default.

53 changes: 0 additions & 53 deletions files/zsh/zimrc

This file was deleted.

1 change: 0 additions & 1 deletion files/zsh/zsh-dircolors.config

This file was deleted.

54 changes: 40 additions & 14 deletions files/zsh/zshenv
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
# Start configuration added by Zim install {{{
#
# User configuration sourced by all invocations of the shell
# 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.

: ${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}"

# Define Zim location
: ${ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim}
# }}} End configuration added by Zim install
umask o-w

# Use Neovim as the default editor
export EDITOR=nvim
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

# Set locale
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
export LANGUAGE=en_GB.UTF-8
. "$Z4H"/z4h.zsh || return

export GITCD_HOME=~/git
export GITCD_USEHOST=false
setopt rcs
238 changes: 79 additions & 159 deletions files/zsh/zshrc
Original file line number Diff line number Diff line change
@@ -1,187 +1,107 @@
# Source chtf
if [[ ! -f /usr/local/opt/chtf/share/chtf/chtf.sh ]]; then
echo "Installing chtf..."
brew install Yleisradio/terraforms/chtf > /dev/null 2>&1
source "/usr/local/opt/chtf/share/chtf/chtf.sh"
else
source "/usr/local/opt/chtf/share/chtf/chtf.sh"
fi

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
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

# Start configuration added by Zim install {{{
# 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.
#
# User configuration sourced by interactive shells
#

# -----------------
# Zsh configuration
# -----------------
# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md.

#
# History
#
# Periodic auto-update on Zsh startup: 'ask' or 'no'.
# You can manually run `z4h update` to update everything.
zstyle ':z4h:' auto-update 'yes'
# Ask whether to auto-update this often; has no effect if auto-update is 'no'.
zstyle ':z4h:' auto-update-days '28'

# Remove older command from the history if a duplicate is to be added.
setopt HIST_IGNORE_ALL_DUPS
# Keyboard type: 'mac' or 'pc'.
zstyle ':z4h:bindkey' keyboard 'mac'

#
# Input/output
#
# Start tmux if not already in tmux.
zstyle ':z4h:' start-tmux command tmux -u new -A -D -t z4h

# Set editor default keymap to emacs (`-e`) or vi (`-v`)
bindkey -e
# Whether to move prompt to the bottom when zsh starts and on Ctrl+L.
zstyle ':z4h:' prompt-at-bottom 'yes'

# Prompt for spelling correction of commands.
#setopt CORRECT
# Mark up shell's output with semantic information.
zstyle ':z4h:' term-shell-integration 'yes'

# Customize spelling correction prompt.
#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
# Right-arrow key accepts one character ('partial-accept') from
# command autosuggestions or the whole thing ('accept')?
zstyle ':z4h:autosuggestions' forward-char 'accept'

# Remove path separator from WORDCHARS.
WORDCHARS=${WORDCHARS//[\/]}
# Recursively traverse directories when TAB-completing files.
zstyle ':z4h:fzf-complete' recurse-dirs 'yes'

# Enable direnv to automatically source .envrc files.
zstyle ':z4h:direnv' enable 'yes'
# Show "loading" and "unloading" notifications from direnv.
zstyle ':z4h:direnv:success' notify 'yes'

# --------------------
# Module configuration
# --------------------
# 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 'no'

#
# completion
#

# Set a custom path for the completion dump file.
# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zcompdump is used.
#zstyle ':zim:completion' dumpfile "${ZDOTDIR:-${HOME}}/.zcompdump-${ZSH_VERSION}"

#
# git
#
# 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'

# Set a custom prefix for the generated aliases. The default prefix is 'G'.
zstyle ':zim:git' aliases-prefix 'g'

# Clone additional Git repositories from GitHub.
#
# input
#
# This doesn't do anything apart from cloning the repository and keeping it
# up-to-date. Cloned files can be used after `z4h init`.
z4h install agkozak/zsh-z || return
z4h install viko16/gitcd.plugin.zsh || return
z4h install zimfw/git || return
z4h install zimfw/utility || return

# Append `../` to your input for each `.` you type after an initial `..`
#zstyle ':zim:input' double-dot-expand yes
# 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

#
# termtitle
#
# Extend PATH.
path=(~/bin ~/go/bin ~/.krew/bin $path)

# Set a custom terminal title format using prompt expansion escape sequences.
# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
# If none is provided, the default '%n@%m: %~' is used.
#zstyle ':zim:termtitle' format '%1~'
# Export environment variables.
export GPG_TTY=$TTY

#
# zsh-autosuggestions
#
# Source additional local files if they exist.
z4h source ~/.env.zsh

# Customize the style that the suggestions are shown with.
# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style
#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
# Source remaining dot files until they're migrated to nix or z4h
z4h source ~/.zaliases
z4h source ~/.zfunctions
z4h source ~/.chef/functions.zsh

#
# zsh-syntax-highlighting
#

# Set what highlighters will be used.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
# Use additional Git repositories pulled in with `z4h install`.
z4h load agkozak/zsh-z # jump to frequently visited directories
z4h load zimfw/git # git aliases
z4h load zimfw/utility # utility aliases and functions
z4h source viko16/gitcd.plugin.zsh/gitcd.plugin.zsh # git clone and change directory by a single command

# Customize the main highlighter styles.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it
#typeset -A ZSH_HIGHLIGHT_STYLES
#ZSH_HIGHLIGHT_STYLES[comment]='fg=10'
# 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

# ------------------
# Initialize modules
# ------------------
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

if [[ ${ZIM_HOME}/init.zsh -ot ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
# Update static initialization script if it's outdated, before sourcing it
source ${ZIM_HOME}/zimfw.zsh init -q
fi
source ${ZIM_HOME}/init.zsh
# Autoload functions.
autoload -Uz zmv

# ------------------------------
# Post-init module configuration
# ------------------------------
# Define functions and completions.
function md() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" }
compdef _directories md

#
# zsh-history-substring-search
#
# Define named directories: ~w <=> Windows home directory on WSL.
[[ -z $z4h_win_home ]] || hash -d w=$z4h_win_home

# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

# Bind up and down keys
zmodload -F zsh/terminfo +p:terminfo
if [[ -n ${terminfo[kcuu1]} && -n ${terminfo[kcud1]} ]]; then
bindkey ${terminfo[kcuu1]} history-substring-search-up
bindkey ${terminfo[kcud1]} history-substring-search-down
fi

bindkey '^P' history-substring-search-up
bindkey '^N' history-substring-search-down
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
# }}} End configuration added by Zim install

bindkey "^[[1~" beginning-of-line # Move to beginning of line with Fn+Left
bindkey "^[[4~" end-of-line # Move to end of line with Fn+Right

# Add directories to path if they exist
function prependtopath {
if [ -d $1 ] ; then
path=($1 $path)
fi
}

typeset -U path # Prevent duplicate elements in path.

# These are added in reverse order because they're prepended to the path. List
# them in reverse precedence.
prependtopath ~/.krew/bin
prependtopath ~/go/bin
prependtopath ~/bin

export PATH # Export again to make updated path available to subshells.

# Source files if they exist
function zsource {
[[ -s "$1" ]] && source $1
}

zsource ~/.p10k.zsh # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
zsource ~/.fzf.zsh # Setup fzf

zsource ${HOME}/.zaliases # Load aliases
zsource ${HOME}/.zfunctions # Load functions
zsource ${HOME}/.chef/functions.zsh # Load Chef functions

# Kubernetes
if (($+commands[helm])); then
source <(helm completion zsh)
fi

if (($+commands[kubectl])); then
source <(kubectl completion zsh)
alias k="kubectl"
complete -F __start_kubectl k
fi

autoload -U +X bashcompinit && bashcompinit
(($+commands[aws])) && complete -o nospace -C /usr/local/bin/aws_completer aws
(($+commands[terraform])) && complete -o nospace -C /usr/local/bin/terraform terraform
(($+commands[vault])) && complete -o nospace -C /usr/local/bin/vault vault
# Set shell options: http://zsh.sourceforge.net/Doc/Release/Options.html.
setopt glob_dots # no special treatment for file names with a leading dot
setopt no_auto_menu # require an extra TAB press to open the completion menu
Loading

0 comments on commit 42ab3cd

Please sign in to comment.