Skip to content

Instantly share code, notes, and snippets.

@designfrontier
Last active September 20, 2016 12:22
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 designfrontier/1296687bb4e1a180d15f to your computer and use it in GitHub Desktop.
Save designfrontier/1296687bb4e1a180d15f to your computer and use it in GitHub Desktop.
Lone Star zsh
#!/usr/bin/env zsh
# ------------------------------------------------------------------------------
#
# Lone Star - A futuristic minimal awesome Texas inspired theme for zsh
#
# Based heavily on the pure theme which includes the following note:
#
# Based on the custom Zsh-prompt of the same name by Sindre Sorhus. A huge
# thanks goes out to him for designing the fantastic Pure prompt in the first
# place! I'd also like to thank Julien Nicoulaud for his "nicoulaj" theme from
# which I've borrowed both some ideas and some actual code. You can find out
# more about both of these fantastic two people here:
#
# Sindre Sorhus
# Github: https://github.com/sindresorhus
# Twitter: https://twitter.com/sindresorhus
#
# Julien Nicoulaud
# Github: https://github.com/nicoulaj
# Twitter: https://twitter.com/nicoulaj
#
# With modifications by me... recommend setting your term coursor to _ and blink
#
# Daniel Sellers
# Github: https://github.com/designfrontier
# Twitter: https://twitter.com/daniel_sellers
#
# ------------------------------------------------------------------------------
# Set required options
#
setopt prompt_subst
# Load required modules
#
autoload -Uz vcs_info
# Set vcs_info parameters
#
zstyle ':vcs_info:*' enable hg bzr git
zstyle ':vcs_info:*:*' unstagedstr '!'
zstyle ':vcs_info:*:*' stagedstr '+'
zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%%u%c"
zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%u%c (%a)"
zstyle ':vcs_info:*:*' nvcsformats "%~" "" ""
# Fastest possible way to check if repo is dirty
#
git_dirty() {
# Check if we're in a git repo
command git rev-parse --is-inside-work-tree &>/dev/null || return
# Check if it's dirty
command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo "%F{red}★%f"
}
# Display information about the current repository
# or if not in a repo display current directory
#
repo_information() {
if [[ -z ${vcs_info_msg_0_%%/.} ]] then
echo "%F{cyan}${PWD/#$HOME/~}%f"
else
echo "%F{cyan}${vcs_info_msg_0_%%/.} %F{8}$vcs_info_msg_1_`git_dirty` $vcs_info_msg_2_%f"
fi
}
# Displays the exec time of the last command if set threshold was exceeded
#
cmd_exec_time() {
local stop=`date +%s`
local start=${cmd_timestamp:-$stop}
let local elapsed=$stop-$start
[ $elapsed -gt 5 ] && echo ${elapsed}s
}
# Get the intial timestamp for cmd_exec_time
#
preexec() {
cmd_timestamp=`date +%s`
}
# Output additional information about paths, repos and exec time
#
precmd() {
vcs_info # Get version control info before we start outputting stuff
print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f"
}
# Define prompts
#
PROMPT="%{$bg[red]%}$VAULTED_ENV%{$reset_color%}%(?.%F{8}.%F{red})➟%f " # Display a red prompt char on failure
RPROMPT="%F{8}${SSH_TTY:+%n@%m}%f" # Display username if connected via SSH
# ------------------------------------------------------------------------------
#
# List of vcs_info format strings:
#
# %b => current branch
# %a => current action (rebase/merge)
# %s => current version control system
# %r => name of the root directory of the repository
# %S => current path relative to the repository root directory
# %m => in case of Git, show information about stashes
# %u => show unstaged changes in the repository
# %c => show staged changes in the repository
#
# List of prompt format strings:
#
# prompt:
# %F => color dict
# %f => reset color
# %~ => current path
# %* => time
# %n => username
# %m => shortname host
# %(?..) => prompt conditional - %(condition.true.false)
#
# ------------------------------------------------------------------------------
@designfrontier
Copy link
Author

@designfrontier
Copy link
Author

Red Star for git status, current branch after location
red star for git status

Long running tasks show run time in yellow
time running

Running something that exits with a failed state turners the pointer arrow red
error state

To reload your .zshrc => . ~/.zshrc

@jaketrent
Copy link

Nice to see the get_smart goodness here

@designfrontier
Copy link
Author

Now shows your environment if you are using vaulted for environment management

screen shot 2016-02-26 at 4 03 25 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment