Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add themes/base.theme.bash to clean files #1785

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ themes/agnoster
themes/90210
themes/powerline
themes/barbuk
themes/base.theme.bash

# plugins
#
Expand Down
74 changes: 44 additions & 30 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash

CLOCK_CHAR_THEME_PROMPT_PREFIX=''
CLOCK_CHAR_THEME_PROMPT_SUFFIX=''
Expand Down Expand Up @@ -100,25 +100,39 @@ if [[ -x "$SVN_EXE" ]] ; then
fi

function scm {
if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT
elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT
elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4
elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG
elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG
elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN
elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN
else SCM=$SCM_NONE
if [[ "$SCM_CHECK" = false ]]; then
SCM=$SCM_NONE
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then
SCM=$SCM_GIT
elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then
SCM=$SCM_GIT
elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
SCM=$SCM_P4
elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then
SCM=$SCM_HG
elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then
SCM=$SCM_HG
elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then
SCM=$SCM_SVN
elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then
SCM=$SCM_SVN
else
SCM=$SCM_NONE
fi
}

function scm_prompt_char {
if [[ -z $SCM ]]; then scm; fi
if [[ $SCM == $SCM_GIT ]]; then SCM_CHAR=$SCM_GIT_CHAR
elif [[ $SCM == $SCM_P4 ]]; then SCM_CHAR=$SCM_P4_CHAR
elif [[ $SCM == $SCM_HG ]]; then SCM_CHAR=$SCM_HG_CHAR
elif [[ $SCM == $SCM_SVN ]]; then SCM_CHAR=$SCM_SVN_CHAR
else SCM_CHAR=$SCM_NONE_CHAR
if [[ $SCM == "$SCM_GIT" ]]; then
SCM_CHAR=$SCM_GIT_CHAR
elif [[ $SCM == "$SCM_P4" ]]; then
SCM_CHAR=$SCM_P4_CHAR
elif [[ $SCM == "$SCM_HG" ]]; then
SCM_CHAR=$SCM_HG_CHAR
elif [[ $SCM == "$SCM_SVN" ]]; then
SCM_CHAR=$SCM_SVN_CHAR
else
SCM_CHAR=$SCM_NONE_CHAR
fi
}

Expand All @@ -127,10 +141,10 @@ function scm_prompt_vars {
scm_prompt_char
SCM_DIRTY=0
SCM_STATE=''
[[ $SCM == $SCM_GIT ]] && git_prompt_vars && return
[[ $SCM == $SCM_P4 ]] && p4_prompt_vars && return
[[ $SCM == $SCM_HG ]] && hg_prompt_vars && return
[[ $SCM == $SCM_SVN ]] && svn_prompt_vars && return
[[ $SCM == "$SCM_GIT" ]] && git_prompt_vars && return
[[ $SCM == "$SCM_P4" ]] && p4_prompt_vars && return
[[ $SCM == "$SCM_HG" ]] && hg_prompt_vars && return
[[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return
}

function scm_prompt_info {
Expand All @@ -149,7 +163,7 @@ function scm_prompt_info_common {
SCM_DIRTY=0
SCM_STATE=''

if [[ ${SCM} == ${SCM_GIT} ]]; then
if [[ ${SCM} == "${SCM_GIT}" ]]; then
if [[ ${SCM_GIT_SHOW_MINIMAL_INFO} == true ]]; then
# user requests minimal git status information
git_prompt_minimal_info
Expand All @@ -161,9 +175,9 @@ function scm_prompt_info_common {
fi

# TODO: consider adding minimal status information for hg and svn
{ [[ ${SCM} == ${SCM_P4} ]] && p4_prompt_info && return; } || true
{ [[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return; } || true
{ [[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return; } || true
{ [[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return; } || true
{ [[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return; } || true
{ [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true
}

function terraform_workspace_prompt {
Expand Down Expand Up @@ -318,7 +332,7 @@ function get_hg_root {
return
fi

CURRENT_DIR=$(dirname $CURRENT_DIR)
CURRENT_DIR=$(dirname "$CURRENT_DIR")
done
}

Expand Down Expand Up @@ -375,8 +389,8 @@ function rvm_version_prompt {
function rbenv_version_prompt {
if which rbenv &> /dev/null; then
rbenv=$(rbenv version-name) || return
$(rbenv commands | grep -q gemset) && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}"
if [ $rbenv != "system" ]; then
$rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}"
if [ "$rbenv" != "system" ]; then
echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX"
fi
fi
Expand All @@ -396,7 +410,7 @@ function chruby_version_prompt {

ruby_version=$(ruby --version | awk '{print $1, $2;}') || return

if [[ ! $(chruby | grep '\*') ]]; then
if ! chruby | grep -q '\*'; then
ruby_version="${ruby_version} (system)"
fi
echo -e "${CHRUBY_THEME_PROMPT_PREFIX}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX}"
Expand All @@ -415,7 +429,7 @@ function k8s_context_prompt {

function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=`basename "$VIRTUAL_ENV"`
virtualenv=$(basename "$VIRTUAL_ENV")
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
fi
}
Expand All @@ -439,7 +453,7 @@ function git_user_info {
# support two or more initials, set by 'git pair' plugin
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
# if `user.initials` weren't set, attempt to extract initials from `user.name`
[[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" $(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done))
[[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" "$(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done)")
[[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX"
}

Expand All @@ -456,7 +470,7 @@ function clock_char {
function clock_prompt {
CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"}
CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"}
[ -z $THEME_SHOW_CLOCK ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"}
[ -z "$THEME_SHOW_CLOCK" ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"}
SHOW_CLOCK=$THEME_SHOW_CLOCK

if [[ "${SHOW_CLOCK}" = "true" ]]; then
Expand Down