Skip to content

Instantly share code, notes, and snippets.

@sfred
Created June 2, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfred/0a5a8829f53203d85824da645988f9bc to your computer and use it in GitHub Desktop.
Save sfred/0a5a8829f53203d85824da645988f9bc to your computer and use it in GitHub Desktop.
.zshrc
# sfred's .zshrc
# https://github.com/sfred/dotfiles
# Load ZSH functions
autoload -U add-zsh-hook
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# The following lines were added by compinstall
zstyle :compinstall filename '/Users/sfred/.zshrc'
autoload -Uz compinit
compinit
# ZSH Syntax Highlighting
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Aliases
alias reload="source ~/.zshrc"
# Set Spaceship ZSH as a prompt
autoload -U promptinit; promptinit
prompt spaceship
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && . "$(brew --prefix)/opt/nvm/nvm.sh" # This loads nvm
[ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && . "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# Automatically switch node versions when a directory has a `.nvmrc` file
load-nvmrc() {
local node_version="$(nvm version)" # Current node version
local nvmrc_path="$(nvm_find_nvmrc)" # Path to the .nvmrc file
# Check if there exists a .nvmrc file
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
# Check if the node version in .nvmrc is installed on the computer
if [ "$nvmrc_node_version" = "N/A" ]; then
# Install the node version in .nvmrc on the computer and switch to that node version
nvm install
# Check if the current node version matches the version in .nvmrc
elif [ "$nvmrc_node_version" != "$node_version" ]; then
# Switch node versions
nvm use
fi
# If there isn't an .nvmrc make sure to set the current node version to the default node version
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
# Add the above function when the present working directory (pwd) changes
add-zsh-hook chpwd load-nvmrc
load-nvmrc
# Allow the use of the z plugin to easily navigate directories
. $(brew --prefix)/etc/profile.d/z.sh
# Uses the zsh precmd function hook to set the tab title to the current working directory before each prompt
function precmd () {
window_title="\\033]0;${PWD##*/}\\007"
echo -ne "$window_title"
}
# goenv
eval "$(goenv init -)"
# Pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
# Pyenv-virtualenv
eval "$(pyenv virtualenv-init -)"
export SPACESHIP_VENV_SHOW=false
export VIRTUAL_ENV_DISABLE_PROMPT=1
# Set docker / kube prompts
export SPACESHIP_DOCKER_SHOW=false
export SPACESHIP_KUBECONTEXT_SYMBOL="☸ "
# Yarn
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
# Source zfunctions and homebrew
export PATH="/usr/local/sbin:$PATH"
fpath=($fpath "/Users/sfred/.zfunctions")
# Ruby
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
# colorls aliases
alias l='colorls --group-directories-first'
alias ll='colorls --group-directories-first --almost-all --long'
export PATH="$HOME/.rbenv/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment