Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .my_aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# ~/.my_aliases — shared aliases & functions (safe on macOS)
# Guards ensure commands exist; avoids Linux-only flags like `--color=auto`.

# ----- Helpers -----
_exists() { command -v "$1" >/dev/null 2>&1; }

# ----- ls/ll/l -----
if _exists ls; then
# macOS: use -G (BSD ls). If you install coreutils (gls), you can switch.
alias ls='ls -G'
alias ll='ls -lah'
alias l='pwd; ls -lrtAF'
fi

# ----- Quick dirs -----
alias pd='pushd'
alias ppd='popd'

# ----- Kubernetes shortcuts -----
if _exists kubectl; then
alias kcontext='kubectl config get-contexts || echo "no-kcontext"'
alias kscontext='kubectl config use-context || echo "no-kscontext"'

# exec into pod: k8sh [ns] <pod>
k8sh() {
local ns=obj
local namespace="default"
local objname="$1"
if [ -n "$2" ]; then namespace="$1"; objname="$2"; fi
kubectl -n "$namespace" exec -it "$objname" -- bash 2>/dev/null || \
kubectl -n "$namespace" exec -it "$objname" -- sh
}

# Tail logs of pods by label key=value
module_log() {
local selector="$1"
[ -z "$selector" ] && { echo "usage: module_log app.kubernetes.io/name=<value>"; return 1; }
until kubectl logs -f -l "$selector"; do sleep 1; done
}

fi

# ----- JSON / CSV tooling -----
if _exists jq; then
flatj() { jq 'paths(scalars) | map(tostring) | join(".")' "$1"; }
flatjv() { jq -r 'paths(scalars) as $p | [([ $p[]|tostring ]|join(".")), (getpath($p)|tojson)] | join(" = ")' "$1"; }
fi
pretty_csv() { command -v column >/dev/null && column -t -s, -n "$@" | less -F -S -X -K; }

# ----- macOS conveniences -----
copyKey() { cat ~/.ssh/id_rsa.pub | pbcopy; echo "Public key copied to clipboard."; }
alias md='mdfind -onlyin .'

# ----- AWS helpers -----
alias aws_user='aws sts get-caller-identity'

# ----- One-off installers (use with care) -----
getdocker() { curl -fsSL https://get.docker.com | sudo sh -; }

# ----- Networking -----
alias tcpdump_http='sudo tcpdump -s0 -i any -vvv -w dump.pcap tcp port 80'
tunnel() {
# usage: tunnel host.example.com
sudo ssh -i ~/.ssh/id_rsa -nNT \
-L 80:localhost:80 -L 8080:localhost:8080 -L 3306:localhost:3306 -L 6379:localhost:6379 \
"root@$1"
}

# ----- Go env quick-setup -----
go_setup() {
mkdir -p "$HOME/go/src" "$HOME/go/bin" "$HOME/go/pkg" "$HOME/go/src/github.com"
export GOPATH="$HOME/go"
echo "GOPATH=$GOPATH"
}

# ----- Safer SSH helpers (pass host/ip as arg) -----
ssr() { ssh "root@$1"; }
ssu() { ssh "ubuntu@$1"; }

# ----- macFUSE / SSHFS mounts (with keepalive + reconnect) -----
# Requires: brew install macfuse sshfs (or equivalent)
if _exists sshfs; then
jnar() {
mkdir -p "$HOME/jnar/rapidfort"
diskutil unmount "$HOME/jnar/rapidfort" >/dev/null 2>&1
sshfs -o reconnect \
-o ServerAliveInterval=15 \
-o ServerAliveCountMax=3 \
-o auto_cache \
-o follow_symlinks \
root@jnar:/root/rapidfort "$HOME/jnar/rapidfort"
}
jnar2() {
mkdir -p "$HOME/jnar2/rapidfort"
diskutil unmount "$HOME/jnar2/rapidfort" >/dev/null 2>&1
sshfs -o reconnect \
-o ServerAliveInterval=15 \
-o ServerAliveCountMax=3 \
-o auto_cache \
-o follow_symlinks \
root@jnar2:/root/rapidfort "$HOME/jnar2/rapidfort"
}
fi
47 changes: 47 additions & 0 deletions .zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export PATH="/opt/homebrew/bin:/usr/local/bin:$HOME/.local/bin:$HOME/bin:$PATH"

# ----- History -----
HISTFILE="$HOME/.zsh_history"
HISTSIZE=20000
SAVEHIST=20000
setopt hist_ignore_dups hist_reduce_blanks inc_append_history share_history

# ----- Completion -----
autoload -Uz compinit && compinit

# --- Git branch in prompt (green) ---
# --- Fancy Git prompt (macOS zsh) ---

# 1) Enable substitutions in PROMPT and load helpers
setopt prompt_subst
autoload -Uz vcs_info add-zsh-hook

# 2) Configure vcs_info for Git
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git:*' check-for-changes true # detect dirty state
zstyle ':vcs_info:git:*' stagedstr ' +' # staged changes marker
zstyle ':vcs_info:git:*' unstagedstr ' %' # unstaged changes marker
zstyle ':vcs_info:git:*' formats '%F{yellow}(%b%c%u)%f' # (branch + staged/unstaged)
zstyle ':vcs_info:git:*' actionformats '%F{yellow}(%b%c%u|%a)%f' # rebase/merge actions

# 3) Refresh vcs_info before each prompt
vcs_precmd() { vcs_info }
add-zsh-hook precmd vcs_precmd

# 5) Prompt: [platform][IP] user@host (branch + dirty) : cwd with root/# or user/% ending
# Example: [platform][100.92.16.57] rajeevt@jmac (main %) : ~/workspace %
PROMPT='%F{green}%n@%m%f ${vcs_info_msg_0_} %F{blue}%~%f %(#.#.%%) '

# Optional right prompt: show last exit code when non-zero + time
RPROMPT='%(?..%F{red}↩ %?%f) %F{240}%*%f'

# ----- Don’t clobber builtins on macOS -----
export TERM=xterm-256color

# ----- Load your aliases/functions -----
[ -f "$HOME/.my_aliases" ] && source "$HOME/.my_aliases"

# Optional per-tool extras (if you keep them)
for f in "$HOME/.kubectl_aliases" "$HOME/.docker_aliases" "$HOME/.git_aliases"; do
[ -f "$f" ] && source "$f"
done
111 changes: 111 additions & 0 deletions macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash
set -euo pipefail

# -------- helpers --------
ts() { date +"%Y%m%d-%H%M%S"; }
backup_if_exists() {
local target="$1"
if [ -e "$target" ] || [ -L "$target" ]; then
cp -a "$target" "${target}.bak.$(ts)"
fi
}

append_once() {
# append a line to a file if it doesn't already exist (as exact match)
local file="$1"
local line="$2"
grep -Fqx "$line" "$file" 2>/dev/null || printf '%s\n' "$line" >> "$file"
}

# -------- 1) Ensure $HOME/bin --------
mkdir -p "$HOME/bin"

# -------- 2) Copy dotfiles to $HOME (with backups) --------
# .zshrc
if [ -f "./.zshrc" ]; then
backup_if_exists "$HOME/.zshrc"
cp -a "./.zshrc" "$HOME/.zshrc"
echo "Installed ~/.zshrc"
else
echo "Note: ./.zshrc not found; skipping."
fi

# .my_aliases (support both names)
if [ -f "./.my_aliases" ]; then
backup_if_exists "$HOME/.my_aliases"
cp -a "./.my_aliases" "$HOME/.my_aliases"
echo "Installed ~/.my_aliases"
elif [ -f "./.myalias" ]; then
backup_if_exists "$HOME/.my_aliases"
cp -a "./.myalias" "$HOME/.my_aliases"
echo "Installed ~/.my_aliases (from ./.myalias)"
else
echo "Note: neither ./.my_aliases nor ./.myalias found; skipping."
fi

# .kubectl_aliases
if [ -f "./.kubectl_aliases" ]; then
backup_if_exists "$HOME/.kubectl_aliases"
cp -a "./.kubectl_aliases" "$HOME/.kubectl_aliases"
echo "Installed ~/.kubectl_aliases"
else
echo "Note: ./.kubectl_aliases not found; skipping."
fi

# -------- 3) Install / set up Homebrew --------
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew not found. Installing..."
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Homebrew found."
fi

# Determine brew prefix (Apple Silicon vs Intel)
BREW_PREFIX="$(/usr/bin/env brew --prefix 2>/dev/null || true)"
if [ -z "${BREW_PREFIX}" ]; then
# Fallbacks
if [ -d /opt/homebrew ]; then
BREW_PREFIX=/opt/homebrew
elif [ -d /usr/local/Homebrew ]; then
BREW_PREFIX=/usr/local
fi
fi

# -------- 4) Ensure PATH contains Homebrew and $HOME/bin (idempotent) --------
# Use ~/.zprofile for login shells & ~/.zshrc for interactive shells.
touch "$HOME/.zprofile" "$HOME/.zshrc"

if [ -n "${BREW_PREFIX:-}" ]; then
# Recommended brew shellenv line
BREW_LINE='eval "$('"$BREW_PREFIX"'/bin/brew shellenv)"'
append_once "$HOME/.zprofile" "$BREW_LINE"
append_once "$HOME/.zshrc" "$BREW_LINE"
fi

# Ensure $HOME/bin is early in PATH
BIN_LINE='export PATH="$HOME/bin:$PATH"'
append_once "$HOME/.zprofile" "$BIN_LINE"
append_once "$HOME/.zshrc" "$BIN_LINE"

# Apply to current session (best effort)
if [ -n "${BREW_PREFIX:-}" ] && [ -x "$BREW_PREFIX/bin/brew" ]; then
eval "$("$BREW_PREFIX/bin/brew" shellenv)"
fi
export PATH="$HOME/bin:$PATH"

# -------- 5) Copy all x* to $HOME/bin and make executable --------
shopt -s nullglob
copied=0
for f in x*; do
# Only regular files
[ -f "$f" ] || continue
cp -a "$f" "$HOME/bin/"
chmod +x "$HOME/bin/$(basename "$f")"
echo "Installed $HOME/bin/$(basename "$f")"
copied=$((copied+1))
done
shopt -u nullglob
[ "$copied" -eq 0 ] && echo "Note: no files matching 'x*' found to copy."

echo "Done. Open a new terminal or run: source ~/.zprofile && source ~/.zshrc"