pull/1954/merge
John D Pell 2022-04-03 09:27:29 -04:00 committed by GitHub
commit 7e2c075343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 93 deletions

View File

@ -1,6 +1,5 @@
# shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
# Theme custom glyphs
SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '}
@ -15,96 +14,99 @@ PYTHON_VENV_CHAR=${BARBUK_PYTHON_VENV_CHAR:=' '}
COMMAND_DURATION_ICON=${BARBUK_COMMAND_DURATION_ICON:-"$bold_blue"}
# Command duration
COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-1}
COMMAND_DURATION_COLOR="$normal"
: "${COMMAND_DURATION_MIN_SECONDS:=1}"
: "${COMMAND_DURATION_COLOR:="${normal?}"}"
# Ssh user and hostname display
SSH_INFO=${BARBUK_SSH_INFO:=true}
HOST_INFO=${BARBUK_HOST_INFO:=long}
# Bash-it default glyphs customization
# Bash-it default glyphs overrides
SCM_NONE_CHAR=
SCM_THEME_PROMPT_DIRTY=" ${bold_red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green?}"
SCM_THEME_PROMPT_PREFIX="|"
SCM_THEME_PROMPT_SUFFIX="${green}| "
SCM_GIT_BEHIND_CHAR="${bold_red}${normal}"
SCM_GIT_AHEAD_CHAR="${bold_green}${normal}"
SCM_THEME_PROMPT_SUFFIX="${green?}| "
SCM_GIT_BEHIND_CHAR="${bold_red?}${normal?}"
SCM_GIT_AHEAD_CHAR="${bold_green?}${normal?}"
SCM_GIT_UNTRACKED_CHAR="⌀"
SCM_GIT_UNSTAGED_CHAR="${bold_yellow}${normal}"
SCM_GIT_STAGED_CHAR="${bold_green}+${normal}"
GIT_THEME_PROMPT_DIRTY=" ${bold_red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX="${cyan}"
GIT_THEME_PROMPT_SUFFIX="${cyan}"
SCM_THEME_BRANCH_TRACK_PREFIX="${normal}${cyan}"
SCM_GIT_UNSTAGED_CHAR="${bold_yellow?}${normal?}"
SCM_GIT_STAGED_CHAR="${bold_green?}+${normal?}"
GIT_THEME_PROMPT_DIRTY=" ${bold_red?}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green?}"
GIT_THEME_PROMPT_PREFIX="${cyan?}"
GIT_THEME_PROMPT_SUFFIX="${cyan?}"
SCM_THEME_BRANCH_TRACK_PREFIX="${normal?}${cyan?}"
SCM_THEME_CURRENT_USER_PREFFIX='  '
SCM_GIT_SHOW_CURRENT_USER=false
SCM_GIT_SHOW_CURRENT_USER='false'
function _git-uptream-remote-logo {
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
function _git-uptream-remote-logo() {
[[ -z "$(_git-upstream)" ]] && SCM_GIT_CHAR="${SCM_GIT_CHAR_DEFAULT:-}"
local remote remote_domain
remote=$(_git-upstream-remote)
remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}')
remote="$(_git-upstream-remote)"
remote_domain="$(git config --get remote."${remote}".url | awk -F'[@:.]' '{print $2}')"
# remove // suffix for https:// url
remote_domain=${remote_domain//\//}
remote_domain="${remote_domain//\//}"
case $remote_domain in
github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;;
gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;;
bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;;
*) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;;
case "${remote_domain}" in
github) SCM_GIT_CHAR="${SCM_GIT_CHAR_GITHUB:-}" ;;
gitlab) SCM_GIT_CHAR="${SCM_GIT_CHAR_GITLAB:-}" ;;
bitbucket) SCM_GIT_CHAR="${SCM_GIT_CHAR_BITBUCKET:-}" ;;
*) SCM_GIT_CHAR="${SCM_GIT_CHAR_DEFAULT:-}" ;;
esac
}
function git_prompt_info {
function git_prompt_info() {
git_prompt_vars
echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
echo -e " on ${SCM_GIT_CHAR_ICON_BRANCH:-} ${SCM_PREFIX:-}${SCM_BRANCH:-}${SCM_STATE:-}${SCM_GIT_AHEAD:-}${SCM_GIT_BEHIND:-}${SCM_GIT_STASH:-}${SCM_SUFFIX:-}"
}
function _exit-code {
if [[ "$1" -ne 0 ]]; then
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
function _exit-code() {
if [[ "${1:-}" -ne 0 ]]; then
exit_code=" ${purple?}${EXIT_CODE_ICON:-}${yellow?}${exit_code:-}${bold_orange?}"
else
exit_code="${bold_green}"
exit_code="${bold_green?}"
fi
}
function _prompt {
function _prompt() {
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
local scm_char scm_prompt_info
command_duration=$(_command_duration)
command_duration="$(_command_duration)"
_exit-code exit_code
_git-uptream-remote-logo
history -a
_save-and-reload-history 1
# Detect root shell
if [ "$(whoami)" = root ]; then
dir_color=$red
if [[ "${USER:-${LOGNAME:?}}" == root ]]; then
dir_color="${red?}"
fi
# Detect ssh
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
if [ "$HOST_INFO" = long ]; then
if [[ -n "${SSH_CONNECTION:-}" && "${SSH_INFO:-}" == true ]]; then
if [[ "${HOST_INFO:-}" == long ]]; then
host="\H"
else
host="\h"
fi
ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in"
ssh_info="${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in"
fi
# 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
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}"
scm_char="$(scm_char)"
scm_prompt_info="$(scm_prompt_info)"
PS1="\\n${ssh_info} ${purple}${scm_char}${python_venv}${dir_color}\\w${normal}${scm_prompt_info}${command_duration}${exit_code}"
[[ ${#PS1} -gt $((COLUMNS * 2)) ]] && wrap_char="\\n"
PS1="${PS1}${wrap_char}${normal} "
}

View File

@ -1,12 +1,11 @@
# shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
# Detect whether a reboot is required
function show_reboot_required() {
if [ -n "$_bf_prompt_reboot_info" ]; then
if [ -f /var/run/reboot-required ]; then
printf "Reboot required!"
if [[ -n "${_bf_prompt_reboot_info:-}" ]]; then
if [[ -f /var/run/reboot-required ]]; then
printf '%s' "Reboot required!"
fi
fi
}
@ -14,21 +13,21 @@ function show_reboot_required() {
# Set different host color for local and remote sessions
function set_host_color() {
# Detect if connection is through SSH
if [[ -n $SSH_CLIENT ]]; then
printf '%s' "${lime_yellow}"
if [[ -n "${SSH_CLIENT:-}" ]]; then
printf '%s' "${lime_yellow?}"
else
printf '%s' "${light_orange}"
printf '%s' "${light_orange?}"
fi
}
# Set different username color for users and root
function set_user_color() {
case $(id -u) in
case ${EUID:-$UID} in
0)
printf '%s' "${red}"
printf '%s' "${red?}"
;;
*)
printf '%s' "${cyan}"
printf '%s' "${cyan?}"
;;
esac
}
@ -47,40 +46,48 @@ function set_custom_colors() {
powder_blue="\[$(tput setaf 153)\]"
}
__ps_time() {
printf '%s' "$(clock_prompt)${normal}\n"
function __ps_time() {
local clock_prompt
clock_prompt="$(clock_prompt)"
printf '%s\n' "${clock_prompt}${normal?}"
}
function prompt_command() {
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
local show_reboot_required set_user_color set_host_color scm_prompt ps_time
show_reboot_required="$(show_reboot_required)"
ps_reboot="${bright_yellow?}${show_reboot_required}${normal?}\n"
ps_username="$(set_user_color)\u${normal}"
ps_uh_separator="${dark_grey}@${normal}"
ps_hostname="$(set_host_color)\h${normal}"
set_user_color="$(set_user_color)"
ps_username="${set_user_color}\u${normal}"
ps_uh_separator="${dark_grey?}@${normal}"
set_host_color="$(set_host_color)"
ps_hostname="${set_host_color}\h${normal}"
ps_path="${yellow}\w${normal}"
ps_scm_prompt="${light_grey}$(scm_prompt)"
ps_path="${yellow?}\w${normal}"
scm_prompt="$(scm_prompt)"
ps_scm_prompt="${light_grey?}${scm_prompt}"
ps_user_mark="${normal} ${normal}"
ps_user_input="${normal}"
# Set prompt
PS1="$ps_reboot$(__ps_time)$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
ps_time="$(__ps_time)"
PS1="$ps_reboot${ps_time}$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
}
# Initialize custom colors
set_custom_colors
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$dark_grey"}
: "${THEME_CLOCK_COLOR:="$dark_grey"}"
# scm theming
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${light_grey}"
SCM_THEME_PROMPT_CLEAN=" ${green}${light_grey}"
SCM_GIT_CHAR="${green}±${light_grey}"
SCM_SVN_CHAR="${bold_cyan}${light_grey}"
SCM_HG_CHAR="${bold_red}${light_grey}"
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}${light_grey?}"
SCM_THEME_PROMPT_CLEAN=" ${green?}${light_grey?}"
SCM_GIT_CHAR="${green?}±${light_grey?}"
SCM_SVN_CHAR="${bold_cyan?}${light_grey?}"
SCM_HG_CHAR="${bold_red?}${light_grey?}"
safe_append_prompt_command prompt_command

View File

@ -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\]"
;;
@ -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="└─▪ "