165 lines
5.7 KiB
Plaintext
165 lines
5.7 KiB
Plaintext
# zshrc for macOS: zsh + oh-my-zsh counterpart of bash/bashrc-osx (same env,
|
|
# aliases and dtach menu; the prompt lives in bchanot.zsh-theme).
|
|
# Machine-specific lines (nvm, bun, tokens...) go in ~/.zshrc.local, never here.
|
|
|
|
# Homebrew on PATH (Apple Silicon: /opt/homebrew, Intel: /usr/local).
|
|
for brew_bin in /opt/homebrew/bin/brew /usr/local/bin/brew; do
|
|
if [ -x "$brew_bin" ]; then
|
|
eval "$("$brew_bin" shellenv)"
|
|
break
|
|
fi
|
|
done
|
|
unset brew_bin
|
|
|
|
## oh-my-zsh (loaded first: the aliases below override its defaults, e.g. `d`)
|
|
export ZSH="$HOME/.oh-my-zsh"
|
|
ZSH_THEME="bchanot"
|
|
plugins=(git)
|
|
source "$ZSH/oh-my-zsh.sh"
|
|
|
|
## Enable color support of ls and also add handy aliases
|
|
# Some colors (BSD ls: -G instead of GNU --color)
|
|
alias ls='ls -G'
|
|
alias grep='grep --color=auto'
|
|
|
|
## Some export
|
|
# colored GCC warnings and errors
|
|
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
|
|
|
|
# XDG cache dir: tmux.conf saves resurrect/continuum sessions under it
|
|
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
|
|
|
|
# Ensure ~/.local/bin is on PATH (pipx CLIs + personal scripts from bin/)
|
|
case ":$PATH:" in
|
|
*":$HOME/.local/bin:"*) ;;
|
|
*) export PATH="$HOME/.local/bin:$PATH" ;;
|
|
esac
|
|
|
|
# Rust toolchain (install.sh, rustup): puts ~/.cargo/bin on PATH, dedup done by the env file.
|
|
if [ -f "$HOME/.cargo/env" ]; then
|
|
# shellcheck source=/dev/null
|
|
. "$HOME/.cargo/env"
|
|
fi
|
|
|
|
# History: none for root, near-unlimited otherwise (zsh has no -1 = unlimited).
|
|
if [[ $EUID == 0 ]] ; then
|
|
HISTSIZE=0
|
|
SAVEHIST=0
|
|
else
|
|
HISTSIZE=10000000
|
|
SAVEHIST=10000000
|
|
fi
|
|
|
|
# Identity for git commits and vim headers. Filled by install.sh (asked once,
|
|
# reused from an existing ~/.bashrc / ~/.zshrc on re-runs), never stored here.
|
|
export USER="@USER@"
|
|
export EMAIL="@EMAIL@"
|
|
|
|
# claude-dans-dtach : creer une session (claude tournant dans dtach, detache via Ctrl-\).
|
|
# Reprend la derniere conversation du dossier (--continue), sinon session neuve.
|
|
# Usage : cd ~/projets/seo && cc seo -> session nommee "seo".
|
|
# Pas de systemd sur macOS : dtach est lance directement (pas de slice cgroup).
|
|
dtach_claude() {
|
|
local name="${1:-claude-$(date +%H%M%S)}"
|
|
mkdir -p "$HOME/.dtach"
|
|
dtach -c "$HOME/.dtach/${name}" -e '^\' \
|
|
bash -c 'set -a; [ -f "$HOME/.claude/.env" ] && . "$HOME/.claude/.env"; set +a; claude --continue || exec claude'
|
|
}
|
|
alias cc='dtach_claude'
|
|
|
|
# Rappeler a la demande le menu de reprise.
|
|
alias d='source ~/.local/bin/dtach-router'
|
|
|
|
# openrouter : bascule Claude Code sur OpenRouter dans le shell courant (fonction, pas
|
|
# script : un script ne peut pas modifier l'environnement de son parent). `openrouter`
|
|
# active, `openrouter -d` (ou -u) desactive. La cle vient de $OPENROUTER_API_KEY, a
|
|
# exporter depuis un fichier prive non versionne (~/.bashrc.local, ~/.zshrc.local).
|
|
# Les valeurs qu'avaient deja ces variables sont gardees dans $_OPENROUTER_SAVED
|
|
# (commandes export/unset) et rejouees a la desactivation.
|
|
openrouter() {
|
|
local v saved=""
|
|
case "${1:-}" in
|
|
-d | -u)
|
|
if [ -n "${_OPENROUTER_SAVED+x}" ]; then
|
|
saved="$_OPENROUTER_SAVED"
|
|
elif [ "${ANTHROPIC_BASE_URL:-}" != "https://openrouter.ai/api" ]; then
|
|
echo "openrouter: not active"
|
|
return 0
|
|
fi
|
|
unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_API_KEY \
|
|
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY
|
|
eval "$saved"
|
|
unset _OPENROUTER_SAVED
|
|
echo "openrouter: off"
|
|
echo "Pensez a vous log in de Claude Code"
|
|
;;
|
|
"")
|
|
[ -n "${OPENROUTER_API_KEY:-}" ] || {
|
|
echo "openrouter: OPENROUTER_API_KEY is not set" >&2
|
|
return 1
|
|
}
|
|
if [ -z "${_OPENROUTER_SAVED+x}" ]; then
|
|
for v in ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_API_KEY \
|
|
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY; do
|
|
if printenv "$v" >/dev/null; then
|
|
saved="$saved export $v=$(printf %q "$(printenv "$v")");"
|
|
else
|
|
saved="$saved unset $v;"
|
|
fi
|
|
done
|
|
_OPENROUTER_SAVED="$saved"
|
|
fi
|
|
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
|
|
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
|
|
export ANTHROPIC_API_KEY="" # doit etre explicitement vide
|
|
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
|
|
echo "openrouter: on"
|
|
echo "Pensez a vous logout de Claude Code"
|
|
;;
|
|
*)
|
|
echo "usage: openrouter [-d|-u]" >&2
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# repo-sync : un arbre local (~/repos) pour tous les depots des forges declarees
|
|
# dans ~/.config/repos/forges.conf. `repo <projet> [namespace]` clone si besoin
|
|
# puis s'y place ; la liste se rafraichit en arriere-plan, au plus 1 fois par jour.
|
|
repo() {
|
|
local dir
|
|
dir="$(repo-sync path "$@")" && cd "$dir" || return
|
|
}
|
|
_repo() {
|
|
local cache="${REPOS_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/repos/list}"
|
|
local -a items
|
|
[[ -f "$cache" ]] || return 0
|
|
if (( CURRENT == 2 )); then
|
|
items=(${(f)"$(cut -f1 "$cache" | sort -u)"})
|
|
_describe 'project' items
|
|
elif (( CURRENT == 3 )); then
|
|
items=(${(f)"$(awk -F'\t' -v p="$words[2]" '$1 == p { print $2 }' "$cache")"})
|
|
_describe 'namespace' items
|
|
fi
|
|
}
|
|
compdef _repo repo
|
|
[[ -o interactive ]] && command -v repo-sync >/dev/null && (repo-sync refresh --quiet >/dev/null 2>&1 &)
|
|
|
|
# Reglages propres a cette machine (non versionnes).
|
|
[ -f "$HOME/.zshrc.local" ] && source "$HOME/.zshrc.local"
|
|
|
|
# SSH interactif hors tmux (et hors terminal VS Code Remote-SSH) : entrer dans tmux,
|
|
# session partagee "main" (rattachee si elle existe). Le shell lance dans tmux relit ce
|
|
# fichier et ouvre le menu dtach ci-dessous ; quitter tmux ferme la connexion (exec).
|
|
case $- in *i*)
|
|
if [ -n "${SSH_CONNECTION:-}" ] && [ -z "${TMUX:-}" ] \
|
|
&& [ "${TERM_PROGRAM:-}" != vscode ] && command -v tmux >/dev/null; then
|
|
exec tmux new-session -A -s main
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
# Au demarrage d'un shell interactif, proposer de reprendre une session dtach existante
|
|
# (silencieux si aucune).
|
|
case $- in *i*) [ -x "$HOME/.local/bin/dtach-router" ] && . "$HOME/.local/bin/dtach-router" ;; esac
|