|
# shellcheck disable=all |
|
|
|
# PATH |
|
# export CODE="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/remote-cli" |
|
|
|
# check if binary exists |
|
check_bin() { type -P "$1" >/dev/null 2>&1; } |
|
|
|
# aliases |
|
alias ll='ls -FGlAhp' |
|
alias ..='cd ../' |
|
alias ...='cd ../../' |
|
alias bat='bat --paging=never' |
|
alias dd='gdd' |
|
alias diff='diff -W $(( $(tput cols) - 2 ))' |
|
alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder' |
|
alias mkdir='mkdir -pv' |
|
alias open-ports='sudo lsof -i | grep LISTEN' |
|
alias rsync='rsync -arvW --progress --stats --ignore-existing' |
|
alias show-blocked='sudo ipfw list' |
|
alias sudocode='SUDO_EDITOR="$(which code) --wait" sudoedit' |
|
alias tree='tree -a -I "__*__*|*.pyc|*.bak|.DS_*|.devbox|.git|.pytest_*|.ruff_cache|.venv|facts|node_modules"' |
|
|
|
# k8s |
|
alias k="kubectl" |
|
alias kc="kubectl config use-context" |
|
alias kns='kubectl config set-context --current --namespace' |
|
alias kgns="kubectl config view --minify --output 'jsonpath={..namespace}' | xargs printf '%s\n'" |
|
alias mk='minikube' |
|
|
|
# argo |
|
alias argo="argo -n argo" |
|
|
|
# terraform |
|
alias tf='terraform' |
|
alias tfi='terraform init' |
|
alias tfa='terraform apply' |
|
alias tfp='terraform plan' |
|
alias tfpn='terraform plan -refresh=false' |
|
|
|
# lunarvim |
|
check_bin lvim && alias vim='lvim' |
|
|
|
# atuin |
|
check_bin atuin && eval "$(atuin init bash --disable-up-arrow)" |
|
|
|
# multipass |
|
alias m='multipass' |
|
|
|
# limactl |
|
alias lc='limactl' |
|
|
|
# windmill |
|
alias wm='wmill' |
|
|
|
# lazydocker |
|
# https://github.com/jesseduffield/lazydocker#installation |
|
alias lzd="lazydocker" |
|
|
|
# mise |
|
# https://mise.jdx.dev/getting-started.html#activate-mise |
|
# https://mise.jdx.dev/getting-started.html#github-api-rate-limiting |
|
if [[ -f "${HOME}/.local/bin/mise" ]];then |
|
eval "$(${HOME}/.local/bin/mise activate bash)" |
|
export MISE_PIN=1 # use asdf versioning |
|
fi |
|
check_bin skate && export MISE_GITHUB_TOKEN="$(skate get mise_gh_token 2>/dev/null || echo '')" |
|
|
|
# aqua |
|
check_bin aqua && export AQUA_GLOBAL_CONFIG="${AQUA_GLOBAL_CONFIG:-}:${XDG_CONFIG_HOME:-$HOME/.config}/aquaproj-aqua/aqua.yaml" |
|
|
|
# fzf |
|
# https://github.com/junegunn/fzf#using-git |
|
check_bin fzf && eval "$(fzf --bash)" |
|
|
|
# nix |
|
if [[ -d "/nix" ]]; then |
|
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" |
|
export PATH="/nix/var/nix/profiles/default/bin:$PATH" |
|
fi |
|
|
|
# orbstack |
|
check_bin orb && source ~/.orbstack/shell/init.bash 2>/dev/null || : |
|
|
|
# localstack |
|
check_bin localstack && export LOCALSTACK_ACTIVATE_PRO=1 |
|
|
|
# claude desktop |
|
# * NOTE: requires `envsubst` (from `gettext` package) |
|
if [[ -f "$HOME/git/claude_config/.env" ]]; then |
|
export $(grep -v '^#' "$HOME/git/claude_config/.env" | xargs) |
|
envsubst < "$HOME/git/claude_config/claude_desktop_config.json.tpl" \ |
|
> "$HOME/git/claude_config/claude_desktop_config.json" |
|
fi |
|
|
|
# claude code (mcp) |
|
if [[ -f "$HOME/git/claude_config/.mcp.json.tpl" ]]; then |
|
export $(grep -v '^#' "$HOME/git/claude_config/.env" | xargs) |
|
envsubst < "$HOME/git/claude_config/.mcp.json.tpl" \ |
|
> "$HOME/git/claude_config/.mcp.json" |
|
alias claude='claude --mcp-config "$HOME/.claude/.mcp.json" "$@"' |
|
alias claude-yolo='claude --dangerously-skip-permissions' |
|
fi |
|
|
|
# opencode |
|
if [[ -f "$HOME/git/opencode_config/.env" ]]; then |
|
export $(grep -v '^#' "$HOME/git/opencode_config/.env" | xargs) |
|
envsubst '$CONTEXT7_API_KEY $HOME $UV_PROJECT_ENVIRONMENT' \ |
|
< "$HOME/git/opencode_config/opencode.jsonc.tpl" \ |
|
> "$HOME/git/opencode_config/opencode.jsonc" |
|
fi |
|
|
|
# jujutsu |
|
check_bin jujutsu && source <(jj util completion bash) |
|
|
|
# process-compose |
|
# https://f1bonacc1.github.io/process-compose/cli/process-compose_completion_bash/ |
|
check_bin process-compose && source <(process-compose completion bash) |
|
|
|
# unikraft |
|
check_bin kraft && source <(kraft completion bash) |
|
|
|
# control plane (tabtab) |
|
check_bin tabtab && source "$HOME/.config/tabtab/__tabtab.bash" |
|
|
|
# lm studio |
|
[[ -f "$HOME/.lmstudio/bin" ]] && export PATH="$HOME/.lmstudio/bin:$PATH" |
|
|
|
# linuxbrew (i.e., homebrew) |
|
# https://docs.brew.sh/Homebrew-on-Linux |
|
[[ -f "/home/linuxbrew/.linuxbrew/bin/brew" ]] && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" |
|
|
|
# FUNCTIONS |
|
cd() { builtin cd "$@"; ll; } |
|
iface() { route get 0.0.0.0 2>/dev/null | awk '/interface: / {print $2}'; } |
|
mkpasswd() { docker run -it --rm alpine mkpasswd -m sha-512 "$@"; } |
|
inspect-cert() { openssl crl2pkcs7 -nocrl -certfile $1 | openssl pkcs7 -print_certs -text -noout; } |
|
lsof() { |
|
if [[ $# -ne 1 ]]; then |
|
command lsof |
|
elif [[ $1 =~ ^[0-9]+$ ]]; then |
|
command sudo lsof -i TCP:"$1" -n -P |
|
elif [[ $# -gt 2 ]]; then |
|
command lsof "$@" |
|
fi |
|
} |
|
|
|
# lazygit |
|
# https://github.com/jesseduffield/lazygit?tab=readme-ov-file#installation |
|
lg() { |
|
export LAZYGIT_NEW_DIR_FILE=~/.lazygit/newdir |
|
|
|
lazygit "$@" |
|
|
|
if [ -f $LAZYGIT_NEW_DIR_FILE ]; then |
|
cd "$(cat $LAZYGIT_NEW_DIR_FILE)" |
|
rm -f $LAZYGIT_NEW_DIR_FILE > /dev/null |
|
fi |
|
} |
|
|
|
# jbang w/suppressed stderr |
|
# * e.g., `WARNING: Using incubator modules: jdk.incubator.vector` |
|
jbang() { |
|
command jbang "$@" 2>/dev/null |
|
} |
|
|
|
# recursive git status |
|
git_status() { |
|
export GREEN='\033[0;32m' |
|
export YELLOW='\033[0;33m' |
|
export RED='\033[0;31m' |
|
export BLUE='\033[0;34m' |
|
export NC='\033[0m' |
|
git_dir=$(find . -mindepth 1 -maxdepth 1 -type d ! -name ".git") |
|
for dir in $git_dir; do |
|
cd $dir && printf "${GREEN}${dir}${NC}\n" |
|
branch=$(git branch --show-current) |
|
status=$(git status --porcelain) |
|
[[ -n $branch ]] && printf "${BLUE}Branch${NC}: $branch\n" |
|
[[ -n $status ]] && printf "${YELLOW}$status${NC}\n" |
|
[[ -z $status ]] && printf "${GREEN}Clean${NC}\n" || printf "${RED}Dirty${NC}\n" |
|
cd .. |
|
done |
|
} |
|
|
|
rgrep() { |
|
local exclude_file="$HOME/exclude_patterns.txt" |
|
local args=( |
|
--color never |
|
--max-depth 3 |
|
--no-line-number |
|
--files-with-matches |
|
) |
|
|
|
[[ -f "$exclude_file" ]] && args+=(--ignore-file "$exclude_file") |
|
|
|
if ! command -v rg &>/dev/null; then |
|
echo "ripgrep not found. Please install ripgrep." |
|
echo "https://github.com/BurntSushi/ripgrep?tab=readme-ov-file#installation" |
|
return |
|
fi |
|
|
|
rg "${args[@]}" "$@" |
|
} |
|
|
|
# Check listening TCP and UDP ports |
|
# USAGE: find_available_ports [start] [end] [max] |
|
# EXAMPLE: find_available_ports 8000 9000 15 |
|
find_available_ports() { |
|
local start=${1:-8000} end=${2:-9000} max=${3:-10} |
|
local count=0 tcp_count=0 udp_count=0 |
|
echo "Searching for up to $max available port-protocol combinations in range $start-$end..." |
|
|
|
local used_tcp_ports=$(sudo lsof -iTCP -sTCP:LISTEN -n -P 2>/dev/null \ |
|
| awk '{print $9}' \ |
|
| sed -E 's/.*:([0-9]+)$/\1/' \ |
|
| sort -nu \ |
|
| grep -E "^($start|[1-9][0-9]{4,})$" \ |
|
| awk -v end=$end '$1 <= end' \ |
|
| tr '\n' ' ' |
|
) |
|
|
|
local used_udp_ports=$(sudo lsof -iUDP -n -P 2>/dev/null \ |
|
| awk '{print $9}' \ |
|
| sed -E 's/.*:([0-9]+)$/\1/' \ |
|
| sort -nu \ |
|
| grep -E "^($start|[1-9][0-9]{4,})$" \ |
|
| awk -v end=$end '$1 <= end' \ |
|
| tr '\n' ' ' |
|
) |
|
|
|
for port in $(seq $start $end); do |
|
local available="" |
|
if ! echo "$used_tcp_ports" | grep -qw "$port"; then |
|
available+="TCP" |
|
((tcp_count++)) |
|
((count++)) |
|
fi |
|
if ! echo "$used_udp_ports" | grep -qw "$port"; then |
|
[[ -n $available ]] && available+="," |
|
available+="UDP" |
|
((udp_count++)) |
|
((count++)) |
|
fi |
|
if [[ -n $available ]]; then |
|
echo "Port $port is available ($available)" |
|
[[ $count -eq $max ]] && break |
|
fi |
|
done |
|
|
|
echo "Found $count total available ports ($tcp_count TCP, $udp_count UDP)." |
|
} |
Uh oh!
There was an error while loading. Please reload this page.