diff --git a/zsh.d/aliases.zsh b/zsh.d/aliases.zsh index d33763e..6e772ea 100755 --- a/zsh.d/aliases.zsh +++ b/zsh.d/aliases.zsh @@ -3,45 +3,81 @@ if [[ -n $LOADED_ALIASES ]]; then return fi +#------------------------------------------------------------------------------ +# Core System Command Overrides +#------------------------------------------------------------------------------ alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' +alias sed=gsed +alias grep=ggrep +alias sort=gsort +alias awk=gawk + +#------------------------------------------------------------------------------ +# File Navigation & Management +#------------------------------------------------------------------------------ alias ll='ls -lah' +alias ls='eza ' +alias dc='cd ' +alias dotfiles='cd ~/Repos/dotfiles' +alias pj='fdf ~/Repos' +alias repos="~/Repos" -### General aliases ### -alias zshrc='${=EDITOR} ${ZDOTDIR:-$HOME}/.zshrc' # Quick access to the .zshrc file -alias watch='watch --color ' +#------------------------------------------------------------------------------ +# Editor Related +#------------------------------------------------------------------------------ alias vim="nvim" alias v='nvim' alias vi='nvim' alias sudoedit="nvim" alias lvim='NVIM_APPNAME=LazyVim nvim' -alias sed=gsed -alias grep=ggrep -alias sort=gsort -alias awk=gawk -alias myip='curl ipv4.icanhazip.com' +alias zshrc='${=EDITOR} ${ZDOTDIR:-$HOME}/.zshrc' + +#------------------------------------------------------------------------------ +# Development Tools +#------------------------------------------------------------------------------ alias tf='terraform' alias tg='terragrunt' -alias ls='eza ' alias git_current_branch='git branch --show-current' -alias server='python -m http.server 3030' +alias gb='git for-each-ref --sort=-committerdate --format="%(refname:short)" | grep -n . | sed "s?origin/??g" | sort -t: -k2 -u | sort -n | cut -d: -f2 | fzf | xargs git checkout' +alias update-nvim-nightly='asdf uninstall neovim nightly && asdf install neovim nightly' -alias dotfiles='cd ~/Repos/dotfiles' -alias dc='cd ' -alias pj='fdf ~/Repos' -alias repos="~/Repos" +#------------------------------------------------------------------------------ +# Network & System Utils +#------------------------------------------------------------------------------ +alias watch='watch --color ' +alias myip='curl ipv4.icanhazip.com' +alias server='python -m http.server 3030' +alias kgevents='kubectl get event --sort-by=.metadata.creationTimestamp | grep -E -v "(Successfully (pulled|assigned)|(Started|Created) container|(Deleted|Created) pod)"' -# file aliases +#------------------------------------------------------------------------------ +# File Type Associations +#------------------------------------------------------------------------------ alias -s {lua,yml,yaml}=nvim -# global aliases +#------------------------------------------------------------------------------ +# Global Aliases (Pipe Operations) +#------------------------------------------------------------------------------ +# Loop Controls alias -g Wt='while :;do ' alias -g Wr=' | while read -r line;do echo "=== $line ==="; ' alias -g D=';done' -alias -g S='| sort' + +# Text Processing +alias -g H='| head' +alias -g T='| tail' +alias -g G='| grep' +alias -g L="| less" +alias -g P="| pbcopy" alias -g V='| nvim' -alias -g SRT='+short | sort' +alias -g S='| sort' + +# Output Redirection +alias -g NE="2> /dev/null" +alias -g NUL="> /dev/null 2>&1" + +# Kubernetes Specific alias -g Sa='--sort-by=.metadata.creationTimestamp' alias -g Srt='--sort-by=.metadata.creationTimestamp' alias -g SECRET='-ojson | jq ".data | with_entries(.value |= @base64d)"' @@ -51,23 +87,10 @@ alias -g NM=' --no-headers -o custom-columns=":metadata.name"' alias -g RC='--sort-by=".status.containerStatuses[0].restartCount" -A | grep -v "\s0\s"' alias -g BAD='| grep -v "1/1\|2/2\|3/3\|4/4\|5/5\|6/6\|Completed\|Evicted"' alias -g IP='-ojsonpath="{.spec.nodeName}"' +alias -g SRT='+short | sort' + +# Shell Processing alias -g dollar_1_line='$(awk "{print \$1}"<<<"${line}")' alias -g dollar_2_line='$(awk "{print \$2}"<<<"${line}")' -alias -g H='| head' -alias -g T='| tail' -alias -g G='| grep' -alias -g L="| less" -alias -g P="| pbcopy" -alias -g NE="2> /dev/null" -alias -g NUL="> /dev/null 2>&1" - -# see recently pushed branches -# alias gb="git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads | fzf | xargs git checkout && git pull" -alias gb='git for-each-ref --sort=-committerdate --format="%(refname:short)" | grep -n . | sed "s?origin/??g" | sort -t: -k2 -u | sort -n | cut -d: -f2 | fzf | xargs git checkout' - -alias kgevents='kubectl get event --sort-by=.metadata.creationTimestamp | grep -E -v "(Successfully (pulled|assigned)|(Started|Created) container|(Deleted|Created) pod)"' - -alias update-nvim-nightly='asdf uninstall neovim nightly && asdf install neovim nightly' - export LOADED_ALIASES=true diff --git a/zsh.d/completions.zsh b/zsh.d/completions.zsh index 14c5de2..31c12ef 100644 --- a/zsh.d/completions.zsh +++ b/zsh.d/completions.zsh @@ -1,34 +1,45 @@ load_completion_from_cmd() { local cmd=$1 - shift - local args=$@ - local completion_file=$ZSH_CACHE_DIR/completions/_$cmd - if ! (( $+commands[$cmd] )); then - return - fi + local args=("${@:2}") + local completion_file="${ZSH_CACHE_DIR}/completions/_${cmd}" + + [[ -n $commands[$cmd] ]] || return + if [[ ! -f $completion_file ]]; then typeset -g -A _comps autoload -Uz _$cmd _comps[$cmd]=_$cmd fi + eval "$cmd ${args[*]}" >| $completion_file &| } -GENCOMPL_FPATH=$HOME/.zsh/complete +# Constants at the top +GENCOMPL_FPATH="${HOME}/.zsh/complete" + +# Initialize completion system autoload -U +X bashcompinit && bashcompinit + +# Group related paths together fpath+=( - $ZSH_CACHE_DIR/completions - /opt/homebrew/share/zsh/site-functions - $ASDF_DIR/completions - $GENCOMPL_FPATH + "${ZSH_CACHE_DIR}/completions" + "/opt/homebrew/share/zsh/site-functions" + "${ASDF_DIR}/completions" + "${GENCOMPL_FPATH}" ) +# Group related completions together +# Infrastructure tools complete -o nospace -C terraform terraform complete -o nospace -C terragrunt terragrunt complete -o nospace -C 'aws_completer' aws + +# Development tools load_completion_from_cmd docker completion zsh -load_completion_from_cmd argocd completion zsh +load_completion_from_cmd kubectl completion zsh load_completion_from_cmd helm completion zsh + +# CLI tools load_completion_from_cmd gh completion --shell zsh -load_completion_from_cmd kubectl completion zsh +load_completion_from_cmd argocd completion zsh load_completion_from_cmd wezterm shell-completion --shell zsh diff --git a/zsh.d/functions.zsh b/zsh.d/functions.zsh index 0f0bf69..c995231 100755 --- a/zsh.d/functions.zsh +++ b/zsh.d/functions.zsh @@ -382,12 +382,42 @@ function zip-code() { } function matrix() { + lines=$(tput lines) + cols=$(tput cols) + + awkscript=' + { + letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*" + + lines=$1 + random_col=$3 + + c=$4 + letter=substr(letters,c,1) + + cols[random_col]=0; + + for (col in cols) { + line=cols[col]; + cols[col]=cols[col]+1; + + printf "\033[%s;%sH\033[2;32m%s", line, col, letter; + printf "\033[%s;%sH\033[1;37m%s\033[0;0H", cols[col], col, letter; + + if (cols[col] >= lines) { + cols[col]=0; + } + } + } + ' + echo -e "\e[1;40m" clear + while :; do - echo $LINES $COLUMNS $(($RANDOM % $COLUMNS)) $(($RANDOM % 72)) + echo $lines $cols $(($RANDOM % $cols)) $(($RANDOM % 72)) sleep 0.05 - done | awk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}' + done | awk "$awkscript" } function man() {