Skip to content

Instantly share code, notes, and snippets.

@jonohayon
Created September 23, 2016 12:00
Show Gist options
  • Save jonohayon/928bdc19b84c0535e221fee3944f4a4b to your computer and use it in GitHub Desktop.
Save jonohayon/928bdc19b84c0535e221fee3944f4a4b to your computer and use it in GitHub Desktop.
zshrc and zshtheme

.zshrc:

##########
# .zshrc #
##########

# Include extended-glob (for excluding and stuff)
setopt extended_glob

source ~/.antigen/antigen.zsh # Load antigen

# Use the Oh My ZSH library
antigen use oh-my-zsh

# Some recommended plugins
antigen bundles <<EOBUNDLES
  git
  zsh-users/zsh-syntax-highlighting
  zsh-users/zsh-completions
  denysdovhan/gitio-zsh
  voronkovich/gitignore.plugin.zsh
  chrissicool/zsh-256color
  node
  npm
  catimg
  nyan
  extract
  command-not-found
  heroku
  osx
EOBUNDLES

# Some Z hooks
antigen bundle rupa/z
add-zsh-hook precmd _z_precmd
function _z_precmd() {
  _z --add "$PWD"
}

antigen apply

# Initialize nvm
export NVM_DIR="/Users/jonathano/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

