-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle all unbound parameters, even colors!
- Loading branch information
1 parent
d460318
commit 18a8504
Showing
1 changed file
with
27 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2034 # Expected behavior for themes. | ||
# shellcheck disable=SC2154 #TODO: fix these all. | ||
|
||
SCM_THEME_PROMPT_DIRTY=" ${bold_red}⊘${normal}" | ||
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" | ||
SCM_THEME_PROMPT_PREFIX="${reset_color}( " | ||
SCM_THEME_PROMPT_SUFFIX=" ${reset_color})" | ||
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}⊘${normal?}" | ||
SCM_THEME_PROMPT_CLEAN=" ${bold_green?}✓${normal?}" | ||
SCM_THEME_PROMPT_PREFIX="${reset_color?}( " | ||
SCM_THEME_PROMPT_SUFFIX=" ${reset_color?})" | ||
|
||
GIT_THEME_PROMPT_DIRTY=" ${bold_red}⊘${normal}" | ||
GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" | ||
GIT_THEME_PROMPT_PREFIX="${reset_color}( " | ||
GIT_THEME_PROMPT_SUFFIX=" ${reset_color})" | ||
GIT_THEME_PROMPT_DIRTY=" ${bold_red?}⊘${normal?}" | ||
GIT_THEME_PROMPT_CLEAN=" ${bold_green?}✓${normal?}" | ||
GIT_THEME_PROMPT_PREFIX="${reset_color?}( " | ||
GIT_THEME_PROMPT_SUFFIX=" ${reset_color?})" | ||
|
||
STATUS_THEME_PROMPT_BAD="${bold_red}❯${reset_color}${normal} " | ||
STATUS_THEME_PROMPT_OK="${bold_green}❯${reset_color}${normal} " | ||
PURITY_THEME_PROMPT_COLOR="${PURITY_THEME_PROMPT_COLOR:=$blue}" | ||
STATUS_THEME_PROMPT_BAD="${bold_red?}❯${reset_color?}${normal?} " | ||
STATUS_THEME_PROMPT_OK="${bold_green?}❯${reset_color?}${normal?} " | ||
: "${PURITY_THEME_PROMPT_COLOR:=$blue}" | ||
|
||
venv_prompt() { | ||
function venv_prompt() { | ||
python_venv="" | ||
# Detect python venv | ||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then | ||
python_venv="($PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV}) " | ||
if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then | ||
python_venv="(${PYTHON_VENV_CHAR}${CONDA_DEFAULT_ENV}) " | ||
elif [[ -n "${VIRTUAL_ENV}" ]]; then | ||
python_venv="($PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}")) " | ||
python_venv="(${PYTHON_VENV_CHAR}${VIRTUAL_ENV##*/}) " | ||
fi | ||
[[ -n "${python_venv}" ]] && echo "${python_venv}" | ||
} | ||
|
||
function prompt_command() { | ||
local retval=$? ret_status | ||
ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" | ||
PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status}$(venv_prompt)" | ||
local retval="$?" ret_status python_venv scm_prompt_info venv_prompt | ||
case "${retval}" in | ||
0) | ||
ret_status="$STATUS_THEME_PROMPT_OK" | ||
;; | ||
*) | ||
ret_status="$STATUS_THEME_PROMPT_BAD" | ||
;; | ||
esac | ||
scm_prompt_info="$(scm_prompt_info)" | ||
venv_prompt="$(venv_prompt)" | ||
PS1="\n${PURITY_THEME_PROMPT_COLOR}\w ${scm_prompt_info}\n${ret_status}${venv_prompt}" | ||
} | ||
|
||
safe_append_prompt_command prompt_command |