Skip to content

Instantly share code, notes, and snippets.

@zachdunn
Last active December 3, 2018 12:59
Show Gist options
  • Save zachdunn/f9edfafb7fb543c0591315df4452ec7d to your computer and use it in GitHub Desktop.
Save zachdunn/f9edfafb7fb543c0591315df4452ec7d to your computer and use it in GitHub Desktop.
Theme for oh my zsh
# ... (Find this section in your local .zshrc to replace)
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git osx terminalapp zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
# ...
# ----
# New part. Shouldn't replace anything in your .zshrc by default.
# ---
# ENV
export SERVER_HOST_TYPE=local
export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters
# Highlighters
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[arg0]='fg=035'
ZSH_HIGHLIGHT_STYLES[precommand]='fg=196'
ZSH_HIGHLIGHT_STYLES[root]='bg=196'
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=065'
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=245'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=245'
ZSH_HIGHLIGHT_STYLES[alias]='fg=035,bold'
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=196')

A theme for ZSH with host/root highlighting for easier server hopping.

onemightyroar-zsh

Install

  1. Install https://github.com/robbyrussell/oh-my-zsh
  2. Add onemightyroar.zsh-theme to ~/.oh-my-zsh/themes
  3. Open ~/.zshrc and update theme via ZSH_THEME="onemightyroar"
  4. Run source ~/.zshrc to reload shell
  5. You're good to go

Flagging remote hosts

To highlight remote hosts, add an environment variable SERVER_HOST_TYPE='remote' to the system PATH. This makes it easier to identify which system you're running on:

remote-hosts

TODO: Update this to flag tunneled connections automatically, without explicit ENV config.

Root

Root will always highlight red by default.

root-highlight

# onemightyroar.zsh-theme
#
# Author: Zach Dunn
# URL: https://zachdunn.com/about
# Repo: https://github.com/andyfleming/oh-my-zsh
#
# Created on: July 30, 2013
# Last modified on: Jan 12, 2017
# Colors
eval my_gray='$FG[237]'
eval my_orange='$FG[214]'
eval my_red='$FG[196]'
eval my_purple='$FG[105]'
eval my_lightblue='$FG[075]'
eval my_blue='$FG[032]'
eval my_seafoam='$FG[043]'
# Highlight remote hosts, based on `SERVER_HOST_TYPE` environment variable in PATH.
local REMOTE_HOST='remote'
# Highlight root user in red
if [ $(id -u) = 0 ]; then
host_color=$my_red;
else
host_color=$my_orange;
fi
local return_code="%(?..%{$my_red%}%? ↵%{$reset_color%})"
if [ "$SERVER_HOST_TYPE" = "$REMOTE_HOST" ]; then
user_color=$my_seafoam;
else
user_color=$my_gray;
fi
# primary prompt
PROMPT='$my_gray------------------------------------------------------------%{$reset_color%}
$my_blue%~\
$(git_prompt_info)
$host_color%m %{$reset_color%}$my_purple%(!.ϟ.ϟ)%{$reset_color%} '
PROMPT2='%{$my_red%}\ %{$reset_color%}'
RPS1='${return_code}'
# Right side prompt (i.e. user@hostname)
RPROMPT='$user_color%n@%m%{$reset_color%}%'
# git settings
ZSH_THEME_GIT_PROMPT_PREFIX="$my_lightblue(branch:"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$my_lightblue)%{$reset_color%}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment