1
0

add zsh completion setup

This commit is contained in:
2025-02-13 21:42:00 +01:00
parent ad41074de5
commit 7c2b4b2fa6
4 changed files with 113 additions and 23 deletions

View File

@@ -2,12 +2,18 @@
alias tree='tree -CF --du -h' alias tree='tree -CF --du -h'
# enable color support of ls and also add handy aliases
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# alias tf="aws-vault exec feedzai-main -d 8h -- terraform" # alias tf="aws-vault exec feedzai-main -d 8h -- terraform"
# alias tfi="aws-vault exec feedzai-main -d 8h -- terraform init" # alias tfi="aws-vault exec feedzai-main -d 8h -- terraform init"
# alias tfp="aws-vault exec feedzai-main -d 8h -- terraform plan -lock=false" # alias tfp="aws-vault exec feedzai-main -d 8h -- terraform plan -lock=false"
# alias tfa="aws-vault exec feedzai-main -d 8h -- terraform apply" # alias tfa="aws-vault exec feedzai-main -d 8h -- terraform apply"
# alias tfu="aws-vault exec feedzai-main -d 8h -- terraform get -update" # alias tfu="aws-vault exec feedzai-main -d 8h -- terraform get -update"
# #
# alias tg="aws-vault exec feedzai-main -d 8h -- terragrunt" # alias tg="aws-vault exec feedzai-main -d 8h -- terragrunt"
# alias tgi="aws-vault exec feedzai-main -d 8h -- terragrunt init" # alias tgi="aws-vault exec feedzai-main -d 8h -- terragrunt init"
# alias tgp="aws-vault exec feedzai-main -d 8h -- terragrunt plan -lock=false" # alias tgp="aws-vault exec feedzai-main -d 8h -- terragrunt plan -lock=false"

View File

@@ -1,3 +1,22 @@
. "$HOME/.cargo/env" export EDITOR="nvim"
export VISUAL="nvim"
if [ -f ~/.zshrc ]; then . ~/.zshrc; fi export HISTFILE=~/.zsh_history
export HISTSIZE=5000000
export SAVEHIST=$HISTSIZE
export CLICOLOR=1
export DOTFILES="$HOME/dotfiles"
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# Man pages
export MANPAGER='nvim +Man!'
export SSH_ENV="$HOME/.ssh/agent-environment"
export PATH=~/.local/bin:$PATH
. "$HOME/.cargo/env"

View File

@@ -1,7 +1,3 @@
export HISTFILE=~/.zsh_history
export HISTSIZE=5000000
export SAVEHIST=$HISTSIZE
setopt INC_APPEND_HISTORY setopt INC_APPEND_HISTORY
setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format.
setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history.
@@ -9,28 +5,17 @@ setopt HIST_FIND_NO_DUPS # Do not display a previously found event.
setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate. setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate.
setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again.
setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. setopt HIST_IGNORE_SPACE # Do not record an event starting with a space.
setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. unsetopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file.
setopt SHARE_HISTORY # Share history between all sessions. setopt SHARE_HISTORY # Share history between all sessions.
bindkey "^[[1;5C" forward-word bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word bindkey "^[[1;5D" backward-word
source $DOTFILES/zsh/completion.zsh
# make less more friendly for non-text input files, see lesspipe(1) # make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# enable color support of ls and also add handy aliases
export CLICOLOR=1
zstyle ':completion:*:default' list-colors ''
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
SSH_ENV="$HOME/.ssh/agent-environment"
function start_ssh_agent { function start_ssh_agent {
echo "Initialising new SSH agent..." echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >"${SSH_ENV}" /usr/bin/ssh-agent | sed 's/^echo/#echo/' >"${SSH_ENV}"
@@ -56,8 +41,6 @@ if [ -f ~/.zsh_aliases ]; then
. ~/.zsh_aliases . ~/.zsh_aliases
fi fi
export PATH=~/.local/bin:$PATH
function set_win_title(){ function set_win_title(){
echo -ne "\033]0; $(basename "$PWD") \007" echo -ne "\033]0; $(basename "$PWD") \007"
} }

82
zsh/completion.zsh Normal file
View File

@@ -0,0 +1,82 @@
# ____ ___ __ __ ____ _ _____ _____ ___ ___ _ _
# / ___/ _ \| \/ | _ \| | | ____|_ _|_ _/ _ \| \ | |
# | | | | | | |\/| | |_) | | | _| | | | | | | | \| |
# | |__| |_| | | | | __/| |___| |___ | | | | |_| | |\ |
# \____\___/|_| |_|_| |_____|_____| |_| |___\___/|_| \_|
#
# +---------+
# | General |
# +---------+
# source ./gambit.zsh
# Load more completions
fpath=($DOTFILES/zsh/plugins/zsh-completions/src $fpath)
# Should be called before compinit
zmodload zsh/complist
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 "~/.cache/zsh/.zcompcache"
# Complete the alias when _expand_alias is used as a function
zstyle ':completion:*' complete true
# 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)"}%%[# ]*}//,/ })'