Skip to content

Commit

Permalink
Overhault zsh configuration (#67)
Browse files Browse the repository at this point in the history
* feat: using zinit

* feat: reenable history config

* feat: reenable vim key bindings

* feat: cleanup completion

* feat: a lot more

* feat: some optimizing

* feat: fallback to normal beginning search

Using history-beginning-search-*-end has issues with fixing new search
patterns on browsing the history. Using the version without having the
cursor jumping to the end does not show this behaviour.

* feat: let zinit handle wezterm integration

* refactor: make syntax highlighting last again

* feat: source fzf shell integration

* feat: finish fzf integration
  • Loading branch information
mrolli authored Oct 7, 2024
1 parent 01b3f46 commit 7efa602
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 56 deletions.
27 changes: 19 additions & 8 deletions config/zsh/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

# Initialize and configure autocompletion
# Guide about style: https://thevaluable.dev/zsh-completion-guide-examples/
if command -v brew &>/dev/null

# Load Homebrew featured completions if available
if [ -d "$HOMEBREW_PREFIX/share/zsh/site-functions" ]
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
FPATH="$(brew --prefix)/share/zsh-completions:${FPATH}"
FPATH="$ZDOTDIR/zsh-completions:${FPATH}"
FPATH="$HOMEBREW_PREFIX/share/zsh/site-functions:${FPATH}"
fi

autoload -U compinit && compinit -d $ZCACHEDIR/zcompdump

# Replay recored compdef calls
zinit cdreplay -q

_comp_options+=(globdots) # with hidden files
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' completer _extensions _complete
#zstyle ':completion:*' completer _extensions _complete _approximate
zstyle ':completion:*' menu select
zstyle ':completion:*' menu no
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'
Expand All @@ -25,6 +29,8 @@ zstyle ':completion:*:*:-command-:*:*' group-order alias builtins functions comm
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*' complete-options true
zstyle ':completion:*' rehash true
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'

# Activate 1password autocompletion if 1password is avaialble
if command -v op &>/dev/null; then
Expand All @@ -36,10 +42,15 @@ if command -v wezterm &>/dev/null; then
eval "$(wezterm shell-completion --shell zsh)"
fi

# Active fzf autocompletion and shell integration
if command -v fzf &>/dev/null; then
eval "$(fzf --zsh)"
fi

# Activate azure autocompletion if az is avaialble
if command -v az &>/dev/null; then
autoload bashcompinit && bashcompinit
source $(brew --prefix)/etc/bash_completion.d/az
autoload autload -U +X bashcompinit && bashcompinit && \
source $HOMEBREW_PREFIX/etc/bash_completion.d/az
fi

# Activate terraform autocompletion if terraform is avaialble
Expand Down
3 changes: 3 additions & 0 deletions config/zsh/macos.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ command -v brew &>/dev/null && eval "$(brew shellenv)"
[ -d "$HOMEBREW_PREFIX/opt/ruby/bin" ] && \
export PATH="$HOMEBREW_PREFIX/opt/ruby/bin:$PATH"

# Add binary path of libpq if available
[ -d "$HOMEBREW_PREFIX/opt/libpq/bin" ] && PATH="$HOMEBREW_PREFIX/opt/libpq/bin:$PATH"

[ -f "$HOME/.vagrant.d/vcloud_token.sh" ] && source "$HOME/.vagrant.d/vcloud_token.sh"
11 changes: 10 additions & 1 deletion config/zsh/zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export ZDATADIR="${XDG_DATA_HOME:-$HOME/.local/share}/zsh"
export ZCACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh"

# Highlight section titles in manual pages in yellow.
export LESS_TERMCAP_md="$(tput setaf 136)"
export LESS_TERMCAP_md="$(tput bold; tput setaf 136)"
# Don’t clear the screen after quitting a manual page.
export MANPAGER='less -X'

Expand All @@ -27,6 +27,11 @@ export EDITOR="nvim"
export SVNEDITOR="nvim"
export VISUAL="nvim"

# Colors
unset LSCOLORS
export CLICOLOR=1
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43:or=40;31;07'

# Make less the default pager, and specify some useful defaults.
less_options=(
# If the entire text fits on one screen, just show it and quit. (Be more
Expand Down Expand Up @@ -57,3 +62,7 @@ export PAGER='less';

# Vagrant/Packer specific
export PACKER_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/packer"

# Zsh Vi Mode plugin
ZVM_VI_SURROUND_BINDKEY='s-prefix'
ZVM_INIT_MODE=sourcing
84 changes: 37 additions & 47 deletions config/zsh/zshrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
#!/usr/bin/env zsh
# Setup Zinit plugin manager
ZINIT_HOME="$XDG_DATA_HOME/zinit/zinit.git"
if [ ! -d "$ZINIT_HOME" ]; then
mkdir -p "$(dirname "$ZINIT_HOME")"
git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi

[[ -v $ZDATADIR ]] || source ~/.zshenv
source "$ZINIT_HOME/zinit.zsh"

mkdir -p "$ZDATADIR"/{,plugins} "$ZCACHEDIR"
# Add in zsh plugins
zinit ice depth=1; zinit light zsh-users/zsh-completions
zinit ice depth=1; zinit light zsh-users/zsh-autosuggestions
zinit ice depth=1; zinit light jeffreytse/zsh-vi-mode
zinit ice depth=1; zinit light Aloxaf/fzf-tab
# See https://wezfurlong.org/wezterm/shell-integration.html
zinit snippet https://raw.githubusercontent.com/wez/wezterm/main/assets/shell-integration/wezterm.sh
# keep syntax highlighting last
zinit ice depth=1; zinit light zdharma-continuum/fast-syntax-highlighting

fpath=($ZDATADIR/plugins $fpath)
# Add direnv and its hook, see https://zdharma-continuum.github.io/zinit/wiki/Direnv-explanation/
zinit from"gh-r" as"program" mv"direnv* -> direnv" \
atclone'./direnv hook zsh > zhook.zsh' atpull'%atclone' \
pick"direnv" src="zhook.zsh" for \
direnv/direnv

# Colors
unset LSCOLORS
export CLICOLOR=1
# On a MacOS machine I want my macos-goodies
if [ "$(uname -s)" = "Darwin" ]; then
zinit ice depth=1; zinit light mrolli/zsh-macos-goodies
fi

# Explicitly set vi mode for key bindings
bindkey -v
export KEYTIMEOUT=1

# History Management - keep plenty of history
HISTFILE=$ZDATADIR/zhistory
HISTSIZE=100000
SAVEHIST=100000
HISTDUP=erase
setopt APPEND_HISTORY # Append history to the history file rather than replace it..
setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format.
#setopt SHARE_HISTORY # Share history between all sessions.
# setopt SHARE_HISTORY # Share history between all sessions.
setopt INC_APPEND_HISTORY_TIME # Append command right after execution.
setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history.
setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again.
Expand All @@ -29,63 +50,32 @@ setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history
setopt HIST_VERIFY # Do not execute immediately upon history expansion.

# search history with up/down arrows based on what's typed in the prompt
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^\e[A" history-beginning-search-backward-end
bindkey "^\e[B" history-beginning-search-forward-end
bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward

# Go to folder path without using cd
setopt AUTO_CD
# Turn off all beeps
unsetopt BEEP
# Turn off autocomplete beeps
# unsetopt LIST_BEEP

# Use colors functions to have color at hand
# See https://github.com/zsh-users/zsh/blob/master/Functions/Misc/colors
autoload -Uz colors && colors
#unsetopt LIST_BEEP

# Source my config files
source "$ZDOTDIR/macos.zsh"
if [ "$(uname -s)" = "Darwin" ]; then
source "$ZDOTDIR/macos.zsh"
fi
source "$ZDOTDIR/completion.zsh"
source "$ZDOTDIR/aliases.zsh"
source "$ZDOTDIR/functions.zsh"

# On a MacOS machine I want my macos-goodies
if [ "$(uname -s)" = "Darwin" ] && [ ! -d "$ZDATADIR/plugins/zsh-macos-goodies" ]; then
git clone https://github.com/mrolli/zsh-macos-goodies.git "$ZDATADIR/plugins/zsh-macos-goodies" &>/dev/null
fi
source "$ZDATADIR/plugins/zsh-macos-goodies/macos-goodies.plugin.zsh"

# App 3rd-party plugins
# See https://github.com/jeffreytse/zsh-vi-mode
if [ ! -d "$ZDATADIR/plugins/zsh-vi-mode" ]; then
git clone https://github.com/jeffreytse/zsh-vi-mode.git "$ZDATADIR/plugins/zsh-vi-mode" &>/dev/null
fi
source "$ZDATADIR/plugins/zsh-vi-mode/zsh-vi-mode.plugin.zsh"
# See https://wezfurlong.org/wezterm/shell-integration.html
if [ ! -f "$ZDATADIR/plugins/wezterm.sh" ]; then
curl -flo "$ZDATADIR/plugins/wezterm.sh" \
"https://raw.githubusercontent.com/wez/wezterm/main/assets/shell-integration/wezterm.sh" \
&>/dev/null
fi
source "$ZDATADIR/plugins/wezterm.sh"


# build the PATH variable
PATH=~/.local/bin:$PATH

# Add Go binary path
[ -d "$HOME/go/bin" ] && PATH="$HOME/go/bin:$PATH"

# Add direnv hook
command -v direnv &>/dev/null && eval "$(direnv hook zsh)"

# Initialize miniconda
[ -x "$HOMEBREW_PREFIX/Caskroom/miniconda/base/bin/conda" ] && \
source "$ZDOTDIR/conda.zsh"
# Make vagrant vcloud token available
[ -f "$HOME/.vagrant.d/vcloud_token.sh" ] && source "$HOME/.vagrant.d/vcloud_token.sh"

# build prompt
eval "$(starship init zsh)"

0 comments on commit 7efa602

Please sign in to comment.