Adding shortening of CWD and Golang
parent
4256dcf54e
commit
a519448852
|
|
@ -1,8 +1,10 @@
|
||||||
CLOCK_THEME_PROMPT_COLOR=92
|
CLOCK_THEME_PROMPT_COLOR=124
|
||||||
CWD_THEME_PROMPT_COLOR=29
|
CWD_THEME_PROMPT_COLOR=311
|
||||||
HOST_THEME_PROMPT_COLOR=6
|
HOST_THEME_PROMPT_COLOR=6
|
||||||
SCM_THEME_PROMPT_CLEAN_COLOR=4
|
SCM_THEME_PROMPT_CLEAN_COLOR=4
|
||||||
SCM_THEME_PROMPT_DIRTY_COLOR=214
|
SCM_THEME_PROMPT_DIRTY_COLOR=202
|
||||||
SCM_THEME_PROMPT_STAGED_COLOR=30
|
SCM_THEME_PROMPT_STAGED_COLOR=30
|
||||||
SCM_THEME_PROMPT_UNSTAGED_COLOR=129
|
SCM_THEME_PROMPT_UNSTAGED_COLOR=129
|
||||||
USER_INFO_THEME_PROMPT_COLOR=196
|
USER_INFO_THEME_PROMPT_COLOR=196
|
||||||
|
GO_THEME_PROMPT_COLOR=19
|
||||||
|
POWERLINE_GO_COLOR=33
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,5 @@ SCM_THEME_PROMPT_DIRTY_COLOR=9
|
||||||
SCM_THEME_PROMPT_STAGED_COLOR=121
|
SCM_THEME_PROMPT_STAGED_COLOR=121
|
||||||
SCM_THEME_PROMPT_UNSTAGED_COLOR=210
|
SCM_THEME_PROMPT_UNSTAGED_COLOR=210
|
||||||
USER_INFO_THEME_PROMPT_COLOR=46
|
USER_INFO_THEME_PROMPT_COLOR=46
|
||||||
|
GO_THEME_PROMPT_COLOR=33
|
||||||
|
POWERLINE_GO_COLOR=33
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ 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)"
|
||||||
|
|
@ -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,7 +290,7 @@ 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 \
|
||||||
|
|
@ -310,7 +310,7 @@ function p4_prompt_vars {
|
||||||
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,7 +331,7 @@ 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
|
||||||
|
|
@ -344,7 +344,7 @@ function get_hg_root {
|
||||||
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}
|
||||||
|
|
@ -372,7 +372,7 @@ function hg_prompt_vars {
|
||||||
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,11 +381,20 @@ function nvm_version_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function node_version_prompt {
|
function npm_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
|
||||||
|
|
@ -394,9 +403,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"
|
||||||
|
|
@ -404,13 +413,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
|
||||||
|
|
@ -425,39 +434,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`
|
||||||
|
|
@ -465,7 +474,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"}
|
||||||
|
|
@ -475,7 +484,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"}
|
||||||
|
|
@ -487,14 +496,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}"
|
||||||
|
|
@ -505,7 +514,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}"
|
||||||
}
|
}
|
||||||
|
|
@ -515,16 +524,16 @@ 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
|
||||||
|
|
@ -547,7 +556,7 @@ if ! _command_exists battery_percentage; then
|
||||||
}
|
}
|
||||||
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
|
||||||
|
|
@ -565,10 +574,8 @@ function __check_precmd_conflict() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_append_prompt_command {
|
function safe_append_prompt_command() {
|
||||||
local prompt_re
|
local prompt_reif [ "${__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}")
|
||||||
|
|
@ -628,7 +635,7 @@ function _save-and-reload-history() {
|
||||||
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_colorscheme {
|
function prompt_colorscheme() {
|
||||||
[[ -z "${BASH_IT_COLORSCHEME}" ]] && return
|
[[ -z "${BASH_IT_COLORSCHEME}" ]] && return
|
||||||
|
|
||||||
local -a colorscheme_locations=(
|
local -a colorscheme_locations=(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
. "$BASH_IT/themes/powerline/powerline.base.bash"
|
. "$BASH_IT/themes/powerline/powerline.base.bash"
|
||||||
|
. "$BASH_IT/themes/powerline/powerline.helpers.bash"
|
||||||
|
|
||||||
|
|
||||||
function __powerline_last_status_prompt {
|
function __powerline_last_status_prompt {
|
||||||
[[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}"
|
[[ "$1" -ne 0 ]] && echo "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}"
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,12 @@ RBENV_THEME_PROMPT_SUFFIX=""
|
||||||
RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161}
|
RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161}
|
||||||
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "}
|
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "}
|
||||||
|
|
||||||
|
GO_THEME_PROMPT_COLOR=${POWERLINE_GO_COLOR:=33}
|
||||||
|
GO_CHAR=${POWERLINE_GO_CHAR:="(go) "}
|
||||||
|
|
||||||
|
CWD_SHORTEN_TO=${POWERLINE_CWD_SHORTEN_TO:=30}
|
||||||
|
CWD_SHORTEN_SCREEN_PERCENT=${CWD_SHORTEN_SCREEN_PERCENT:=25}
|
||||||
|
|
||||||
TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161}
|
TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161}
|
||||||
TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
|
TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
# Define this here so it can be used by all of the Powerline themes
|
# Define this here so it can be used by all of the Powerline themes
|
||||||
THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true}
|
THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true}
|
||||||
|
|
||||||
|
. "$BASH_IT/themes/powerline/powerline.helpers.bash"
|
||||||
|
|
||||||
function set_color() {
|
function set_color() {
|
||||||
set +u
|
set +u
|
||||||
if [[ "${1}" != "-" ]]; then
|
if [[ "${1}" != "-" ]]; then
|
||||||
|
|
@ -75,6 +77,32 @@ function __powerline_ruby_prompt() {
|
||||||
[[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}"
|
[[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __find_nearest_go_mod() {
|
||||||
|
local path="${PWD}"
|
||||||
|
while true; do
|
||||||
|
[[ -z "${path}" || ${path} == "/" ]] && break
|
||||||
|
if [[ -f "${path}/go.mod" ]]; then
|
||||||
|
printf "${path}/go.mod"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
path=$(dirname ${path})
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function __powerline_go_prompt {
|
||||||
|
local go_version=""
|
||||||
|
|
||||||
|
if _command_exists go ; then
|
||||||
|
local go_mod=$(__find_nearest_go_mod)
|
||||||
|
[[ -n "${go_mod}" && -f "${go_mod}" ]] || return
|
||||||
|
local -a go_version_output
|
||||||
|
mapfile -t go_version_output < <(egrep '^go ' ${go_mod} | tr ' ' '\n')
|
||||||
|
go_version="${go_version_output[1]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "${go_version}" ]] && echo "${GO_CHAR}${go_version}|${GO_THEME_PROMPT_COLOR}"
|
||||||
|
}
|
||||||
|
|
||||||
function __powerline_k8s_context_prompt() {
|
function __powerline_k8s_context_prompt() {
|
||||||
local kubernetes_context=""
|
local kubernetes_context=""
|
||||||
|
|
||||||
|
|
@ -129,8 +157,21 @@ function __powerline_scm_prompt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_cwd_prompt() {
|
function __powerline_cwd_prompt() {
|
||||||
local cwd=$(pwd | sed "s|^${HOME}|~|")
|
local cwd
|
||||||
|
local max_width
|
||||||
|
local screen_width
|
||||||
|
if [[ -n "${CWD_SHORTEN_SCREEN_PERCENT}" ]]; then
|
||||||
|
screen_width=$(.powerline.screen-width)
|
||||||
|
max_width=$(( screen_width * CWD_SHORTEN_SCREEN_PERCENT / 100 ))
|
||||||
|
elif [[ -n "${CWD_SHORTEN_TO}" ]]; then
|
||||||
|
max_width=${CWD_SHORTEN_TO}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n ${max_width} ]]; then
|
||||||
|
cwd=$(cwd.shorten "${max_width}" "${PWD}")
|
||||||
|
else
|
||||||
|
cwd=$(pwd | sed "s|^${HOME}|~|")
|
||||||
|
fi
|
||||||
echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
|
echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,265 @@
|
||||||
|
# A bunch of Powerline Prompt Helper functions that
|
||||||
|
# change which compnents are shown, and to what level of detail to
|
||||||
|
# render the Git/SCM info.
|
||||||
|
|
||||||
|
# Minimizing the list of components and showing less Git info can significantly
|
||||||
|
# speed up your prompt rendering.
|
||||||
|
#
|
||||||
|
# For instance, on the most recent MacBook Pro 16 (2020) with 3GHZ CPU it takes 1 second
|
||||||
|
# to render the `powerline.prompt.git.max()` and powerline.prompt.all
|
||||||
|
|
||||||
|
# @description
|
||||||
|
# This function returns a shortened
|
||||||
|
# @see: https://stackoverflow.com/questions/1616678/bash-pwd-shortening
|
||||||
|
export POWERLINE_SHORT_CWD_WIDTH=30
|
||||||
|
|
||||||
|
function cwd.shorten() {
|
||||||
|
local begin="" # The unshortened 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 end="${2:-$(pwd)}/" # The unmodified rest of the path.
|
||||||
|
|
||||||
|
if [[ "$end" =~ "${HOME}" ]]; then
|
||||||
|
INHOME=1
|
||||||
|
end="${end#$HOME}" #strip /home/username from start of string
|
||||||
|
begin="$HOME" #start expansion from the right spot
|
||||||
|
else
|
||||||
|
INHOME=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local end="${end#/}" # Strip the first /
|
||||||
|
local shortenedpath="$end" # The whole path, to check the length.
|
||||||
|
local maxlength="${1:-${POWERLINE_SHORT_CWD_WIDTH}}"
|
||||||
|
|
||||||
|
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 */*/*/...
|
||||||
|
|
||||||
|
while [[ "$end" ]] && (( ${#shortenedpath} > maxlength ))
|
||||||
|
do
|
||||||
|
current="${end%%/*}" # everything before the first /
|
||||||
|
end="${end#*/}" # everything after the first /
|
||||||
|
|
||||||
|
shortcurstar="$current" # No star if we don't shorten it.
|
||||||
|
|
||||||
|
for ((i=${#current}-2; i>=0; i--)); do
|
||||||
|
subcurrent="${current:0:i}"
|
||||||
|
matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent.
|
||||||
|
(( ${#matching[*]} != 1 )) && break # Stop shortening if more than one file matches.
|
||||||
|
shortcurstar="${subcurrent}…"
|
||||||
|
done
|
||||||
|
|
||||||
|
#a dvance
|
||||||
|
begin="$begin/$current"
|
||||||
|
shortbegin="$shortbegin/$shortcurstar"
|
||||||
|
shortenedpath="$shortbegin/$end"
|
||||||
|
done
|
||||||
|
|
||||||
|
shortenedpath="${shortenedpath%/}" # strip trailing /
|
||||||
|
shortenedpath="${shortenedpath#/}" # strip leading /
|
||||||
|
|
||||||
|
if [ $INHOME -eq 1 ]; then
|
||||||
|
echo "~/$shortenedpath" #make sure it starts with ~/
|
||||||
|
else
|
||||||
|
echo "/$shortenedpath" # Make sure it starts with /
|
||||||
|
fi
|
||||||
|
|
||||||
|
shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function.
|
||||||
|
}
|
||||||
|
|
||||||
|
# Powerline Prompt Configuration
|
||||||
|
function powerline.prompt.git.max() {
|
||||||
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.git.min() {
|
||||||
|
export SCM_GIT_SHOW_MINIMAL_INFO=true
|
||||||
|
|
||||||
|
export SCM_GIT_SHOW_CURRENT_USER=false
|
||||||
|
export SCM_GIT_SHOW_DETAILS=false
|
||||||
|
export SCM_GIT_SHOW_COMMIT_COUNT=false
|
||||||
|
export SCM_GIT_SHOW_REMOTE_INFO=false
|
||||||
|
export SCM_GIT_SHOW_STASH_INFO=false
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.git.default() {
|
||||||
|
export SCM_GIT_SHOW_MINIMAL_INFO=false
|
||||||
|
|
||||||
|
export SCM_GIT_SHOW_CURRENT_USER=true
|
||||||
|
export SCM_GIT_SHOW_DETAILS=true
|
||||||
|
export SCM_GIT_SHOW_COMMIT_COUNT=false
|
||||||
|
export SCM_GIT_SHOW_REMOTE_INFO=false
|
||||||
|
export SCM_GIT_SHOW_STASH_INFO=true
|
||||||
|
}
|
||||||
|
|
||||||
|
.powerline.screen-width() {
|
||||||
|
local w
|
||||||
|
local os=$(uname -s)
|
||||||
|
if [[ $os == 'Darwin' ]]; then
|
||||||
|
w=$(stty -a 2>/dev/null | grep columns | awk '{print $6}');
|
||||||
|
else
|
||||||
|
w=$(stty -a 2>/dev/null | grep columns | awk '{print $7}' | sedx 's/;//g');
|
||||||
|
fi
|
||||||
|
printf -- "%d" ${w}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Filter/convert components passed as arguments to the
|
||||||
|
# correct powerline modules
|
||||||
|
# @example: .powerline.components ruby python k8 garbage
|
||||||
|
# @output: ruby python_venv k8s_context
|
||||||
|
function .powerline.components() {
|
||||||
|
local -a components
|
||||||
|
components=()
|
||||||
|
for c in "$@"; do
|
||||||
|
[[ ${c} == "python" ]] && c="python_venv"
|
||||||
|
[[ ${c} == "k8" ]] && c="k8s_context"
|
||||||
|
local func="__powerline_${c}_prompt"
|
||||||
|
type "$func" 2> /dev/null | head -1 | grep -q 'is a function' && components+=("${c}")
|
||||||
|
done
|
||||||
|
echo "${components[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function .powerline.supported.components() {
|
||||||
|
set | grep -E '^__powerline_.*_prompt' | sed 's/__powerline_//g; s/_prompt.*$//g; s/^/ • /g'
|
||||||
|
}
|
||||||
|
|
||||||
|
# usage: powerline.prompt.set [ lang [ lang ]... ]
|
||||||
|
# eg: powerline.prompt.set cwd ruby go node battery
|
||||||
|
function powerline.prompt.set() {
|
||||||
|
[[ -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
|
||||||
|
components=($(.powerline.components "$@"))
|
||||||
|
|
||||||
|
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() {
|
||||||
|
if [[ $BASH_IT_THEME =~ "multiline" ]]; then
|
||||||
|
powerline.prompt.set-left-to
|
||||||
|
powerline.prompt.set-right-to
|
||||||
|
else
|
||||||
|
powerline.prompt.set-to
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.set-to() {
|
||||||
|
if [[ -z $* ]]; then
|
||||||
|
echo "${POWERLINE_PROMPT}"
|
||||||
|
else
|
||||||
|
export POWERLINE_PROMPT="$(.powerline.components "$@")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.set-right-to() {
|
||||||
|
if [[ -z $* ]]; then
|
||||||
|
echo "${POWERLINE_RIGHT_PROMPT}"
|
||||||
|
else
|
||||||
|
export POWERLINE_RIGHT_PROMPT="$(.powerline.components "$@")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.set-left-to() {
|
||||||
|
if [[ -z $* ]]; then
|
||||||
|
echo "${POWERLINE_LEFT_PROMPT}"
|
||||||
|
else
|
||||||
|
export POWERLINE_LEFT_PROMPT="$(.powerline.components "$@")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# @example: powerline.prompt.add-component left ruby
|
||||||
|
function powerline.prompt.add-component() {
|
||||||
|
local side="$1"
|
||||||
|
local func
|
||||||
|
if [[ -n $1 ]] ; then
|
||||||
|
func="powerline.prompt.set-${side}-to"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
func="powerline.prompt.set-to"
|
||||||
|
fi
|
||||||
|
|
||||||
|
${func} $(${func}) "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.golang() {
|
||||||
|
powerline.prompt.add-component left go
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.node() {
|
||||||
|
powerline.prompt.add-component left node
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.ruby() {
|
||||||
|
powerline.prompt.add-component left ruby
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.python() {
|
||||||
|
powerline.prompt.add-component left python_venv
|
||||||
|
}
|
||||||
|
|
||||||
|
## Configure the level of Git Detail
|
||||||
|
function powerline.prompt.min() {
|
||||||
|
export POWERLINE_LEFT_PROMPT="cwd"
|
||||||
|
export POWERLINE_RIGHT_PROMPT="clock user_info hostname"
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.all() {
|
||||||
|
powerline.prompt
|
||||||
|
export POWERLINE_LEFT_PROMPT="scm clock cwd"
|
||||||
|
export POWERLINE_RIGHT_PROMPT="user_info hostname battery"
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.default() {
|
||||||
|
export POWERLINE_LEFT_PROMPT="scm node ruby go cwd "
|
||||||
|
export POWERLINE_RIGHT_PROMPT=" clock user_info hostname battery"
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.default() {
|
||||||
|
powerline-max
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline.prompt.alternative-symbols() {
|
||||||
|
export SCM_GIT_CHAR=" Ⓖ "
|
||||||
|
export USER_INFO_SSH_CHAR="🔐 "
|
||||||
|
export PYTHON_VENV_CHAR="ⓟ "
|
||||||
|
export CONDA_PYTHON_VENV_CHAR="ⓒⓟ "
|
||||||
|
export NODE_CHAR="ⓝ "
|
||||||
|
export RUBY_CHAR="ⓡ "
|
||||||
|
export GO_CHAR="ⓖ "
|
||||||
|
export TERRAFORM_CHAR="ⓣ "
|
||||||
|
export KUBERNETES_CONTEXT_THEME_CHAR="⎈ "
|
||||||
|
export AWS_PROFILE_CHAR="«aws» "
|
||||||
|
export BATTERY_AC_CHAR="⚡"
|
||||||
|
export IN_VIM_THEME_PROMPT_TEXT="ⓥ "
|
||||||
|
export SHLVL_THEME_PROMPT_CHAR="ⓢ "
|
||||||
|
export COMMAND_NUMBER_THEME_PROMPT_CHAR="↳"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -46,6 +46,12 @@ RBENV_THEME_PROMPT_SUFFIX=""
|
||||||
RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161}
|
RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161}
|
||||||
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "}
|
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "}
|
||||||
|
|
||||||
|
GO_THEME_PROMPT_COLOR=${POWERLINE_GO_COLOR:=33}
|
||||||
|
GO_CHAR=${POWERLINE_GO_CHAR:="(go) "}
|
||||||
|
|
||||||
|
CWD_SHORTEN_TO=${POWERLINE_CWD_SHORTEN_TO:=15}
|
||||||
|
CWD_SHORTEN_SCREEN_PERCENT=${CWD_SHORTEN_SCREEN_PERCENT:=25}
|
||||||
|
|
||||||
TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161}
|
TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161}
|
||||||
TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
|
TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue