Skip to content

Commit

Permalink
theme/modern: SC2154
Browse files Browse the repository at this point in the history
Handle all unbound parameters, even colors!
  • Loading branch information
gaelicWizard committed Feb 13, 2022
1 parent 7dfcd09 commit e23d239
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions themes/modern/modern.theme.bash
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.

SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""

SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}${normal?}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green?}${normal?}"
SCM_GIT_CHAR="${bold_green?}±${normal?}"
SCM_SVN_CHAR="${bold_cyan?}${normal?}"
SCM_HG_CHAR="${bold_red?}${normal?}"

case $TERM in
case "${TERM:-dumb}" in
xterm*)
TITLEBAR="\[\033]0;\w\007\]"
;;
Expand All @@ -22,32 +21,34 @@ esac

PS3=">> "

is_vim_shell() {
if [ -n "$VIMRUNTIME" ]; then
echo "[${cyan}vim shell${normal}]"
function is_vim_shell() {
if [[ -n "${VIMRUNTIME:-}" ]]; then
echo "[${cyan?}vim shell${normal?}]"
fi
}

detect_venv() {
python_venv=""
function detect_venv() {
local python_venv=""
# Detect python venv
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}")) "
if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
python_venv="(${PYTHON_VENV_CHAR}${CONDA_DEFAULT_ENV}) "
elif [[ -n "${VIRTUAL_ENV:-}" ]]; then
python_venv="(${PYTHON_VENV_CHAR}${VIRTUAL_ENV##*/}) "
fi
}

prompt() {
SCM_PROMPT_FORMAT='[%s][%s]'
retval=$?
function prompt() {
local retval=$? scm_prompt is_vim_shell python_venv
local SCM_PROMPT_FORMAT='[%s][%s]'
scm_prompt="$(scm_prompt)"
is_vim_shell="$(is_vim_shell)"
if [[ retval -ne 0 ]]; then
PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n${bold_red}└─▪${normal} "
PS1="${TITLEBAR:-}${bold_red?}┌─${reset_color?}${scm_prompt}[${cyan?}\u${normal?}][${cyan?}\w${normal?}]${is_vim_shell}\n${bold_red?}└─▪${normal?} "
else
PS1="${TITLEBAR}┌─$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n└─▪ "
PS1="${TITLEBAR:-}┌─${scm_prompt}[${cyan?}\u${normal?}][${cyan?}\w${normal?}]${is_vim_shell}\n└─▪ "
fi
detect_venv
PS1+="${python_venv}${dir_color}"
PS1+="${python_venv?}${dir_color?}"
}

PS2="└─▪ "
Expand Down

0 comments on commit e23d239

Please sign in to comment.