Last active
May 14, 2025 05:01
-
-
Save guterz/be065bc4c42c07a378ea335d2c92f68f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Christopher Gutierrez < | |
# Description: Zsh configuration for Christopher Gutierrez | |
# License: MIT | |
# Version: 1.0.0 | |
# Date: 2025-05-13 | |
######################## 1. Shell options ######################## | |
# Navigation / editing | |
setopt AUTO_CD # cd by typing directory name | |
setopt CORRECT # spell-correct commands | |
setopt auto_pushd # pushd/popd directory stack | |
setopt pushd_ignore_dups | |
# Globbing / sorting | |
setopt extended_glob numeric_glob_sort | |
# History hygiene | |
setopt HIST_IGNORE_ALL_DUPS HIST_EXPIRE_DUPS_FIRST SHARE_HISTORY \ | |
HIST_FIND_NO_DUPS HIST_REDUCE_BLANKS HIST_SAVE_NO_DUPS \ | |
HIST_SAVE_BY_COPY HIST_IGNORE_SPACE HIST_VERIFY | |
# Real-time history sync (optional; uncomment if desired) | |
#setopt INC_APPEND_HISTORY HIST_IGNORE_DUPS | |
######################## 2. PATH ################################# | |
# De-duplicate PATH and append common local dirs | |
typeset -U path PATH | |
path+=( | |
"$HOME/bin" # your own scripts | |
"$(python3 -m site --user-base)/bin" # pip-user installs | |
/opt/homebrew/bin /opt/homebrew/sbin # Apple-silicon Homebrew | |
) | |
export PATH | |
######################## 3. Completion ########################### | |
if ! (( ${+_comps} )); then | |
autoload -Uz compinit | |
compinit -i # suppress insecure-dir warnings | |
fi | |
if [[ -x /opt/homebrew/bin/aws_completer ]]; then | |
autoload bashcompinit && bashcompinit | |
complete -C '/opt/homebrew/bin/aws_completer' aws | |
fi | |
######################## 4. Aliases ############################## | |
alias cl='clear' | |
alias ll='ls -lah' | |
alias k='kubectl' | |
alias dk8s='kubectl config get-contexts' | |
alias kgp='kubectl get pods -A -o wide' | |
alias knodes='kubectl get nodes -o wide' | |
# Use coloured kubectl if kubecolor is installed | |
if command -v kubecolor >/dev/null; then | |
alias kubectl='kubecolor' | |
fi | |
######################## 5. Helper functions ##################### | |
# Switch kube-context quickly | |
k8s () { kubectl config use-context "$1"; } | |
# History grep – multi-term AND search, case-insensitive | |
hg () { | |
if (( $# == 0 )); then | |
history 0 | |
return | |
fi | |
local cmd='history 0' | |
for term in "$@"; do | |
cmd+=" | grep -i --color=auto -- '$term'" | |
done | |
eval "$cmd" | |
} | |
######################## 6. Key-bindings ######################### | |
bindkey '^[[1;5D' backward-word # Ctrl+← | |
bindkey '^[[1;5C' forward-word # Ctrl+→ | |
bindkey '^[a' beginning-of-line # Alt-a | |
bindkey '^[e' end-of-line # Alt-e | |
######################## 7. AWS / SSM helpers #################### | |
# Generic SSM port-forward | |
ssmfwd () { # ssmfwd <instance> <region> <lPort> [<rPort>] | |
local instance=$1 region=$2 local_port=$3 remote_port=${4:-$3} | |
aws ssm start-session \ | |
--target "$instance" \ | |
--document-name AWS-StartPortForwardingSession \ | |
--parameters "localPortNumber=${local_port},portNumber=${remote_port}" \ | |
--region "$region" | |
} | |
# RDP helper (defaults to local 55678) | |
rdp () { # rdp <instance> <region> [<localPort>] | |
local local_port=${3:-55678} | |
ssmfwd "$1" "$2" "$local_port" 3389 | |
} | |
# Plain SSM session | |
ssm () { # ssm <instance> <region> | |
[[ $# -lt 2 ]] && { echo "Usage: ssm <instance> <region>" >&2; return 1; } | |
aws ssm start-session --target "$1" --region "$2" | |
} | |
# Update kubeconfig for EKS (adds alias <cluster>-<region>) | |
update-eks-kubeconfig () { # update-eks-kubeconfig <region> <cluster> | |
[[ $# -lt 2 ]] && { echo "Usage: update-eks-kubeconfig <region> <cluster>" >&2; return 1; } | |
aws eks update-kubeconfig --region "$1" --name "$2" --alias "$2-$1" | |
} | |
################################################################### | |
# End of cgutierrez.zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment