[zshrc] Make sure homebrew doesn't take over PATH

This commit is contained in:
Sami Samhuri 2022-01-22 20:43:32 -08:00
parent 03707ebb91
commit 05b66e5c47
No known key found for this signature in database
GPG key ID: 4B4195422742FC16

95
zshrc
View file

@ -1,4 +1,4 @@
# 0. Sniff out the platform ### Sniff out the platform
# ========================= # =========================
uname=`uname -s` uname=`uname -s`
function linux() { [[ "$uname" = "Linux" ]] } function linux() { [[ "$uname" = "Linux" ]] }
@ -11,9 +11,35 @@ function command_exists() { which "$1" >/dev/null 2>/dev/null }
# (tests if stdout is a tty) # (tests if stdout is a tty)
function is_interactive() { [ -t 1 ] } function is_interactive() { [ -t 1 ] }
# 1. Environment Vars ### Various environments
# =======================
# Do this before setting up PATH so ~/bin and similar still have the highest precedence.
if mac && [[ -x $HOME/homebrew/bin/brew ]]; then
eval "$($HOME/homebrew/bin/brew shellenv)"
fi
if command_exists rbenv; then
eval "$(rbenv init -)"
fi
if command_exists pyenv; then
eval "$(pyenv init -)"
fi
if command_exists direnv; then
eval "$(direnv hook zsh)"
fi
### SSH keys
# ============
if mac; then
ssh-add --apple-load-keychain
fi
### Environment Vars
# =================== # ===================
custom_paths=(/sbin /usr/sbin /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin /usr/local/bin /usr/local/sbin /opt/homebrew/bin /opt/homebrew/sbin $HOME/go/bin $HOME/bin)
custom_paths=(/sbin /usr/sbin /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin /usr/local/bin /usr/local/sbin $HOME/go/bin $HOME/bin)
for dir in $custom_paths; do for dir in $custom_paths; do
if [[ -d "$dir" ]]; then if [[ -d "$dir" ]]; then
path=($dir $path) path=($dir $path)
@ -68,10 +94,6 @@ if mac; then
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$HOME/homebrew/opt/openssl@1.1" export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$HOME/homebrew/opt/openssl@1.1"
fi fi
if [[ -x $HOME/homebrew/bin/brew ]]; then
eval "$($HOME/homebrew/bin/brew shellenv)"
fi
# Set Apple Terminal.app resume directory # Set Apple Terminal.app resume directory
if [[ $TERM_PROGRAM == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]] { if [[ $TERM_PROGRAM == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]] {
function chpwd { function chpwd {
@ -93,17 +115,17 @@ if [[ -d ~/Library/Mobile\ Documents/com\~apple\~CloudDocs ]]; then
export icloud=~/Library/Mobile\ Documents/com\~apple\~CloudDocs export icloud=~/Library/Mobile\ Documents/com\~apple\~CloudDocs
fi fi
# 2. Shell Options ### Shell Options
# ================ # ================
# 2.1. Parameters and Shell Functionality ### Parameters and Shell Functionality
# --------------------------------------- # ---------------------------------------
#setopt ignoreeof # ignore EOF ('^D') (i.e. don't log out on it) #setopt ignoreeof # ignore EOF ('^D') (i.e. don't log out on it)
setopt braceccl # {a-d} expands to a b c d setopt braceccl # {a-d} expands to a b c d
setopt noclobber # don't overwrite existing files w/ > output redir setopt noclobber # don't overwrite existing files w/ > output redir
setopt hist_allow_clobber # C-p or UP and command has >| now, ready to go setopt hist_allow_clobber # C-p or UP and command has >| now, ready to go
# 2.2. Changing Directories ### Changing Directories
# ------------------------- # -------------------------
setopt autocd # automatically cd to a directory if not cmd setopt autocd # automatically cd to a directory if not cmd
setopt autopushd # automatically pushd directories on dirstack setopt autopushd # automatically pushd directories on dirstack
@ -114,18 +136,18 @@ export DIRSTACKSIZE=8
setopt autonamedirs # % export h=/home/sjs; cd ~h; pwd => /home/sjs setopt autonamedirs # % export h=/home/sjs; cd ~h; pwd => /home/sjs
setopt cdablevars # blah=~/media/movies; cd blah; pwd => ~/media/movies setopt cdablevars # blah=~/media/movies; cd blah; pwd => ~/media/movies
# 2.3. Shell Completion ### Shell Completion
# --------------------- # ---------------------
setopt correct # try to correct spelling... setopt correct # try to correct spelling...
setopt no_correctall # ...only for commands, not filenames setopt no_correctall # ...only for commands, not filenames
setopt no_listbeep # don't beep on ambiguous listings setopt no_listbeep # don't beep on ambiguous listings
setopt listpacked # variable col widths (takes up less space) setopt listpacked # variable col widths (takes up less space)
# 2.4. Shell Expansion and Globbing ### Shell Expansion and Globbing
# --------------------------------- # ---------------------------------
setopt extendedglob # use extended globbing (#, ~, ^) setopt extendedglob # use extended globbing (#, ~, ^)
# 2.5. History and History Expansion ### History and History Expansion
# ---------------------------------- # ----------------------------------
export HISTFILE="$ZDOTDIR/zhistory" # save history export HISTFILE="$ZDOTDIR/zhistory" # save history
export HISTSIZE=2000000 # huge internal buffer export HISTSIZE=2000000 # huge internal buffer
@ -139,16 +161,16 @@ setopt histreduceblanks # compact consecutive white space chars (cool)
setopt histnostore # don't store history related functions setopt histnostore # don't store history related functions
setopt incappendhistory # incrementally add items to HISTFILE setopt incappendhistory # incrementally add items to HISTFILE
# 2.6. Job Control ### Job Control
# ---------------- # ----------------
setopt longlistjobs # list jobs in long format setopt longlistjobs # list jobs in long format
# 2.7. Shell Prompt ### Shell Prompt
# ----------------- # -----------------
setopt promptsubst # allow parameter, command, so on in prompt setopt promptsubst # allow parameter, command, so on in prompt
setopt transient_rprompt # hide RPROMPT after cmdline is executed setopt transient_rprompt # hide RPROMPT after cmdline is executed
# 2.8. ZLE ### ZLE
# -------- # --------
setopt no_beep # don't beep on errors (in ZLE) setopt no_beep # don't beep on errors (in ZLE)
@ -164,12 +186,12 @@ for op in \| \< \> \&
do bindkey "$op" self-insert-redir do bindkey "$op" self-insert-redir
done done
# 2.9. Auto quote pasted URLs ### Auto quote pasted URLs
# --------------------------- # ---------------------------
autoload -U url-quote-magic autoload -U url-quote-magic
zle -N self-insert url-quote-magic zle -N self-insert url-quote-magic
# 3. Terminal Settings ### Terminal Settings
# ==================== # ====================
function precmd { function precmd {
rehash rehash
@ -177,11 +199,11 @@ function precmd {
autoload -U colors # we need the colors for some formats below autoload -U colors # we need the colors for some formats below
colors colors
# 4. ZLE Keybindings ### ZLE Keybindings
# ================== # ==================
bindkey '\ep' history-beginning-search-backward bindkey '\ep' history-beginning-search-backward
# 5. Prompt Subsystem ### Prompt Subsystem
# =================== # ===================
# Load the prompt theme system # Load the prompt theme system
autoload -U promptinit autoload -U promptinit
@ -190,10 +212,10 @@ promptinit
# Use my prompt theme, based on wunjo (zsh-git) # Use my prompt theme, based on wunjo (zsh-git)
prompt sjs prompt sjs
# 6. Aliases ### Aliases
# =========== # ===========
# 6.1. Convenience Aliases/Macros ### Convenience Aliases/Macros
# -------------------------------- # --------------------------------
alias bgd='bg; disown %1' alias bgd='bg; disown %1'
alias cp='nocorrect cp' # don't correct spelling for 'cp' alias cp='nocorrect cp' # don't correct spelling for 'cp'
@ -211,7 +233,7 @@ alias myip='curl -4 icanhazip.com'
alias be='bundle exec' alias be='bundle exec'
alias doc='docker-compose' alias doc='docker-compose'
# 6.2 ls Aliases ### ls Aliases
# ---------------- # ----------------
if command_exists ls-comma; then if command_exists ls-comma; then
alias ls='ls-comma' alias ls='ls-comma'
@ -233,10 +255,10 @@ alias ll='ls -l'
alias lsd='ls -d' alias lsd='ls -d'
alias lld='ls -dl' alias lld='ls -dl'
# 6.3 ruby ### ruby
alias irb='irb --readline -r irb/completion' alias irb='irb --readline -r irb/completion'
# 6.4 git ### git
if command_exists git; then if command_exists git; then
alias a='git add' alias a='git add'
alias b='git branch' alias b='git branch'
@ -278,7 +300,7 @@ function cd () {
fi fi
} }
# 7. Unsorted (new) stuff ### Unsorted (new) stuff
# ======================= # =======================
# if commands takes more than 60 seconds tell me how long it took # if commands takes more than 60 seconds tell me how long it took
export REPORTTIME=60 export REPORTTIME=60
@ -292,10 +314,10 @@ setopt no_hup # leave bg tasks running (a la nohup)
bindkey -e # emacs style key bindings bindkey -e # emacs style key bindings
# 8. Completion ### Completion
# ============= # =============
if type brew &>/dev/null; then if command_exists brew; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
fi fi
@ -313,20 +335,3 @@ else
compinit compinit
fi fi
# 9. Various environments
# =======================
if command_exists rbenv; then
eval "$(rbenv init -)"
fi
if command_exists pyenv; then
eval "$(pyenv init -)"
fi
if command_exists direnv; then
eval "$(direnv hook zsh)"
fi
# 10. SSH keys
# ============
if mac; then
ssh-add --apple-load-keychain
fi