Skip to content

Instantly share code, notes, and snippets.

@ankitg12
Last active February 18, 2026 08:05
Show Gist options
  • Select an option

  • Save ankitg12/9f021b15e6af823e1ebcfc403c694743 to your computer and use it in GitHub Desktop.

Select an option

Save ankitg12/9f021b15e6af823e1ebcfc403c694743 to your computer and use it in GitHub Desktop.
My Bashrc #bashrc
# =====================================================
# Basic Shell Safety
# =====================================================
set -o noclobber # prevent accidental file overwrite with >
set -o pipefail # pipeline fails if any command fails
# =====================================================
# History Configuration (High ROI)
# =====================================================
HISTSIZE=50000
HISTFILESIZE=200000
HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
# Append history immediately and reload from other sessions
PROMPT_COMMAND='history -a; history -n'
# =====================================================
# Better Defaults for Tools
# =====================================================
export LESS='-FRSX'
export LESSHISTFILE=-
alias grep='grep --color=auto'
# =====================================================
# Directory Navigation Shortcuts
# =====================================================
alias ..='cd ..'
alias ...='cd ../..'
alias c='clear'
# =====================================================
# SSH Agent Auto-Start (Safe Version)
# =====================================================
# Start ssh-agent only if:
# - not already running
# - not inside an SSH session
if [ -z "$SSH_AUTH_SOCK" ] && [ -z "$SSH_CONNECTION" ]; then
eval "$(ssh-agent -s)" >/dev/null
fi
# Add default key if agent has no identities
if ! ssh-add -l >/dev/null 2>&1; then
[ -f "$HOME/.ssh/id_rsa" ] && ssh-add "$HOME/.ssh/id_rsa" >/dev/null 2>&1
fi
# =====================================================
# Smart SSH Wrapper (Project-aware + Key bootstrap)
# =====================================================
sshx() {
local args=("$@")
# Use project-local ssh.config if present
local ssh_cfg=()
[ -f ./ssh.config ] && ssh_cfg=(-F ./ssh.config)
# Try key-only authentication first
command ssh "${ssh_cfg[@]}" -o PasswordAuthentication=no "${args[@]}" 2>/dev/null
local status=$?
# If key auth failed, attempt ssh-copy-id
if [ $status -ne 0 ] && [ $# -ge 1 ]; then
echo "Key-only auth failed. Attempting to copy key..."
ssh-copy-id "${args[0]}"
command ssh "${ssh_cfg[@]}" "${args[@]}"
fi
}
alias ssh='sshx'
# =====================================================
# Kubernetes Productivity Aliases
# =====================================================
alias k='kubectl'
alias kgn='kubectl get nodes -o wide'
alias kgp='kubectl get pods -A -o wide'
alias kctx='kubectl config current-context'
alias kns='kubectl config set-context --current --namespace'
alias kx='kubectl exec -it'
alias kl='kubectl logs -f'
alias kwaitn='kubectl wait --for=condition=Ready node --all --timeout=300s'
alias kwaitp='kubectl wait --for=condition=Ready pod -A --all --timeout=300s'
# Enable kubectl completion if available
if command -v kubectl >/dev/null 2>&1; then
source <(kubectl completion bash)
fi
# =====================================================
# Git Shortcuts
# =====================================================
alias gs='git status -sb'
alias gl='git log --oneline --decorate -n 20'
alias gd='git diff'
# =====================================================
# End of .bashrc
# =====================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment