Cleaned up zsh setup

This commit is contained in:
2024-11-13 20:23:55 -05:00
parent 56234842cf
commit d1427cba64
11 changed files with 36 additions and 2 deletions

1719
.config/zsh/.p10k.zsh Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,9 @@
zsh-users/zsh-autosuggestions
zsh-users/zsh-syntax-highlighting
zsh-users/zsh-completions
# todo is this better than zsh-autocomplete below?
# Aloxaf/fzf-tab
# marlonrichert/zsh-autocomplete
romkatv/powerlevel10k

View File

@@ -0,0 +1,9 @@
fpath+=( $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions )
source $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
fpath+=( $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-syntax-highlighting )
source $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh
fpath+=( $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-completions )
source $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-completions/zsh-completions.plugin.zsh
fpath+=( $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-romkatv-SLASH-powerlevel10k )
source $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-romkatv-SLASH-powerlevel10k/powerlevel10k.zsh-theme
source $HOME/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-romkatv-SLASH-powerlevel10k/powerlevel9k.zsh-theme

68
.config/zsh/.zshrc Normal file
View File

@@ -0,0 +1,68 @@
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zsh/.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
# Aliases
alias c='clear'
alias open='xdg-open'
alias lg="lazygit"
alias nv="nvim"
alias ts="tmux new-session -A -s"
alias tl="tmux ls"
# Completions
fpath=($HOME/.zsh/completions $fpath)
autoload -U compinit; compinit
_comp_options+=(globdots) # With hidden
# Load antidote & plugins
source ${ZDOTDIR}/antidote/antidote.zsh
antidote load
# fzf keybindings
if type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files'
export FZF_DEFAULT_OPTS='-m --height 50% --border'
fi
source /usr/share/doc/fzf/examples/completion.zsh
source /usr/share/doc/fzf/examples/key-bindings.zsh
# ----------------- Replacement for standard tools ----------------- #
# ls -> eza aliases
# https://gist.github.com/AppleBoiy/04a249b6f64fd0fe1744aff759a0563b
# TODO: https://denisrasulev.medium.com/eza-the-best-ls-command-replacement-9621252323e
alias ls='eza'
alias l='eza -lbF --git'
alias ll='eza -lbGF --git'
alias llm='eza -lbGd --git --sort=modified'
alias la='eza -lbhHigUmuSa --time-style=long-iso --git --color-scale'
alias lx='eza -lbhHigUmuSa@ --time-style=long-iso --git --color-scale'
# specialty views
alias lS='eza -1'
alias lt='eza --tree --level=2'
alias l.="eza -a | grep -E '^\.'"
# cd -> zoxide
eval "$(zoxide init zsh)"
alias cd="z"
alias cdi="zi"
# man -> tldr
# No alias
# cat -> bat
export BAT_THEME="base16"
export BAT_STYLE="numbers,changes,header"
alias cat="bat"
alias -g -- -h='-h 2>&1 | bat --language=help --style=plain'
alias -g -- --help='--help 2>&1 | bat --language=help --style=plain'
# direnv hook
eval "$(direnv hook zsh)"
# To customize prompt, run `p10k configure` or edit ~/.zsh/.p10k.zsh.
[[ ! -f "$ZDOTDIR/.p10k.zsh" ]] || source $ZDOTDIR/.p10k.zsh

1
.config/zsh/antidote Submodule

Submodule .config/zsh/antidote added at 4858ab37c1

88
.config/zsh/bd.zsh Normal file
View File

@@ -0,0 +1,88 @@
# shellcheck shell=bash
bd () {
(($#<1)) && {
printf -- 'usage: %s <name-of-any-parent-directory>\n' "${0}"
printf -- ' %s <number-of-folders>\n' "${0}"
return 1
} >&2
local requestedDestination="${1}"
local -a parents=(${(ps:/:)"${PWD}"})
local numParents
local dest
local i
local parent
# prepend root to the parents array
parents=('/' "${parents[@]}")
# Remove the current directory since it isn't a parent
shift -p parents
# Get the number of parent directories
numParents="$(( ${#parents[@]}))"
# Build dest and 'cd' to it by looping over the parents array in reverse
dest='./'
for i in $(seq "${numParents}" -1 1); do
parent="${parents[${i}]}"
dest+='../'
if [[ "${requestedDestination}" == "${parent}" ]]; then
cd $dest
return $?
fi
done
# If the user provided an integer, go up as many times as asked
dest='./'
if [[ "${requestedDestination}" == <-> ]]; then
if [[ "${requestedDestination}" -gt "${numParents}" ]]; then
printf -- '%s: Error: Can not go up %s times (not enough parent directories)\n' "${0}" "${requestedDestination}"
return 1
fi
for i in {1.."${requestedDestination}"}; do
dest+='../'
done
cd "${dest}"
return $?
fi
# If the above methods fail
printf -- '%s: Error: No parent directory named "%s"\n' "${0}" "${requestedDestination}"
return 1
}
_bd () {
# Get parents (in reverse order)
local localMatcherList
local -a parents=(${(ps:/:)"${PWD}"})
local numParents
local i
local -a parentsReverse
zstyle -s ':completion:*' 'matcher-list' 'localMatcherList'
# prepend root to the parents array
parents=('/' "${parents[@]}")
# Remove the current directory since it isn't a parent
shift -p parents
# Get the number of parent directories
numParents="$(( ${#parents[@]}))"
parentsReverse=()
for i in $(seq "${numParents}" -1 1); do
parentsReverse+=("${parents[${i}]}")
done
compadd -V 'Parent directories' -M "${localMatcherList}" "$@" -- "${parentsReverse[@]}"
}
compdef _bd bd

102
.config/zsh/completion.zsh Normal file
View File

@@ -0,0 +1,102 @@
# ____ ___ __ __ ____ _ _____ _____ ___ ___ _ _
# / ___/ _ \| \/ | _ \| | | ____|_ _|_ _/ _ \| \ | |
# | | | | | | |\/| | |_) | | | _| | | | | | | | \| |
# | |__| |_| | | | | __/| |___| |___ | | | | |_| | |\ |
# \____\___/|_| |_|_| |_____|_____| |_| |___\___/|_| \_|
#
# +---------+
# | General |
# +---------+
# source ./gambit.zsh
# Load more completions
fpath=($DOTFILES/zsh/plugins/zsh-completions/src $fpath)
# Should be called before compinit
zmodload zsh/complist
# Use hjlk in menu selection (during completion)
# Doesn't work well with interactive mode
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect '^xg' clear-screen
bindkey -M menuselect '^xi' vi-insert # Insert
bindkey -M menuselect '^xh' accept-and-hold # Hold
bindkey -M menuselect '^xn' accept-and-infer-next-history # Next
bindkey -M menuselect '^xu' undo # Undo
autoload -U compinit; compinit
_comp_options+=(globdots) # With hidden files
# Only work with the Zsh function vman
# See $DOTFILES/zsh/scripts.zsh
compdef vman="man"
# +---------+
# | Options |
# +---------+
# setopt GLOB_COMPLETE # Show autocompletion menu with globs
setopt MENU_COMPLETE # Automatically highlight first element of completion menu
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
# +---------+
# | zstyles |
# +---------+
# Ztyle pattern
# :completion:<function>:<completer>:<command>:<argument>:<tag>
# Define completers
zstyle ':completion:*' completer _extensions _complete _approximate
# Use cache for commands using cache
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
# Complete the alias when _expand_alias is used as a function
zstyle ':completion:*' complete true
zle -C alias-expension complete-word _generic
bindkey '^Xa' alias-expension
zstyle ':completion:alias-expension:*' completer _expand_alias
# Use cache for commands which use it
# Allow you to select in a menu
zstyle ':completion:*' menu select
# Autocomplete options for cd instead of directory stack
zstyle ':completion:*' complete-options true
zstyle ':completion:*' file-sort modification
zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f'
zstyle ':completion:*:*:*:*:descriptions' format '%F{blue}-- %D %d --%f'
zstyle ':completion:*:*:*:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:*:*:*:warnings' format ' %F{red}-- no matches found --%f'
# zstyle ':completion:*:default' list-prompt '%S%M matches%s'
# Colors for files and directory
zstyle ':completion:*:*:*:*:default' list-colors ${(s.:.)LS_COLORS}
# Only display some tags for the command cd
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
# zstyle ':completion:*:complete:git:argument-1:' tag-order !aliases
# Required for completion to be in good groups (named after the tags)
zstyle ':completion:*' group-name ''
zstyle ':completion:*:*:-command-:*:*' group-order aliases builtins functions commands
# See ZSHCOMPWID "completion matching control"
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' keep-prefix true
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'

View File

@@ -0,0 +1,51 @@
#compdef tldr
_applications() {
local -a commands
if commands=(${(uonzf)"$(tldr --list 2>/dev/null)"//:/\\:}); then
_describe -t commands 'command' commands
fi
}
_tealdeer() {
local I="-h --help -v --version"
integer ret=1
local -a args
args+=(
"($I -l --list)"{-l,--list}"[List all commands in the cache]"
"($I -f --render)"{-f,--render}"[Render a specific markdown file]:file:_files"
"($I -p --platform)"{-p,--platform}'[Override the operating system]:platform:((
linux
macos
sunos
windows
android
freebsd
netbsd
openbsd
))'
"($I -L --language)"{-L,--language}"[Override the language settings]:lang"
"($I -u --update)"{-u,--update}"[Update the local cache]"
"($I)--no-auto-update[If auto update is configured, disable it for this run]"
"($I -c --clear-cache)"{-c,--clear-cache}"[Clear the local cache]"
"($I)--pager[Use a pager to page output]"
"($I -r --raw)"{-r,--raw}"[Display the raw markdown instead of rendering it]"
"($I -q --quiet)"{-q,--quiet}"[Suppress informational messages]"
"($I)--show-paths[Show file and directory paths used by tealdeer]"
"($I)--seed-config[Create a basic config]"
"($I)--color[Controls when to use color]:when:((
always
auto
never
))"
'(- *)'{-h,--help}'[Display help]'
'(- *)'{-v,--version}'[Show version information]'
'1: :_applications'
)
_arguments $args[@] && ret=0
return ret
}
_tealdeer