Skip to content

Instantly share code, notes, and snippets.

@jperocho
Last active May 18, 2022 00:21
Show Gist options
  • Save jperocho/3aba6417bee25d2f2fa9f0dc0e187094 to your computer and use it in GitHub Desktop.
Save jperocho/3aba6417bee25d2f2fa9f0dc0e187094 to your computer and use it in GitHub Desktop.
Basic zshrc that works
# Zsh plugins
. ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# Brew path
export PATH=$PATH:/usr/local/lib/pkgconfig
# Python 3 path brew install
export PATH=$PATH:/usr/local/opt/python@3.9/libexec/bin/
# Vim path
export PATH=$PATH:/usr/local/Cellar/vim/8.2.4950
# Enables ls colors
export CLICOLOR=1
# Alias
alias ..="cd .."
alias ...="cd ../.."
alias l="ls -lah"
alias pip=pip3
alias python=python3
# Git alias
alias gst="git status"
alias ga="git add"
alias gl="git pull"
alias gp="git push"
alias gcam="git commit -am"
alias gcmsg="git commit -m"
alias gco="git checkout"
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%b'
# Custom Prompt
setopt prompt_subst
NEW_LINE=$'\n'
PROMPT_CHAR=$'\n%(!.#.$) '
CWD=$'\n%F{blue}%(4~|%1~|%~)%f'
PS1='$CWD %F{red}${vcs_info_msg_0_}%f $(node_version) $(aws_profile) $PROMPT_CHAR'
# AWS
function aws_profile {
if [[ $AWS_PROFILE ]]; then
echo "%F{yellow}AWS: $AWS_PROFILE%f "
fi
}
# Node version
function node_version {
PACKAGE_JSON=./package.json
if [[ -f "$PACKAGE_JSON" ]]; then
NODE=$(which node)
NODE_VER=$($NODE --version)
echo "%F{green}NODEJS: ${NODE_VER}%f "
fi
}
# End of Custom Prompt
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# load nvmrc
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment