Skip to content

Instantly share code, notes, and snippets.

@dmarticus
Last active January 6, 2021 00:37
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 dmarticus/85c3eda173fe870c5da1d27482f6a532 to your computer and use it in GitHub Desktop.
Save dmarticus/85c3eda173fe870c5da1d27482f6a532 to your computer and use it in GitHub Desktop.
Minimal ZSH theme with a hack that adds the nix_shell status to your prompt
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[white]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}●%{$fg[white]%}]%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_CLEAN="]%{$reset_color%} "
ZSH_THEME_SVN_PROMPT_PREFIX=$ZSH_THEME_GIT_PROMPT_PREFIX
ZSH_THEME_SVN_PROMPT_SUFFIX=$ZSH_THEME_GIT_PROMPT_SUFFIX
ZSH_THEME_SVN_PROMPT_DIRTY=$ZSH_THEME_GIT_PROMPT_DIRTY
ZSH_THEME_SVN_PROMPT_CLEAN=$ZSH_THEME_GIT_PROMPT_CLEAN
ZSH_THEME_HG_PROMPT_PREFIX=$ZSH_THEME_GIT_PROMPT_PREFIX
ZSH_THEME_HG_PROMPT_SUFFIX=$ZSH_THEME_GIT_PROMPT_SUFFIX
ZSH_THEME_HG_PROMPT_DIRTY=$ZSH_THEME_GIT_PROMPT_DIRTY
ZSH_THEME_HG_PROMPT_CLEAN=$ZSH_THEME_GIT_PROMPT_CLEAN
CURRENT_BG='NONE'
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
# NOTE: This segment separator character is correct. In 2012, Powerline changed
# the code points they use for their special characters. This is the new code point.
# If this is not working for you, you probably have an old version of the
# Powerline-patched fonts installed. Download and install the new version.
# Do not submit PRs to change this unless you have reviewed the Powerline code point
# history and have new information.
# This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
# what font the user is viewing this source code in. Do not replace the
# escape sequence with a single literal character.
# Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
SEGMENT_SEPARATOR=$'\ue0b0'
}
vcs_status() {
if [[ $(whence in_svn) != "" ]] && in_svn; then
svn_prompt_info
elif [[ $(whence in_hg) != "" ]] && in_hg; then
hg_prompt_info
else
git_prompt_info
fi
}
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
prompt_nix_shell() {
if [[ -n "$IN_NIX_SHELL" ]]; then
if [[ -n $NIX_SHELL_PACKAGES ]]; then
local package_names=""
local packages=($NIX_SHELL_PACKAGES)
for package in $packages; do
package_names+=" ${package##*.}"
done
prompt_segment black yellow "{$package_names }"
elif [[ -n $name ]]; then
local cleanName=${name#interactive-}
cleanName=${cleanName%-environment}
prompt_segment black yellow "{ $cleanName } "
else # This case is only reached if the nix-shell plugin isn't installed or failed in some way
prompt_segment black yellow "nix-shell {} "
fi
fi
}
PROMPT='%2~ $(vcs_status)$(prompt_nix_shell)»%b '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment