Merge pull request #1 from kigster/kig/powerline-enhancements

Various powerlline enhancements and simplification
pull/1944/head
Konstantin Gredeskoul 2021-05-10 02:47:12 -07:00 committed by GitHub
commit 93214cfcce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 556 additions and 378 deletions

View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
# vim: ft=bash:
# @author: Konstantin Gredeskoul
# @since: 04/08/2021
# @description Defines a functino for quickly changing theme color
function bashit.colorscheme() {
local scheme="$1"
[[ -z "${scheme}" ]] && {
if [[ "${ITERM_PROFILE}" =~ "Light" || "${ITERM_PROFILE}" =~ "light" ]]; then
export scheme=light
else
export scheme=dark
fi
}
local theme="${BASH_IT}/colorschemes/${scheme}.colorscheme.bash"
if [[ -f ${theme} ]]; then
source "${theme}"
else
echo "Invlaid theme name: ${scheme}, file ${theme} ain't a livin thang."
fi
}
function promptly.color() {
bashit.colorsscheme "$@"
}
export THEME_RUBRIC="ruby scm cwd | time "
function promptly() {
echo
}
function promptlyt() {
echo
}
function powerline.prompt.templates() {
local t=${1}
bashit.colorsscheme "$@"
}
powerline.prompt.git.max
powerline.prompt.left aws ruby haskell go scm cwd
powerline.prompt.right user_info clock battery
bashit.colorscheme dark

View File

@ -1,14 +1,14 @@
CLOCK_THEME_PROMPT_COLOR=124 CLOCK_THEME_PROMPT_COLOR=124
CWD_THEME_PROMPT_COLOR=311 CWD_THEME_PROMPT_COLOR=111
HOST_THEME_PROMPT_COLOR=6 HOST_THEME_PROMPT_COLOR=99
SCM_THEME_PROMPT_CLEAN_COLOR=4 SCM_THEME_PROMPT_CLEAN_COLOR=4
SCM_THEME_PROMPT_STAGED_COLOR=2563 SCM_THEME_PROMPT_STAGED_COLOR=2563
SCM_THEME_PROMPT_DIRTY_COLOR=2561 SCM_THEME_PROMPT_DIRTY_COLOR=2561
SCM_THEME_PROMPT_UNSTAGED_COLOR=209 SCM_THEME_PROMPT_UNSTAGED_COLOR=209
USER_INFO_THEME_PROMPT_COLOR=196 USER_INFO_THEME_PROMPT_COLOR=126
GO_THEME_PROMPT_COLOR=19 GO_THEME_PROMPT_COLOR=19
POWERLINE_GO_COLOR=33 POWERLINE_GO_COLOR=33
NODE_THEME_PROMPT_COLOR=26
#CLOCK_THEME_PROMPT_COLOR=214 #CLOCK_THEME_PROMPT_COLOR=214
#CWD_THEME_PROMPT_COLOR=123 #CWD_THEME_PROMPT_COLOR=123
@ -20,3 +20,4 @@ POWERLINE_GO_COLOR=33
#USER_INFO_THEME_PROMPT_COLOR=46 #USER_INFO_THEME_PROMPT_COLOR=46
#GO_THEME_PROMPT_COLOR=33 #GO_THEME_PROMPT_COLOR=33
#POWERLINE_GO_COLOR=33 #POWERLINE_GO_COLOR=33

View File

@ -1,8 +1,8 @@
CLOCK_THEME_PROMPT_COLOR=214 CLOCK_THEME_PROMPT_COLOR=131
CWD_THEME_PROMPT_COLOR=123 CWD_THEME_PROMPT_COLOR=153
HOST_THEME_PROMPT_COLOR=9 HOST_THEME_PROMPT_COLOR=9
RUBY_THEME_PROMPT_COLOR=202 RUBY_THEME_PROMPT_COLOR=202
SCM_THEME_PROMPT_CLEAN_COLOR=560 SCM_THEME_PROMPT_CLEAN_COLOR=177
SCM_THEME_PROMPT_DIRTY_COLOR=220 SCM_THEME_PROMPT_DIRTY_COLOR=220
SCM_THEME_PROMPT_STAGED_COLOR=1251 SCM_THEME_PROMPT_STAGED_COLOR=1251
SCM_THEME_PROMPT_UNSTAGED_COLOR=209 SCM_THEME_PROMPT_UNSTAGED_COLOR=209

View File

@ -0,0 +1,24 @@
CLOCK_THEME_PROMPT_COLOR=93
CLOUD_THEME_PROMPT_COLOR=161
COMMAND_NUMBER_THEME_PROMPT_COLOR=24
CWD_THEME_PROMPT_COLOR=23
DIRSTACK_THEME_PROMPT_COLOR=190
HISTORY_NUMBER_THEME_PROMPT_COLOR=234
HOST_THEME_PROMPT_COLOR=133
IN_TOOLBOX_THEME_PROMPT_COLOR=125
IN_VIM_THEME_PROMPT_COLOR=245
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=26
LAST_STATUS_THEME_PROMPT_COLOR=52
NODE_THEME_PROMPT_COLOR=22
PYTHON_VENV_THEME_PROMPT_COLOR=35
RUBY_THEME_PROMPT_COLOR=161
SHLVL_THEME_PROMPT_COLOR=123
TERRAFORM_THEME_PROMPT_COLOR=161
USER_INFO_THEME_PROMPT_COLOR_SUDO=202
SCM_THEME_PROMPT_COLOR=37
SCM_THEME_PROMPT_CLEAN_COLOR=324
SCM_THEME_PROMPT_STAGED_COLOR=2513
SCM_THEME_PROMPT_DIRTY_COLOR=2519
SCM_THEME_PROMPT_UNSTAGED_COLOR=209

View File

@ -180,12 +180,12 @@ function scm_prompt_info_common {
{ [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true { [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true
} }
function terraform_workspace_prompt() { function terraform_workspace_prompt {
if _command_exists terraform; then if _command_exists terraform; then
if [ -d .terraform ]; then if [ -d .terraform ]; then
echo -e "$(terraform workspace show 2>/dev/null)" echo -e "$(terraform workspace show 2>/dev/null)"
fi fi
fi fi
} }
function active_gcloud_account_prompt { function active_gcloud_account_prompt {
@ -194,7 +194,7 @@ function active_gcloud_account_prompt {
fi fi
} }
function git_prompt_minimal_info() { function git_prompt_minimal_info {
SCM_STATE=${SCM_THEME_PROMPT_CLEAN} SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
_git-hide-status && return _git-hide-status && return
@ -290,27 +290,27 @@ function git_prompt_vars {
SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "") SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "")
} }
function p4_prompt_vars() { function p4_prompt_vars {
IFS=$'\t' read -r \ IFS=$'\t' read -r \
opened_count non_default_changes default_count \ opened_count non_default_changes default_count \
add_file_count edit_file_count delete_file_count \ add_file_count edit_file_count delete_file_count \
<<<"$(_p4-opened-counts)" <<<"$(_p4-opened-counts)"
if [[ "${opened_count}" -gt 0 ]]; then if [[ "${opened_count}" -gt 0 ]]; then
SCM_DIRTY=1 SCM_DIRTY=1
SCM_STATE=${SCM_THEME_PROMPT_DIRTY} SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
[[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR}${opened_count}" [[ "${opened_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_OPENED_CHAR}${opened_count}"
[[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR}${non_default_changes}" [[ "${non_default_changes}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_CHANGES_CHAR}${non_default_changes}"
[[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR}${default_count}" [[ "${default_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_P4_DEFAULT_CHAR}${default_count}"
else else
SCM_DIRTY=0 SCM_DIRTY=0
SCM_STATE=${SCM_THEME_PROMPT_DIRTY} SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
fi fi
SCM_PREFIX=${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_PREFIX=${P4_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
} }
function svn_prompt_vars() { function svn_prompt_vars {
if [[ -n $(svn status | head -c1 2>/dev/null) ]]; then if [[ -n $(svn status | head -c1 2>/dev/null) ]]; then
SCM_DIRTY=1 SCM_DIRTY=1
SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
@ -331,48 +331,48 @@ function svn_prompt_vars() {
# - lets say we cd into ~/Projects/Foo/Bar # - lets say we cd into ~/Projects/Foo/Bar
# - .hg is located in ~/Projects/Foo/.hg # - .hg is located in ~/Projects/Foo/.hg
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo # - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
function get_hg_root() { function get_hg_root {
local CURRENT_DIR=$(pwd) local CURRENT_DIR=$(pwd)
while [ "$CURRENT_DIR" != "/" ]; do while [ "$CURRENT_DIR" != "/" ]; do
if [ -d "$CURRENT_DIR/.hg" ]; then if [ -d "$CURRENT_DIR/.hg" ]; then
echo "$CURRENT_DIR/.hg" echo "$CURRENT_DIR/.hg"
return return
fi fi
CURRENT_DIR=$(dirname "$CURRENT_DIR") CURRENT_DIR=$(dirname "$CURRENT_DIR")
done done
} }
function hg_prompt_vars() { function hg_prompt_vars {
if [[ -n $(hg status 2>/dev/null) ]]; then if [[ -n $(hg status 2>/dev/null) ]]; then
SCM_DIRTY=1 SCM_DIRTY=1
SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else else
SCM_DIRTY=0 SCM_DIRTY=0
SCM_STATE=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} SCM_STATE=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
fi fi
SCM_PREFIX=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_PREFIX=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} SCM_SUFFIX=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
HG_ROOT=$(get_hg_root) HG_ROOT=$(get_hg_root)
if [ -f "$HG_ROOT/branch" ]; then if [ -f "$HG_ROOT/branch" ]; then
# Mercurial holds it's current branch in .hg/branch file # Mercurial holds it's current branch in .hg/branch file
SCM_BRANCH=$(cat "$HG_ROOT/branch") SCM_BRANCH=$(cat "$HG_ROOT/branch")
else else
SCM_BRANCH=$(hg summary 2>/dev/null | grep branch: | awk '{print $2}') SCM_BRANCH=$(hg summary 2>/dev/null | grep branch: | awk '{print $2}')
fi fi
if [ -f "$HG_ROOT/dirstate" ]; then if [ -f "$HG_ROOT/dirstate" ]; then
# Mercurial holds various information about the working directory in .hg/dirstate file. More on http://mercurial.selenic.com/wiki/DirState # Mercurial holds various information about the working directory in .hg/dirstate file. More on http://mercurial.selenic.com/wiki/DirState
SCM_CHANGE=$(hexdump -vn 10 -e '1/1 "%02x"' "$HG_ROOT/dirstate" | cut -c-12) SCM_CHANGE=$(hexdump -vn 10 -e '1/1 "%02x"' "$HG_ROOT/dirstate" | cut -c-12)
else else
SCM_CHANGE=$(hg summary 2>/dev/null | grep parent: | awk '{print $2}') SCM_CHANGE=$(hg summary 2>/dev/null | grep parent: | awk '{print $2}')
fi fi
} }
function nvm_version_prompt() { function nvm_version_prompt {
local node local node
if declare -f -F nvm &>/dev/null; then if declare -f -F nvm &>/dev/null; then
node=$(nvm current 2>/dev/null) node=$(nvm current 2>/dev/null)
@ -381,20 +381,11 @@ function nvm_version_prompt() {
fi fi
} }
function npm_version_prompt() { function node_version_prompt {
local node
if declare -f -F npm &>/dev/null; then
node=$(nvm current 2>/dev/null)
[[ "${node}" == "system" ]] && return
echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}"
fi
}
function node_version_prompt() {
echo -e "$(nvm_version_prompt)" echo -e "$(nvm_version_prompt)"
} }
function rvm_version_prompt() { function rvm_version_prompt {
if which rvm &>/dev/null; then if which rvm &>/dev/null; then
rvm=$(rvm-prompt) || return rvm=$(rvm-prompt) || return
if [ -n "$rvm" ]; then if [ -n "$rvm" ]; then
@ -403,9 +394,9 @@ function rvm_version_prompt() {
fi fi
} }
function rbenv_version_prompt() { function rbenv_version_prompt {
if which rbenv &>/dev/null; then if which rbenv &>/dev/null; then
rbenv=$(rbenv version-name) || return: rbenv=$(rbenv version-name) || return
rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2>/dev/null) && rbenv="$rbenv@${gemset%% *}" rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2>/dev/null) && rbenv="$rbenv@${gemset%% *}"
if [ "$rbenv" != "system" ]; then if [ "$rbenv" != "system" ]; then
echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX" echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX"
@ -413,13 +404,13 @@ function rbenv_version_prompt() {
fi fi
} }
function rbfu_version_prompt() { function rbfu_version_prompt {
if [[ $RBFU_RUBY_VERSION ]]; then if [[ $RBFU_RUBY_VERSION ]]; then
echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}" echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}"
fi fi
} }
function chruby_version_prompt() { function chruby_version_prompt {
if declare -f -F chruby &>/dev/null; then if declare -f -F chruby &>/dev/null; then
if declare -f -F chruby_auto &>/dev/null; then if declare -f -F chruby_auto &>/dev/null; then
chruby_auto chruby_auto
@ -434,39 +425,39 @@ function chruby_version_prompt() {
fi fi
} }
function ruby_version_prompt() { function ruby_version_prompt {
if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)" echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
fi fi
} }
function k8s_context_prompt() { function k8s_context_prompt {
echo -e "$(kubectl config current-context 2>/dev/null)" echo -e "$(kubectl config current-context 2>/dev/null)"
} }
function virtualenv_prompt() { function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=$(basename "$VIRTUAL_ENV") virtualenv=$(basename "$VIRTUAL_ENV")
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
fi fi
} }
function condaenv_prompt() { function condaenv_prompt {
if [[ $CONDA_DEFAULT_ENV ]]; then if [[ $CONDA_DEFAULT_ENV ]]; then
echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}" echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}"
fi fi
} }
function py_interp_prompt() { function py_interp_prompt {
py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return
echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}" echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}"
} }
function python_version_prompt() { function python_version_prompt {
echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)" echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)"
} }
function git_user_info() { function git_user_info {
# support two or more initials, set by 'git pair' plugin # support two or more initials, set by 'git pair' plugin
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%') SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
# if `user.initials` weren't set, attempt to extract initials from `user.name` # if `user.initials` weren't set, attempt to extract initials from `user.name`
@ -474,7 +465,7 @@ function git_user_info() {
[[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX" [[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX"
} }
function clock_char() { function clock_char {
CLOCK_CHAR=${THEME_CLOCK_CHAR:-"⌚"} CLOCK_CHAR=${THEME_CLOCK_CHAR:-"⌚"}
CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"} CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"}
SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"} SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
@ -484,7 +475,7 @@ function clock_char() {
fi fi
} }
function clock_prompt() { function clock_prompt {
CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"} CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"}
CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"} 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"}
@ -496,14 +487,14 @@ function clock_prompt() {
fi fi
} }
function user_host_prompt() { function user_host_prompt {
if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then
echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}" echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}"
fi fi
} }
# backwards-compatibility # backwards-compatibility
function git_prompt_info() { function git_prompt_info {
_git-hide-status && return _git-hide-status && return
git_prompt_vars git_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
@ -514,7 +505,7 @@ function p4_prompt_info() {
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}" echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}"
} }
function svn_prompt_info() { function svn_prompt_info {
svn_prompt_vars svn_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}" echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
} }
@ -524,39 +515,39 @@ function hg_prompt_info() {
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}" echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}"
} }
function scm_char() { function scm_char {
scm_prompt_char scm_prompt_char
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}" echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
} }
function prompt_char() { function prompt_char {
scm_char scm_char
} }
function battery_char() { function battery_char {
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
echo -e "${bold_red}$(battery_percentage)%" echo -e "${bold_red}$(battery_percentage)%"
fi fi
} }
if ! _command_exists battery_charge; then if ! _command_exists battery_charge; then
# if user has installed battery plugin, skip this... # if user has installed battery plugin, skip this...
function battery_charge() { function battery_charge() {
# no op # no op
echo -n echo -n
} }
fi fi
# The battery_char function depends on the presence of the battery_percentage function. # The battery_char function depends on the presence of the battery_percentage function.
# If battery_percentage is not defined, then define battery_char as a no-op. # If battery_percentage is not defined, then define battery_char as a no-op.
if ! _command_exists battery_percentage; then if ! _command_exists battery_percentage; then
function battery_char() { function battery_char() {
# no op # no op
echo -n echo -n
} }
fi fi
function aws_profile() { function aws_profile {
if [[ $AWS_DEFAULT_PROFILE ]]; then if [[ $AWS_DEFAULT_PROFILE ]]; then
echo -e "${AWS_DEFAULT_PROFILE}" echo -e "${AWS_DEFAULT_PROFILE}"
else else
@ -564,71 +555,74 @@ function aws_profile() {
fi fi
} }
function __check_precmd_conflict() {
local f function npm_version_prompt() {
for f in "${precmd_functions[@]}"; do local node
if [[ "${f}" == "${1}" ]]; then if declare -f -F npm &>/dev/null; then
return 0 node=$(nvm current 2>/dev/null)
[[ "${node}" == "system" ]] && return
echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}"
fi
}
function prompt_colorscheme() {
[[ -z "${BASH_IT_COLORSCHEME}" ]] && return
local -a colorscheme_locations=(
"${HOME}/.${BASH_IT_COLORSCHEME}.colorscheme.bash"
"$BASH_IT/custom/${BASH_IT_COLORSCHEME}.colorscheme.bash"
"$BASH_IT/colorschemes/${BASH_IT_COLORSCHEME}.colorscheme.bash"
)
for scheme_file in ${colorscheme_locations[@]}; do
if [[ -f ${scheme_file} ]]; then
source "${scheme_file}"
fi fi
done done
return 1
} }
function safe_append_prompt_command() {
local prompt_re
if [ "${__bp_imported}" == "defined" ]; then
# We are using bash-preexec
if ! __check_precmd_conflict "${1}"; then
precmd_functions+=("${1}")
fi
else
# Set OS dependent exact match regular expression
if [[ ${OSTYPE} == darwin* ]]; then
# macOS
prompt_re="[[:<:]]${1}[[:>:]]"
else
# Linux, FreeBSD, etc.
prompt_re="\<${1}\>"
fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then function __check_precmd_conflict() {
return local f
elif [[ -z ${PROMPT_COMMAND} ]]; then for f in "${precmd_functions[@]}"; do
PROMPT_COMMAND="${1}" if [[ "${f}" == "${1}" ]]; then
else return 0
PROMPT_COMMAND="${1};${PROMPT_COMMAND}" fi
fi done
fi return 1
} }
function safe_append_prompt_command_kig() { function _save-and-reload-history() {
local prompt_re local autosave=${1:-0}
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
}
prompt_colorscheme function safe_append_prompt_command {
local prompt_re
if [ "${__bp_imported}" == "defined" ]; then if [ "${__bp_imported}" == "defined" ]; then
# We are using bash-preexec # We are using bash-preexec
if ! __check_precmd_conflict "${1}"; then if ! __check_precmd_conflict "${1}"; then
precmd_functions+=("${1}") precmd_functions+=("${1}")
fi fi
else else
# Set OS dependent exact match regular expression # Set OS dependent exact match regular expression
if [[ ${OSTYPE} == darwin* ]]; then if [[ ${OSTYPE} == darwin* ]]; then
# macOS # macOS
prompt_re="[[:<:]]${1}[[:>:]]" prompt_re="[[:<:]]${1}[[:>:]]"
else else
# Linux, FreeBSD, etc. # Linux, FreeBSD, etc.
prompt_re="\<${1}\>" prompt_re="\<${1}\>"
fi fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
return return
elif [[ -z ${PROMPT_COMMAND} ]]; then elif [[ -z ${PROMPT_COMMAND} ]]; then
PROMPT_COMMAND="${1}" PROMPT_COMMAND="${1}"
else else
PROMPT_COMMAND="${1};${PROMPT_COMMAND}" PROMPT_COMMAND="${1};${PROMPT_COMMAND}"
fi fi
fi fi
} }
function _save-and-reload-history() { function _save-and-reload-history() {

View File

@ -21,23 +21,23 @@ function __powerline_user_info_prompt() {
local color=${USER_INFO_THEME_PROMPT_COLOR} local color=${USER_INFO_THEME_PROMPT_COLOR}
if [[ "${THEME_CHECK_SUDO}" = true ]]; then if [[ "${THEME_CHECK_SUDO}" = true ]]; then
sudo -vn 1> /dev/null 2>&1 && color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} sudo -vn 1>/dev/null 2>&1 && color=${USER_INFO_THEME_PROMPT_COLOR_SUDO}
fi fi
case "${POWERLINE_PROMPT_USER_INFO_MODE}" in case "${POWERLINE_PROMPT_USER_INFO_MODE}" in
"sudo") "sudo")
if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then
user_info="!" user_info="!"
fi fi
;; ;;
*) *)
local user=${SHORT_USER:-${USER}} local user=${SHORT_USER:-${USER}}
if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then
user_info="${USER_INFO_SSH_CHAR}${user}" user_info="${USER_INFO_SSH_CHAR}${user}"
else else
user_info="${user}" user_info="${user}"
fi fi
;; ;;
esac esac
[[ -n "${user_info}" ]] && echo "${user_info}|${color}" [[ -n "${user_info}" ]] && echo "${user_info}|${color}"
} }
@ -78,29 +78,29 @@ function __powerline_ruby_prompt() {
} }
function __find_nearest_go_mod() { function __find_nearest_go_mod() {
local path="${PWD}" local path="${PWD}"
while true; do while true; do
[[ -z "${path}" || ${path} == "/" ]] && break [[ -z "${path}" || ${path} == "/" ]] && break
if [[ -f "${path}/go.mod" ]]; then if [[ -f "${path}/go.mod" ]]; then
printf "${path}/go.mod" printf "${path}/go.mod"
return 0 return 0
fi fi
path=$(dirname ${path}) path=$(dirname ${path} 2>/dev/null)
done done
} }
function __powerline_go_prompt { function __powerline_go_prompt {
local go_version="" local go_version=""
if _command_exists go ; then if _command_exists go; then
local go_mod=$(__find_nearest_go_mod) local go_mod=$(__find_nearest_go_mod)
[[ -n "${go_mod}" && -f "${go_mod}" ]] || return [[ -n "${go_mod}" && -f "${go_mod}" ]] || return
local -a go_version_output local -a go_version_output
mapfile -t go_version_output < <(egrep '^go ' ${go_mod} | tr ' ' '\n') mapfile -t go_version_output < <(egrep '^go ' ${go_mod} | tr ' ' '\n')
go_version="${go_version_output[1]}" go_version="${go_version_output[1]}"
fi fi
[[ -n "${go_version}" ]] && echo "${GO_CHAR}${go_version}|${GO_THEME_PROMPT_COLOR}" [[ -n "${go_version}" ]] && echo "${GO_CHAR}${go_version}|${GO_THEME_PROMPT_COLOR}"
} }
function __powerline_k8s_context_prompt() { function __powerline_k8s_context_prompt() {
@ -158,21 +158,21 @@ function __powerline_scm_prompt() {
function __powerline_cwd_prompt() { function __powerline_cwd_prompt() {
local cwd local cwd
local max_width local max_width
local screen_width local screen_width
if [[ -n "${CWD_SHORTEN_SCREEN_PERCENT}" ]]; then if [[ -n "${CWD_SHORTEN_SCREEN_PERCENT}" ]]; then
screen_width=$(.powerline.screen-width) screen_width=$(.powerline.screen-width)
max_width=$(( screen_width * CWD_SHORTEN_SCREEN_PERCENT / 100 )) max_width=$((screen_width * CWD_SHORTEN_SCREEN_PERCENT / 100))
elif [[ -n "${CWD_SHORTEN_TO}" ]]; then elif [[ -n "${CWD_SHORTEN_TO}" ]]; then
max_width=${CWD_SHORTEN_TO} max_width=${CWD_SHORTEN_TO}
fi fi
if [[ -n ${max_width} ]]; then if [[ -n ${max_width} ]]; then
cwd=$(cwd.shorten "${max_width}" "${PWD}") cwd=$(cwd.shorten "${max_width}" "${PWD}")
else else
cwd=$(pwd | sed "s|^${HOME}|~|") cwd=$(pwd | sed "s|^${HOME}|~|")
fi fi
echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
} }
function __powerline_hostname_prompt() { function __powerline_hostname_prompt() {
@ -189,7 +189,7 @@ function __powerline_clock_prompt() {
function __powerline_battery_prompt() { function __powerline_battery_prompt() {
local color="" local color=""
local battery_status="$(battery_percentage 2> /dev/null)" local battery_status="$(battery_percentage 2>/dev/null)"
if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then
true true
@ -253,7 +253,7 @@ function __powerline_command_number_prompt() {
function __powerline_left_segment() { function __powerline_left_segment() {
local params local params
IFS="|" read -ra params <<< "${1}" IFS="|" read -ra params <<<"${1}"
local pad_before_segment=" " local pad_before_segment=" "
if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
# vim: ft=bash
# A bunch of Powerline Prompt Helper functions that # A bunch of Powerline Prompt Helper functions that
# change which compnents are shown, and to what level of detail to # change which compnents are shown, and to what level of detail to
# render the Git/SCM info. # render the Git/SCM info.
@ -9,257 +11,361 @@
# to render the `powerline.prompt.git.max()` and powerline.prompt.all # to render the `powerline.prompt.git.max()` and powerline.prompt.all
# @description # @description
# This function returns a shortened # This function returns a shortened
# @see: https://stackoverflow.com/questions/1616678/bash-pwd-shortening # @see: https://stackoverflow.com/questions/1616678/bash-pwd-shortening
export POWERLINE_SHORT_CWD_WIDTH=30 export POWERLINE_SHORT_CWD_WIDTH=40
function cwd.shorten() { function cwd.shorten() {
local begin="" # The unshortened beginning of the path. local begin="" # The unshortened beginning of the path.
local shortbegin="" # The shortened beginning of the path. local shortbegin="" # The shortened beginning of the path.
local current="" # The section of the path we're currently working on. local current="" # The section of the path we're currently working on.
local end="${2:-$(pwd)}/" # The unmodified rest of the path. local end="${2:-$(pwd)}/" # The unmodified rest of the path.
if [[ "$end" =~ "${HOME}" ]]; then if [[ "$end" =~ ${HOME} ]]; then
INHOME=1 INHOME=1
end="${end#$HOME}" #strip /home/username from start of string end="${end#$HOME}" #strip /home/username from start of string
begin="$HOME" #start expansion from the right spot begin="$HOME" #start expansion from the right spot
else else
INHOME=0 INHOME=0
fi fi
local end="${end#/}" # Strip the first / local end="${end#/}" # Strip the first /
local shortenedpath="$end" # The whole path, to check the length. local shortenedpath="$end" # The whole path, to check the length.
local maxlength="${1:-${POWERLINE_SHORT_CWD_WIDTH}}" local maxlength="${1:-${POWERLINE_SHORT_CWD_WIDTH}}"
shopt -q nullglob && NGV="-s" || NGV="-u" # Store the value for later. shopt -q nullglob && NGV="-s" || NGV="-u" # Store the value for later.
shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/... shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/...
while [[ "$end" ]] && (( ${#shortenedpath} > maxlength )) while [[ "$end" ]] && ((${#shortenedpath} > maxlength)); do
do current="${end%%/*}" # everything before the first /
current="${end%%/*}" # everything before the first / end="${end#*/}" # everything after the first /
end="${end#*/}" # everything after the first /
shortcurstar="$current" # No star if we don't shorten it. shortcurstar="$current" # No star if we don't shorten it.
for ((i=${#current}-2; i>=0; i--)); do for ((i = ${#current} - 2; i >= 0; i--)); do
subcurrent="${current:0:i}" subcurrent="${current:0:i}"
matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent. matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent.
(( ${#matching[*]} != 1 )) && break # Stop shortening if more than one file matches. ((${#matching[*]} != 1)) && break # Stop shortening if more than one file matches.
shortcurstar="${subcurrent}" shortcurstar="${subcurrent}"
done done
#a dvance #a dvance
begin="$begin/$current" begin="$begin/$current"
shortbegin="$shortbegin/$shortcurstar" shortbegin="$shortbegin/$shortcurstar"
shortenedpath="$shortbegin/$end" shortenedpath="$shortbegin/$end"
done done
shortenedpath="${shortenedpath%/}" # strip trailing / shortenedpath="${shortenedpath%/}" # strip trailing /
shortenedpath="${shortenedpath#/}" # strip leading / shortenedpath="${shortenedpath#/}" # strip leading /
if [ $INHOME -eq 1 ]; then if [ $INHOME -eq 1 ]; then
echo "~/$shortenedpath" #make sure it starts with ~/ echo "~/$shortenedpath" #make sure it starts with ~/
else else
echo "/$shortenedpath" # Make sure it starts with / echo "/$shortenedpath" # Make sure it starts with /
fi fi
shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function. shopt "$NGV" nullglob # Rerandomize nullglob in case this is being used as a function.
} }
# Powerline Prompt Configuration # Powerline Prompt Configuration
function powerline.prompt.git.max() { function powerline.prompt.git.max() {
export SCM_GIT_SHOW_MINIMAL_INFO=false export SCM_GIT_SHOW_MINIMAL_INFO=false
export SCM_GIT_SHOW_COMMIT_COUNT=true
export SCM_GIT_SHOW_CURRENT_USER=true
export SCM_GIT_SHOW_DETAILS=true
export SCM_GIT_SHOW_REMOTE_INFO=true
export SCM_GIT_SHOW_STASH_INFO=true
export SCM_GIT_SHOW_COMMIT_COUNT=true
export SCM_GIT_SHOW_CURRENT_USER=true
export SCM_GIT_SHOW_DETAILS=true
export SCM_GIT_SHOW_REMOTE_INFO=true
export SCM_GIT_SHOW_STASH_INFO=true
} }
function powerline.prompt.git.min() { function powerline.prompt.git.min() {
export SCM_GIT_SHOW_MINIMAL_INFO=true export SCM_GIT_SHOW_MINIMAL_INFO=true
export SCM_GIT_SHOW_CURRENT_USER=false export SCM_GIT_SHOW_CURRENT_USER=false
export SCM_GIT_SHOW_DETAILS=false export SCM_GIT_SHOW_DETAILS=false
export SCM_GIT_SHOW_COMMIT_COUNT=false export SCM_GIT_SHOW_COMMIT_COUNT=false
export SCM_GIT_SHOW_REMOTE_INFO=false export SCM_GIT_SHOW_REMOTE_INFO=false
export SCM_GIT_SHOW_STASH_INFO=false export SCM_GIT_SHOW_STASH_INFO=false
} }
function powerline.prompt.git.default() { function powerline.prompt.git.default() {
export SCM_GIT_SHOW_MINIMAL_INFO=false export SCM_GIT_SHOW_MINIMAL_INFO=false
export SCM_GIT_SHOW_CURRENT_USER=true export SCM_GIT_SHOW_CURRENT_USER=true
export SCM_GIT_SHOW_DETAILS=true export SCM_GIT_SHOW_DETAILS=true
export SCM_GIT_SHOW_COMMIT_COUNT=false export SCM_GIT_SHOW_COMMIT_COUNT=false
export SCM_GIT_SHOW_REMOTE_INFO=false export SCM_GIT_SHOW_REMOTE_INFO=false
export SCM_GIT_SHOW_STASH_INFO=true export SCM_GIT_SHOW_STASH_INFO=true
} }
.powerline.screen-width() { .powerline.screen-width() {
local w local w
local os=$(uname -s) local os=$(uname -s)
if [[ $os == 'Darwin' ]]; then if [[ $os == 'Darwin' ]]; then
w=$(stty -a 2>/dev/null | grep columns | awk '{print $6}'); w=$(stty -a 2>/dev/null | grep columns | awk '{print $6}')
else else
w=$(stty -a 2>/dev/null | grep columns | awk '{print $7}' | sed -E 's/;//g'); w=$(stty -a 2>/dev/null | grep columns | awk '{print $7}' | sed -E 's/;//g')
fi fi
printf -- "%d" ${w} printf -- "%d" "${w}"
} }
# Filter/convert components passed as arguments to the # Filter/convert components passed as arguments to the
# correct powerline modules # correct powerline modules
# @example: .powerline.components ruby python k8 garbage # @example: powerline.filter-and-print ruby python k8 garbages
# @output: ruby python_venv k8s_context # @output: ruby python_venv k8s_context
function .powerline.components() { function powerline.filter-and-print() {
local -a components local -a components
components=() components=()
for c in "$@"; do for c in "$@"; do
[[ ${c} == "python" ]] && c="python_venv" [[ ${c} == "python" ]] && c="python_venv"
[[ ${c} == "k8" ]] && c="k8s_context" [[ ${c} == "k8" ]] && c="k8s_context"
local func="__powerline_${c}_prompt" local func="__powerline_${c}_prompt"
type "$func" 2> /dev/null | head -1 | grep -q 'is a function' && components+=("${c}") type "$func" 2>/dev/null | head -1 | grep -q 'is a function' && components+=("${c}")
done done
echo "${components[@]}" echo "${components[*]}"
} }
function .powerline.supported.components() { function powerline.components.bulleted-list() {
set | grep -E '^__powerline_.*_prompt' | sed 's/__powerline_//g; s/_prompt.*$//g; s/^/ • /g' set | grep -E '^__powerline_.*_prompt' | sed 's/__powerline_//g; s/_prompt.*$//g; s/^/ • /g' | sort
} }
# usage: powerline.prompt.set [ lang [ lang ]... ] function powerline.components.array() {
# eg: powerline.prompt.set cwd ruby go node battery set | grep -E '^__powerline_.*_prompt' | sed 's/__powerline_//g; s/_prompt.*$//g;' | tr '\n' ' '
function powerline.prompt.set() { echo
[[ -z "$*" ]] && { }
echo -e "${echo_bold_red}Please pass an argument list of components you'd like to see in the PROMPT.${echo_reset_color}"
echo -e "${echo_bold_yellow}Here is the list of all currently supported components:${echo_green}\n"
.powerline.supported.components
echo -e "${echo_reset_color}"
return
}
local -a components function powerline.invalid-arguments() {
components=($(.powerline.components "$@")) echo -e "${echo_bold_red}ERROR:\n\tPlease pass an argument list of components " \
"you'd like to\n\tsee in the PROMPT.${echo_normal}\n"
echo -e "${echo_bold_yellow}\tHere is the list of all currently supported components:\n\t${echo_green}"
powerline.components.bulleted-list
echo -e "${echo_normal}"
}
local count="${#components[@]}" function array.random-sort() {
local half="$(( count / 2 ))" local -a randomized
local even=0
[[ $(( count % 2 )) -eq 0 ]] && even=1
local half_plus_one="$((half+1))" # shellcheck disable=2207
randomized=(
$(
for c in "$@"; do
echo "${c}"
done | sort -R | tr '\n' ' '
)
)
# shellcheck disable=2207
printf "%s" "${randomized[*]}"
}
# Single-line Powerline Prompts # @description You can pass an array of the components either
export POWERLINE_PROMPT="${components[*]}" # as a single space-separate string, of pass two
# strings for left/right components.
# Multiline Powerline Prompts # @exmples
export POWERLINE_LEFT_PROMPT="${components[@]:0:${half_plus_one}}" # # the first example will invoke powerline-multiline prompt:
if (( even )); then # $ powerline.prompt.choose "cwd ruby go" "battery cpu time"
export POWERLINE_RIGHT_PROMPT="${components[@]:${half_plus_one}}" #
else # # while the second will choose single line.
export POWERLINE_RIGHT_PROMPT="${components[@]:${half_plus_one}}" # $ powerline.prompt.choose "cwd ruby go node battery"
#
function powerline.prompt.choose() {
[[ -z "$*" ]] && {
powerline.invalid-arguments
echo
echo "Please note: you can pass the components as a single string,"
echo "or as two strings, in which case first one becomes left,"
echo "and the second becomes right component."
return 1
}
local left="$1"
local right="$2"
if [[ -z ${right} ]]; then
export BASH_IT_THEME="powerline"
export POWERLINE_PROMPT="$(powerline.filter-and-print "$*")"
else
export BASH_IT_THEME="powerline-multiline"
for component_string in "left" "right"; do
local -a components
# shellcheck disable=2206
components=(${!component_string})
# shellcheck disable=2207
components=($(powerline.filter-and-print "${components[*]}"))
done
fi fi
} }
# usage: powerline.prompt.randomize [ lang [ lang ]... ]
# eg: powerline.prompt.randomize cwd ruby go node battery
function powerline.prompt.randomize() {
local -a components
if [[ -z $* ]]; then
# shellcheck disable=2207
components=($( array.random-sort $(powerline.components.array)))
else
# shellcheck disable=2207
components=($(powerline.filter-and-print "$@"))
fi
local count="${#components[@]}"
local half="$((count / 2))"
local even=0
[[ $((count % 2)) -eq 0 ]] && even=1
local half_plus_one="$((half + 1))"
# Single-line Powerline Prompts
export POWERLINE_PROMPT="${components[*]}"
# Multiline Powerline Prompts
export POWERLINE_LEFT_PROMPT="${components[*]:0:${half_plus_one}}"
if ((even)); then
export POWERLINE_RIGHT_PROMPT="${components[*]:${half_plus_one}}"
else
export POWERLINE_RIGHT_PROMPT="${components[*]:${half_plus_one}}"
fi
}
function powerline.prompt.show() { function powerline.prompt.show() {
if [[ $BASH_IT_THEME =~ "multiline" ]]; then if [[ $BASH_IT_THEME =~ "multiline" ]]; then
powerline.prompt.set-left-to echo "Left Side:"
powerline.prompt.set-right-to powerline.prompt.echo-prompt left
echo "Right Side:"
powerline.prompt.side right
else
powerline.prompt.show-unified
fi
}
# Print the prompt variable, either left/right or signle
function powerline.prompt.prompt-print() {
local side="$1"
local variable="$(powerline.prompt.variable "${side}")"
eval "echo ${!variable}"
}
# Print the prompt variable, either left/right or signle
function powerline.prompt.variable-name() {
local side="$1"
if [[ -z ${side} ]]; then
echo "POWERLINE_PROMPT"
else else
powerline.prompt.set-to echo "POWERLINE_${side^}_PROMPT"
fi fi
} }
function powerline.prompt.set-to() { # @description Set left, right or the unified prompt
if [[ -z $* ]]; then # @example
echo "${POWERLINE_PROMPT}" # powerline.prompt.set left "scm git"
function powerline.prompt.set() {
if [[ $BASH_IT_THEME =~ "multiline" ]]; then
local side="$1"; shift
if [[ ${side} != left && ${side} != right ]] ; then
echo "USAGE: powerline.prompt.set[ left | right ] <component.... >" >&2
return 1
fi
local func="powerline.prompt.${side}"
eval "${func} \"$*\""
else else
export POWERLINE_PROMPT="$(.powerline.components "$@")" if [[ -z $* ]]; then
echo "${POWERLINE_PROMPT}"
else
export POWERLINE_PROMPT="$(powerline.filter-and-print "$@")"
fi
fi fi
} }
function powerline.prompt.set-right-to() { function powerline.prompt.right() {
if [[ -z $* ]]; then if [[ -z $* ]]; then
echo "${POWERLINE_RIGHT_PROMPT}" echo "${POWERLINE_RIGHT_PROMPT}"
else else
export POWERLINE_RIGHT_PROMPT="$(.powerline.components "$@")" export POWERLINE_RIGHT_PROMPT="$(powerline.filter-and-print "$@")"
fi fi
} }
function powerline.prompt.set-left-to() { function powerline.prompt.left() {
if [[ -z $* ]]; then if [[ -z $* ]]; then
echo "${POWERLINE_LEFT_PROMPT}" echo "${POWERLINE_LEFT_PROMPT}"
else else
export POWERLINE_LEFT_PROMPT="$(.powerline.components "$@")" export POWERLINE_LEFT_PROMPT="$(powerline.filter-and-print "$@")"
fi fi
}
function powerline.prompt.randomize-to() {
if [[ -z $* ]]; then
echo "${POWERLINE_PROMPT}"
else
export POWERLINE_PROMPT="$(powerline.filter-and-print "$@")"
fi
} }
# @example: powerline.prompt.add-component left ruby # @example: powerline.prompt.add-component left ruby
function powerline.prompt.add-component() { function powerline.prompt.add-component() {
local side="$1" local side="$1"
local func local func
if [[ -n $1 ]] ; then if [[ -n $1 ]]; then
func="powerline.prompt.set-${side}-to" func="powerline.prompt.randomize-${side}-to"
shift shift
else else
func="powerline.prompt.set-to" func="powerline.prompt.randomize-to"
fi fi
${func} $(${func}) "$@" ${func} $(${func}) "$@"
} }
function powerline.prompt.golang() { function powerline.prompt.golang() {
powerline.prompt.add-component left go powerline.prompt.add-component left go
} }
function powerline.prompt.node() { function powerline.prompt.node() {
powerline.prompt.add-component left node powerline.prompt.add-component left node
} }
function powerline.prompt.ruby() { function powerline.prompt.ruby() {
powerline.prompt.add-component left ruby powerline.prompt.add-component left ruby
} }
function powerline.prompt.python() { function powerline.prompt.python() {
powerline.prompt.add-component left python_venv powerline.prompt.add-component left python_venv
} }
## Configure the level of Git Detail ## Configure the level of Git Detail
function powerline.prompt.min() { function powerline.prompt.min() {
export POWERLINE_LEFT_PROMPT="cwd" export POWERLINE_LEFT_PROMPT="cwd"
export POWERLINE_RIGHT_PROMPT="clock user_info hostname" export POWERLINE_RIGHT_PROMPT="clock user_info hostname"
} }
function powerline.prompt.all() { function powerline.prompt.all() {
powerline.prompt powerline.prompt.randomize
export POWERLINE_LEFT_PROMPT="scm clock cwd"
export POWERLINE_RIGHT_PROMPT="user_info hostname battery"
} }
function powerline.prompt.default() { function powerline.prompt.default() {
export POWERLINE_LEFT_PROMPT="scm node ruby go cwd " export POWERLINE_LEFT_PROMPT="scm node ruby go cwd "
export POWERLINE_RIGHT_PROMPT=" clock user_info hostname battery" export POWERLINE_RIGHT_PROMPT=" clock user_info hostname battery"
} }
function powerline.default() { function powerline.default() {
powerline-max powerline.prompt.choose "scm cwd" "clock user"
} }
function powerline.prompt.alternative-symbols() { function powerline.prompt.alternative-symbols() {
export SCM_GIT_CHAR=" Ⓖ " export SCM_GIT_CHAR=" ᛋ "
export USER_INFO_SSH_CHAR="🔐 " export USER_INFO_SSH_CHAR=" 🔐 "
export PYTHON_VENV_CHAR="ⓟ " export PYTHON_VENV_CHAR=" 🐍 "
export CONDA_PYTHON_VENV_CHAR="ⓒⓟ " export CONDA_PYTHON_VENV_CHAR=" 🐍 "
export NODE_CHAR="ⓝ " export NODE_CHAR=" 🅽 "
export RUBY_CHAR="ⓡ " export RUBY_CHAR=" 🔻 "
export GO_CHAR="ⓖ " export GO_CHAR=" 🅶 "
export TERRAFORM_CHAR="ⓣ " export TERRAFORM_CHAR=" 🆃 "
export KUBERNETES_CONTEXT_THEME_CHAR="⎈ " export KUBERNETES_CONTEXT_THEME_CHAR="⎈ "
export AWS_PROFILE_CHAR="«aws» " export AWS_PROFILE_CHAR=" ☁️ "
export BATTERY_AC_CHAR="⚡" export BATTERY_AC_CHAR=" 🔋 "
export IN_VIM_THEME_PROMPT_TEXT="ⓥ " export IN_VIM_THEME_PROMPT_TEXT="ⓥ "
export SHLVL_THEME_PROMPT_CHAR="ⓢ " export SHLVL_THEME_PROMPT_CHAR="ⓢ "
export COMMAND_NUMBER_THEME_PROMPT_CHAR="↳" export COMMAND_NUMBER_THEME_PROMPT_CHAR="↳"
} }