macos zshrc zprofile
This commit is contained in:
45
macos/zprofile.txt
Normal file
45
macos/zprofile.txt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# ~/.zprofile
|
||||||
|
# ----- Login shell environment (runs once per login) -----
|
||||||
|
|
||||||
|
# 1. Homebrew Initialization
|
||||||
|
if [[ -f /opt/homebrew/bin/brew ]]; then
|
||||||
|
eval "$(/opt/homebrew/bin/brew shellenv)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2. Optimized PATH Construction
|
||||||
|
# Prepend custom bins, then add standard system paths
|
||||||
|
export PATH="$HOME/bin:$HOME/bin/net:$HOME/bin/files:$HOME/bin/media:/opt/homebrew/sbin:/opt/homebrew/bin:$HOME/go/bin:$HOME/.lmstudio/bin:/Users/jared/.antigravity/antigravity/bin:$PATH"
|
||||||
|
|
||||||
|
# 3. Node Version Manager (NVM) - Faster Loading Logic
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh"
|
||||||
|
|
||||||
|
# 4. LLVM / OpenCV (Developer Environment)
|
||||||
|
if command -v brew >/dev/null 2>&1; then
|
||||||
|
_LLVM_PATH="/opt/homebrew/opt/llvm"
|
||||||
|
if [[ -d "$_LLVM_PATH" ]]; then
|
||||||
|
export DYLD_LIBRARY_PATH="$_LLVM_PATH/lib:${DYLD_LIBRARY_PATH:-}"
|
||||||
|
export PKG_CONFIG_PATH="$(brew --prefix opencv 2>/dev/null)/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
|
||||||
|
export PATH="$_LLVM_PATH/bin:$PATH"
|
||||||
|
export CC="$_LLVM_PATH/bin/clang"
|
||||||
|
export CXX="$_LLVM_PATH/bin/clang++"
|
||||||
|
|
||||||
|
# Best-effort LIBCLANG_PATH for IDEs/Tools
|
||||||
|
_llvm_cellar="$(brew --cellar llvm 2>/dev/null)"
|
||||||
|
if [ -n "$_llvm_cellar" ]; then
|
||||||
|
_llvm_ver="$(ls -1 "$_llvm_cellar" 2>/dev/null | tail -1)"
|
||||||
|
[ -n "$_llvm_ver" ] && export LIBCLANG_PATH="$_llvm_cellar/$_llvm_ver/lib"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 5. Tool-Specific Exports & Silencing
|
||||||
|
export BYOBU_PREFIX=/opt/homebrew
|
||||||
|
export EDITOR="nano"
|
||||||
|
export TF_CPP_MIN_LOG_LEVEL=2
|
||||||
|
export GLOG_minloglevel=3
|
||||||
|
export GSETTINGS_SCHEMA_DIR=/opt/homebrew/share/glib-2.0/schemas
|
||||||
|
export XDG_DATA_DIRS="/opt/homebrew/share:/usr/local/share:/usr/share"
|
||||||
|
|
||||||
|
# 6. Load Secrets (API keys, etc.)
|
||||||
|
[[ -f "$HOME/.secrets.zsh" ]] && . "$HOME/.secrets.zsh"
|
||||||
256
macos/zshrc.txt
Normal file
256
macos/zshrc.txt
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
# ~/.zshrc
|
||||||
|
# ---------- Interactive zsh (each tab) ----------
|
||||||
|
|
||||||
|
# 1. Initialize Completion System (with caching)
|
||||||
|
autoload -Uz compinit
|
||||||
|
if [[ -n ${ZDOTDIR:-$HOME}/.zcompdump(#qN.m-1) ]]; then
|
||||||
|
compinit -C
|
||||||
|
else
|
||||||
|
compinit
|
||||||
|
fi
|
||||||
|
|
||||||
|
##### History
|
||||||
|
HISTFILE="$HOME/.zsh_history"
|
||||||
|
HISTSIZE=10000
|
||||||
|
SAVEHIST=20000
|
||||||
|
setopt APPEND_HISTORY INC_APPEND_HISTORY EXTENDED_HISTORY
|
||||||
|
setopt HIST_IGNORE_SPACE HIST_REDUCE_BLANKS HIST_SAVE_NO_DUPS HIST_FIND_NO_DUPS
|
||||||
|
|
||||||
|
##### Colors & Appearance
|
||||||
|
export CLICOLOR=1
|
||||||
|
export LSCOLORS=gxfxcxdxbxegedabagacad
|
||||||
|
export TERM=xterm-256color
|
||||||
|
|
||||||
|
_fix_cursor() { print -n -- $'\e[0 q'; }
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook precmd _fix_cursor
|
||||||
|
|
||||||
|
##### Quality-of-Life & AI Helpers
|
||||||
|
alias h='history 1'
|
||||||
|
alias cls="clear && printf '\e[3J'"
|
||||||
|
alias ls='command ls -G'
|
||||||
|
alias grep='grep --color=auto'
|
||||||
|
alias beforeafter='egrep -C 5 -i -e '
|
||||||
|
alias release_from_quarantine='xattr -dr com.apple.quarantine'
|
||||||
|
alias pywhere='which python && python --version'
|
||||||
|
alias renew='exec zsh'
|
||||||
|
alias ..="cd .."
|
||||||
|
alias ...="cd ../.."
|
||||||
|
alias ccat="clear ; cat "
|
||||||
|
alias tree='pwd; ls -R | grep ":$" | sed -e "s/:$//" -e "s/[^-][^\/]*\//--/g" -e "s/^/ /" -e "s/-/|/"'
|
||||||
|
alias notify='terminal-notifier -title "Terminal" -message'
|
||||||
|
|
||||||
|
# AI Helpers
|
||||||
|
alias askai='uv run --project "$HOME/python_projects/openai" --directory "$PWD" "$HOME/python_projects/openai/oai.py" --stream'
|
||||||
|
alias asklocal='uv run --project "$HOME/python_projects/openai" --directory "$PWD" "$HOME/python_projects/openai/endpoint-oai.py" --stream'
|
||||||
|
alias open-webui_start='source "/Users/jared/python_projects/open-webui/.venv/bin/activate" ; open-webui serve --host 127.0.0.1 --port 8765'
|
||||||
|
|
||||||
|
##### Networking & Remote (ISO Toolkit)
|
||||||
|
alias pubip="curl -s -4 ifconfig.me"
|
||||||
|
alias privip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
|
||||||
|
alias netcons='lsof -i'
|
||||||
|
alias flushdns='dscacheutil -flushcache'
|
||||||
|
alias lsock='sudo /usr/sbin/lsof -i -P'
|
||||||
|
alias lsocku='sudo /usr/sbin/lsof -P | grep UDP'
|
||||||
|
alias lsockt='sudo /usr/sbin/lsof -P | grep TCP'
|
||||||
|
alias ipinfo0='ipconfig getpacket en0'
|
||||||
|
alias ipinfo1='ipconfig getpacket en1'
|
||||||
|
alias openports='sudo lsof -i | grep LISTEN'
|
||||||
|
alias showdns='scutil --dns'
|
||||||
|
alias shownameservers='scutil --dns | grep "nameserver\[[0-9]*\]"'
|
||||||
|
alias showip='echo -n "IP: "; ifconfig | grep "inet " | grep -v 127 | awk "{print \$2}" | head -1; echo -n "router: "; netstat -rn | grep "^default" | awk "{print \$2}" | head -1'
|
||||||
|
alias showroutes='netstat -rn | grep -v :: | grep -v lo0 | grep -v 224\.0 | grep -v 255\.255\.255\.255 | grep -v 169\.254'
|
||||||
|
alias fastscan='nmap -n -F --open '
|
||||||
|
alias showconns="$HOME/bin/net/showconns.sh"
|
||||||
|
|
||||||
|
##### Nginx Helpers (Root / Port 80)
|
||||||
|
export NGINX_BIN="/opt/homebrew/opt/nginx/bin/nginx"
|
||||||
|
export NGINX_CONF="/opt/homebrew/etc/nginx/nginx.conf"
|
||||||
|
alias nginx_start='sudo $NGINX_BIN -c $NGINX_CONF'
|
||||||
|
alias nginx_stop="sudo nginx -s stop"
|
||||||
|
alias nginx_reload="sudo nginx -s reload"
|
||||||
|
alias nginx_restart='sudo nginx -s stop; sleep 1; sudo $NGINX_BIN -c $NGINX_CONF'
|
||||||
|
alias nginx_test='sudo $NGINX_BIN -t -c $NGINX_CONF'
|
||||||
|
alias nginx_listen='sudo lsof -iTCP:80 -sTCP:LISTEN | grep nginx'
|
||||||
|
alias editnginx='sudo vi /opt/homebrew/etc/nginx/servers/local-only.conf'
|
||||||
|
alias gowww='cd /opt/homebrew/var/www'
|
||||||
|
alias scp-moviesdb='echo "Sending movies.db to zappy" ; /usr/bin/scp /opt/homebrew/var/www/OC-Movie-Finder/server/movies.db zappy:/var/www/OC-Movie-Finder/server/movies.db'
|
||||||
|
|
||||||
|
##### System, Media & Utilities
|
||||||
|
alias cpu-hogs="$HOME/bin/topcpu.sh"
|
||||||
|
alias ttop="top -R -F -s 10 -o rsize"
|
||||||
|
alias myps="$HOME/bin/ps-jared.sh"
|
||||||
|
alias remove-mac-junkfiles="find . -name '*.DS_Store' -type f -ls -delete && find . -name 'Thumbs.db' -type f -ls -delete"
|
||||||
|
alias sleepnow="pmset sleepnow"
|
||||||
|
alias restartdock="killall -KILL Dock"
|
||||||
|
alias downloadyt='noglob yt-dlp -f mp4 -o "%(title)s.%(ext)s"'
|
||||||
|
alias progresscp='rsync -ah --info=progress2'
|
||||||
|
alias sanitizefiles='$HOME/bin/files/filename_sanitize.sh'
|
||||||
|
alias lowersanitizefiles='$HOME/bin/files/filename_sanitize.sh --lower'
|
||||||
|
alias have="have.sh"
|
||||||
|
alias vlc='open /Applications/VLC.app'
|
||||||
|
|
||||||
|
if command -v ffmpeg >/dev/null 2>&1; then
|
||||||
|
doublespeed () { ffmpeg -i "$*" -r 100 -vf 'setpts=(1/2)*PTS' -an double.mp4 ; }
|
||||||
|
alias ffresize="$HOME/bin/media/ffresize.sh"
|
||||||
|
alias ffmerge="$HOME/bin/media/ffmerge.sh"
|
||||||
|
alias findfps_media='for i in *; do echo " "; echo "$i"; ffmpeg -i "$i" 2>&1 | egrep "(fps)"; done'
|
||||||
|
alias ffprocs="ps wauxg | grep ff | grep -v Google | grep -v Slack | grep -v 'grep ff' | awk '{ print \$2 , \$11, \$12, \$13 }'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# PDF helpers (guarded)
|
||||||
|
command -v sejda-console >/dev/null 2>&1 && {
|
||||||
|
alias rotatepdf="mkdir -p ./rotated ; sejda-console rotate --pageRotation all:90 -o ./rotated --files *.PDF"
|
||||||
|
alias mergepdf="sejda-console merge -o ./merged.pdf --files *.pdf"
|
||||||
|
}
|
||||||
|
|
||||||
|
##### Search & Jared's LS Views
|
||||||
|
f() { /usr/bin/find . -name "*$**" ; }
|
||||||
|
fs() { /usr/bin/find . -iname "$**" ; }
|
||||||
|
fe() { /usr/bin/find . -iname "*$**" ; }
|
||||||
|
findtext () { find . -exec egrep "$*" {} /dev/null \; 2>/dev/null ; }
|
||||||
|
finddir () { find . \( -name 'Application Support' -o -name 'Library' -o -name 'Pictures' -o -name 'Movies' -o -name 'Parallels' -o -name '.tldrc' -o -name 'Virtual Machines.localized' -o -name '.venv' -o -name '.lmstudio' -o -name '.cache' \) -prune -o -type d -iname "*$**" -ls ; }
|
||||||
|
|
||||||
|
findfile () {
|
||||||
|
sudo find . \( -type d \( -name dev -o -name games -o -name libexec -o -name tmp -o -name lib -o -name lib64 -o -name sbin -o -name selinux -o -name sys -o -name proc -o -name spool -o -name mysql -o -name include -o -name '.cache' -o -name '.npm' -o -name 'node_modules' -o -name 'Applications' -o -name 'Library' -o -name '.venv' -o -name '.lmstudio' \) -prune \) -o -type f -iname "*$**" -print 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
fastfindtext () {
|
||||||
|
local pattern="$*"
|
||||||
|
[[ -z "$pattern" ]] && { echo "Usage: fastfindtext <pattern>"; return 1; }
|
||||||
|
sudo find . -maxdepth 4 \
|
||||||
|
\( -type d \( -name dev -o -name 'Library' -o -name '.Trash' -o -name log -o -name bin -o -name games -o -name libexec -o -name src -o -name tmp -o -name lib -o -name lib64 -o -name media -o -name sbin -o -name selinux -o -name sys -o -name proc -o -name spool -o -name mysql -o -name include -o -name dist -o -name .cache -o -name .npm -o -name node_modules -o -name '.venv' -o -name '.lmstudio' -o -name '__pycache__' \) -prune \) -o \
|
||||||
|
\( -type f ! -name '*__*' ! \( -name '*.o' -o -name '*.pyc' -o -name '*.c' -o -name '*.h' -o -name '*.sql' -o -name '*.pcap' -o -name '*.so' -o -name '*.a' -o -name '*.tar' -o -name '*.pdf' -o -name '*.mp4' -o -name '*.epub' -o -name '*.docx' -o -name '*.cbr' -o -name '*.xls' -o -name '*.png' -o -name '*.jpg' -o -name '*.JPG' -o -name '*.dmg' \) -print0 \) \
|
||||||
|
| xargs -0 grep -i -w -l -- "$pattern" | sort -u
|
||||||
|
}
|
||||||
|
|
||||||
|
vff() {
|
||||||
|
local pattern="$1"
|
||||||
|
[[ -z "$pattern" ]] && { echo "Usage: vff <pattern>"; return 1; }
|
||||||
|
local -a EXCLUDES=(bin include lib __pycache__ assets share node_modules dist .git .venv build out target)
|
||||||
|
local -a prune_expr
|
||||||
|
for d in "${EXCLUDES[@]}"; do prune_expr+=(-name "$d" -o); done
|
||||||
|
(( ${#prune_expr[@]} )) && prune_expr=("${prune_expr[@]:0:${#prune_expr[@]}-1}")
|
||||||
|
local -a files=("${(@f)$(find . \( -type d \( ${prune_expr[@]} \) -prune \) -o -type f -iname "*${pattern}*" -print | sort)}")
|
||||||
|
if (( ${#files[@]} == 0 )); then echo "No files found."; return 1; fi
|
||||||
|
if (( ${#files[@]} == 1 )); then "${EDITOR:-vi}" -- "${files[1]}"; return; fi
|
||||||
|
local PS3=$'Select file (number), or q: '
|
||||||
|
select file in "${files[@]}"; do
|
||||||
|
[[ "$REPLY" == [qQ] ]] && break
|
||||||
|
[[ -n "$file" ]] && "${EDITOR:-vi}" -- "$file" && break
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
vii() {
|
||||||
|
if (( $# != 1 )); then echo "Usage: vii <filename>"; return 1; fi
|
||||||
|
local file_path; file_path=$(find . -type f -name "$1" -print -quit)
|
||||||
|
[[ -n "$file_path" ]] && { echo "Opening: $file_path"; vi "$file_path"; } || echo "Not found: $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# LS Logic
|
||||||
|
l () { ls -Ald "$@"*/ 2>/dev/null; echo ' '; ls -lhF "$@" | grep -v '^d' | egrep -v -e '^total'; }
|
||||||
|
ldir () { ls -lh "$@" | grep "^d"; echo ' '; ls -lhF "$@" | grep -v "^d" | egrep -v -e '^total'; }
|
||||||
|
ll () { ls -Alh "$@" | grep "^d" | egrep -e ' \..*$' ; ls -lh "$@" | grep "^d" ; echo ' ' ; ls -lAhF "$@" | grep -v "^d" | egrep -e ' \..*$' ; ls -lhF "$@" | grep -v "^d" | egrep -v -e '^total\ '; }
|
||||||
|
lh () { ls -lAh "$@" | grep "^d" | egrep -e ' \..*$' ; echo ' ' ; ls -lAhF "$@" | grep -v "^d" | egrep -e ' \..*$' | egrep -v -e '^total\ '; }
|
||||||
|
alias lsd='ls -l | grep "^d"'
|
||||||
|
alias lsize="/Users/jared/python_projects/list_by_size/.venv/bin/python /Users/jared/python_projects/list_by_size/list_by_size.py"
|
||||||
|
alias ldate='ls -1tr | while IFS= read -r f; do printf "%s %s %s\n" "$(stat -f "%Sm" -t "%b %d %Y" "$f")" "$( [ -d "$f" ] && echo "dir " || echo file )" "$f"; done'
|
||||||
|
alias llc='echo Total number of files: $(ls -al | wc -l) in $(pwd)'
|
||||||
|
|
||||||
|
##### Project & Brew Aliases
|
||||||
|
alias lsgroup='/Users/jared/python_projects/lsgroup/.venv/bin/python3 /Users/jared/python_projects/lsgroup/lsgroup.py'
|
||||||
|
alias work='$HOME/python_projects/task-manager-curses/.venv/bin/python3 $HOME/python_projects/task-manager-curses/tasks.py --db $HOME/python_projects/task-manager-curses/tasks.db --client-secret=$HOME/python_projects/task-manager-curses/client_secret.json --token=$HOME/python_projects/task-manager-curses/token_work.json'
|
||||||
|
alias personal='$HOME/python_projects/task-manager-curses/.venv/bin/python3 $HOME/python_projects/task-manager-curses/tasks.py --db $HOME/python_projects/task-manager-curses/personal_tasks.db --client-secret=$HOME/python_projects/task-manager-curses/client_secret.json --token=$HOME/python_projects/task-manager-curses/token_personal.json'
|
||||||
|
alias ideas='$HOME/python_projs/ideas/bin/python3 $HOME/python_projs/ideas/ideas.py --db $HOME/python_projs/ideas/ideas.db'
|
||||||
|
alias seepersonaldb='dblab --config --cfg-name "taskspersonal"'
|
||||||
|
alias seeworkdb='dbee'
|
||||||
|
alias gdrive_list='pushd "$HOME/gdrive_list_sort" >/dev/null ; "$HOME/gdrive_list_sort/wildcard_search_google_drive.py" ; popd >/dev/null'
|
||||||
|
|
||||||
|
ocmovies() {
|
||||||
|
cd /opt/homebrew/var/www/OC-Movie-Finder/server || return
|
||||||
|
npm run server
|
||||||
|
}
|
||||||
|
|
||||||
|
brewfind () { find /opt/homebrew -iname "*$@*" | grep 'bin' | grep -e "$@$" ; }
|
||||||
|
alias bi='clear ; brew info '
|
||||||
|
|
||||||
|
##### Git Aliases
|
||||||
|
alias gs='git status'
|
||||||
|
alias ga='git add .'
|
||||||
|
alias gc='git commit -m'
|
||||||
|
alias gp='git push'
|
||||||
|
|
||||||
|
##### SSH Workflow
|
||||||
|
sshKeyGen () {
|
||||||
|
echo "Key name? "; read -r name
|
||||||
|
echo "Email? "; read -r email
|
||||||
|
ssh-keygen -t ed25519 -f "$HOME/.ssh/id_$name" -C "$email"
|
||||||
|
pbcopy < "$HOME/.ssh/id_$name.pub"
|
||||||
|
echo "Public key (Ed25519) copied to clipboard. Update ~/.ssh/config."
|
||||||
|
}
|
||||||
|
|
||||||
|
##### Automated Environments
|
||||||
|
load-nvmrc() { [[ -r .nvmrc ]] && nvm use >/dev/null 2>&1; }
|
||||||
|
add-zsh-hook chpwd load-nvmrc
|
||||||
|
|
||||||
|
##### Startup, Banners & Metrics
|
||||||
|
load-nvmrc
|
||||||
|
|
||||||
|
cmds() {
|
||||||
|
( cat ~/.zshrc | grep alias | grep -v '\#alias' | cut -d'=' -f 1 | cut -d' ' -f2 ) | sort | tr '\n' ' '
|
||||||
|
echo "\n\nUseful brew: byobu tldr ebook-convert btop ncdu resolveip testssl"
|
||||||
|
}
|
||||||
|
|
||||||
|
hdfree () { echo "Space left: $(df -h / | awk 'NR==2{print $4}')"; }
|
||||||
|
|
||||||
|
if curl -s --max-time 1 https://api.ipify.org >/tmp/pubip 2>/dev/null; then
|
||||||
|
echo "Connected to public Internet: $(cat /tmp/pubip)"
|
||||||
|
fi
|
||||||
|
echo "Private: "
|
||||||
|
$HOME/bin/net/net-show-inet4.sh
|
||||||
|
echo " "
|
||||||
|
[[ -x "$HOME/bin/net/wifi_signal.sh" ]] && "$HOME/bin/net/wifi_signal.sh"
|
||||||
|
hdfree
|
||||||
|
echo " "
|
||||||
|
cmds
|
||||||
|
echo " "
|
||||||
|
|
||||||
|
# --- Auto venv activate/deactivate (project-local .venv) ---
|
||||||
|
|
||||||
|
# Helper: return 0 if $PWD is inside $1 (directory prefix match), else 1
|
||||||
|
_is_in_dir() {
|
||||||
|
local base="$1"
|
||||||
|
[[ -z "$base" ]] && return 1
|
||||||
|
[[ "$PWD" == "$base" || "$PWD" == "$base"/* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
auto_venv() {
|
||||||
|
# If a venv is active, deactivate when we leave its owning project directory.
|
||||||
|
# Assumption: VIRTUAL_ENV points to .../PROJECT/.venv
|
||||||
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
||||||
|
local venv_dir="$VIRTUAL_ENV" # .../PROJECT/.venv
|
||||||
|
local project_dir="${venv_dir:h}" # .../PROJECT
|
||||||
|
|
||||||
|
if ! _is_in_dir "$project_dir"; then
|
||||||
|
# Only call deactivate if it exists (it will when a venv was activated normally)
|
||||||
|
if whence -w deactivate >/dev/null 2>&1; then
|
||||||
|
deactivate
|
||||||
|
else
|
||||||
|
# Fallback: at least unset the marker to avoid repeated checks
|
||||||
|
unset VIRTUAL_ENV
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no venv active now, activate if the new directory has a project-local .venv
|
||||||
|
if [[ -z "$VIRTUAL_ENV" && -r ".venv/bin/activate" ]]; then
|
||||||
|
source ".venv/bin/activate"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure the hook is set once (remove/replace your existing auto_venv hook line)
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook chpwd auto_venv
|
||||||
|
|
||||||
|
# Run once for the starting directory of a new shell/tab
|
||||||
|
auto_venv
|
||||||
Reference in New Issue
Block a user