Skip to content

Commit

Permalink
Add support for venvs
Browse files Browse the repository at this point in the history
If you're in a venv, it shows the name in the prompt. Once I saw a cool
plugin that shows the python version, but that's got a heavy performance
overhead and I'd get annoyed looking at the same number every day.

For the new style to take effect, it expects you to have disabled your
normal venv PS1 by flag (`VIRTUAL_ENV_DISABLE_PROMPT`).
  • Loading branch information
PsychoLlama committed Oct 19, 2017
1 parent 29f6655 commit c5455f4
Showing 1 changed file with 61 additions and 13 deletions.
74 changes: 61 additions & 13 deletions llama.zsh-theme
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env zsh

function llama_git_status {
local unstaged_changes="$(git ls-files --others --modified --exclude-standard)"
local staged_changes="$(git diff --name-only --cached)"
Expand All @@ -11,23 +13,60 @@ function llama_git_status {
fi
}

function llama_branch_name {
local branch=$(git_current_branch)
local prompt=""
function llama_venv_status {
if [[ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then
return
fi

if [[ -z "$VIRTUAL_ENV" ]]; then
return
fi

title="%{$fg[cyan]%}$(basename "$VIRTUAL_ENV")"

if [[ ! -z "$1" ]]; then
title="%{$fg[yellow]%}($title%{$fg[yellow]%})"
fi

echo "$title"
}

function llama_branch_status {
local branch="$(git_current_branch)"

# It's a git repo.
if [[ ! -z "$branch" ]]; then
local prompt

prompt+=$(llama_git_status)
prompt+="%{$fg[cyan]%}$branch"

# Not a git repo.
if [[ -z "$branch" ]]; then
echo "$prompt"
fi
}

function llama_tool_summary {
local branch="$(llama_branch_status)"
local venv="$(llama_venv_status "$branch")"

if [[ -z "$branch" ]] && [[ -z "$venv" ]]; then
echo " "
return 0
return
fi

# Prettify the branch name.
prompt+="%{$fg[yellow]%}["
prompt+=$(llama_git_status)
prompt+="%{$fg[cyan]%}$branch"
prompt+="%{$fg[yellow]%}]"
local prompt
local delimiter=('[' ']')

if [[ -z "$branch" ]] && [[ ! -z "$venv" ]]; then
delimiter=('(' ')')
fi

echo $prompt
prompt+="%{$fg[yellow]%}${delimiter[1]}"
prompt+="$branch"
prompt+="$venv"
prompt+="%{$fg[yellow]%}${delimiter[2]}"

echo "$prompt"
}

function llama_return_status {
Expand All @@ -39,4 +78,13 @@ function llama_return_status {
echo "${color}❯ %{$reset_color%}"
}

PROMPT='%{$fg[blue]%}%c$(llama_branch_name)$(llama_return_status)'
function llama_prompt {
local prompt

prompt+="$(llama_tool_summary)"
prompt+="$(llama_return_status)"

echo "$prompt"
}

export PS1='%{$fg[blue]%}%c$(llama_prompt)'

0 comments on commit c5455f4

Please sign in to comment.