# Some nvm hooks
autoload -U add-zsh-hook
function load-nvmrc() {
  if [[ -f .nvmrc && -r .nvmrc ]]; then
    if [[ $(nvm ls | grep `cat ./.nvmrc`) != "" ]]; then
      nvm use
    else
      echo "Node version $(cat ./.nvmrc) wasn't found; Installing..."
      nvm install $(cat ./.nvmrc); nvm use
    fi
  elif [[ $(nvm version) != $(nvm version default)  ]]; then
    nvm use default
  fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

# A simple calculator for the command line
function calc () { echo "$(($@))" }

export ZSH="$HOME/.antigen" # Set the home ZSH directory
source ~/.zshtheme # Source the prompt theme

# Prefered editor
if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR='nano'
else
  export EDITOR='subl'
fi

##################
# Custom Aliases #
##################
alias pdir="cd ~/Desktop/Projects" # Cd to projects directory
alias nindex="node index.js" # Run index.js using nodejs
alias smocha="sudo mocha" # Run mocha tests (nodejs)
alias zshrc="source ~/.zshrc" # Update the zshrc
alias zshtheme="subl ~/.zshtheme" # Edit my theme
alias zshconfig="subl ~/.zshrc" # Edit the zshrc
alias sfa="standard-format -w ./*.js" # Formats all of the js files in . for standardjs
alias npmprivate="npm config set registry http://repo.dev.wix/artifactory/api/npm/npm-repos" # Wix private npm
alias npmpublic="npm config set registry https://registry.npmjs.org/" # Set public npm back
alias cls="clear" # Just cuz it's smaller, not cuz Windows
alias גב="cd" # When in hebrew mode, cd still works
alias בךקשר="clear" # When in hebrew mode, clear still works
alias zshconfig="subl ~/.zshrc" # Edit .zshrc easily
alias st-mongo="mongod --dbpath ~/mongodb" # Start momgodb server easily

# Linux aliases
if [[ "$OSTYPE" == "linux-gnu" ]]; then
  alias telegram="nohup $TELEGRAM_HOME/Telegram &"
fi

# Theos SDK
export THEOS="$HOME/theos"

# PATH shit
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/rezozo/.rvm/bin"
if [[ "$OSTYPE" == "linux-gnu" ]]; then # Linux paths
  # Setting JAVA_HOME, ANDROID_HOME and PATH
  export JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
  export ANDROID_HOME="/home/rezozo/Android/Sdk"
  export STUDIO_HOME="~/android-studio"
  export ANDROID_EMULATOR_FORCE_32BIT="true"
  export PATH="$ANDROID_HOME/tools:$PATH"
  export PATH="$ANDROID_HOME/platform-tools:$PATH"
  export PATH="$STUDIO_HOME/bin:$PATH"

  # PhantomJS
  export PHANTOM_HOME="~/phantomjs-2.1.1-linux-i686/"
  export PATH="$PHANTOM_HOME/bin:$PATH"

  # apktool
  export APKTOOL_HOME="~/apktool"
  export PATH="$APKTOOL_HOME:$PATH"

  # jadx
  export JADX_HOME="~/jadx/bin/"
  export PATH="$JADX_HOME:$PATH"

  # dex2jar
  export D2J_HOME="~/dex2jar"
  export PATH="$D2J_HOME:$PATH"

  # jd-ui
  export JDUI_HOME="~/jd-ui"
  export PATH="$JDUI_HOME:$PATH"

  # NW.js
  export NWJS_HOME="~/nwjs"
  export PATH="$NWJS_HOME:$PATH"

  # Popcorn Time
  export POPCORN_HOME="~/popcorn"
  export PATH="$POPCORN_HOME:$PATH"

  # WebTorrent Desktop
  export WEBTORRENT_HOME="~/webtorrent"
  export PATH="$WEBTORRENT_HOME:$PATH"

  # Swift
  export SWIFT_HOME="~/swift/usr/bin"
  export PATH="$SWIFT_HOME:$PATH"

  # Telegram
  export TELEGRAM_HOME="~/telegram/Telegram"
  export PATH="$TELEGRAM_HOME:$PATH"

  # Prepros
  export PREPROS_HOME="~/prepros"
  export PATH="$PREPROS_HOME:$PATH"

  # Electron
  export ELECTRON_LINUX_HOME="~/electron"
  export PATH="$ELECTRON_LINUX_HOME:$PATH"
fi

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/Users/rezozo/.sdkman"
[[ -s "/Users/rezozo/.sdkman/bin/sdkman-init.sh" ]] && source "/Users/rezozo/.sdkman/bin/sdkman-init.sh"

.zshtheme:

# Reset EVERYTHING!
unset TMOUT
unset RPROMPT
unset RPS1

function git_get_branch() {
  ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
  ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
  echo "${ref#refs/heads/}"
}

function git_get_commit() {
  echo "$(command git rev-parse --short HEAD)"
}

function info_git() {
  if git rev-parse --git-dir > /dev/null 2>&1; then
    local branch=$(git_get_branch)
    local commit=$(git_get_commit)
    echo "[${branch}: ${commit}]"
  fi
}

function battery_info() {
  local percent="${$(pmset -g batt | awk '{print $2}' | grep '%')%?}"
  local is_charging="${$(pmset -g batt | awk '{print $3}' | grep 'char')}"
  if [[ "$is_charging" != "charged;" && "$is_charging" != "charging;" ]]; then
    echo "[⇀ ${percent}]]"
  else
    echo "[⇋ ${percent}]]"
  fi
}

function is_ssh() {
  if [[ -n $SSH_CONNECTION ]]; then
    echo "[SSH]"
  fi
}

function put_spaces() {
  local zero='%([BSUbfksu]|([FBK]|){*})'
  local upperleft="%{$fg_bold[green]%}%T %{$fg_bold[yellow]%}%n %{$fg_bold[red]%}@ %{$fg_bold[cyan]%}%~"
  upperleft=${#${(S%%)upperleft//$~zero/}}
  local upperright="%{$fg_bold[magenta]%}$(info_git)$(battery_info)%{$fg_bold[green]%}[⬢ $(node -v)]"
  upperright=${#${(S%%)upperright//$~zero/}}
  local termwidth
  (( termwidth = $(tput cols) - ${upperleft} - ${upperright} ))
  local spacing=""
  for i in {1..$termwidth}; do
    spacing="${spacing} "
  done
  echo $spacing
}

PROMPT=$'%{$fg_bold[green]%}%T %{$fg_bold[yellow]%}%n %{$fg_bold[red]%}@ %{$fg_bold[cyan]%}%~$(put_spaces)%{$fg_bold[magenta]%}$(info_git)%{$fg_bold[white]%}$(battery_info)%{$fg_bold[green]%}[⬢ $(node -v)]\
 %{$fg_bold[blue]%}→ %{$fg_bold[red]%}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment