Skip to content

Commit 0743ebe

Browse files
authored
Merge pull request #1954 from gaelicWizard/SC2154
2 parents 715d530 + 367780b commit 0743ebe

File tree

3 files changed

+97
-67
lines changed

3 files changed

+97
-67
lines changed

themes/barbuk/barbuk.theme.bash

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ SCALEWAY_PROFILE_CHAR=${BARBUK_SCALEWAY_PROFILE_CHAR:=" scw "}
2727
GCLOUD_CHAR=${BARBUK_GCLOUD_CHAR:=" google "}
2828

2929
# Command duration
30-
COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-1}
30+
: "${COMMAND_DURATION_MIN_SECONDS:=1}"
31+
: "${COMMAND_DURATION_COLOR:="${normal?}"}"
3132

3233
# Ssh user and hostname display
3334
SSH_INFO=${BARBUK_SSH_INFO:=true}
3435
HOST_INFO=${BARBUK_HOST_INFO:=long}
3536

36-
# Bash-it default glyphs customization
37+
# Bash-it default glyphs overrides
3738
SCM_NONE_CHAR=
3839
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}"
3940
SCM_THEME_PROMPT_CLEAN=" ${bold_green?}"
@@ -49,6 +50,8 @@ GIT_THEME_PROMPT_CLEAN=" ${bold_green?}✓"
4950
GIT_THEME_PROMPT_PREFIX="${cyan?}"
5051
GIT_THEME_PROMPT_SUFFIX="${cyan?}"
5152
SCM_THEME_BRANCH_TRACK_PREFIX="${normal?}${cyan?}"
53+
SCM_THEME_CURRENT_USER_PREFFIX=''
54+
SCM_GIT_SHOW_CURRENT_USER='false'
5255
NVM_THEME_PROMPT_PREFIX=''
5356
NVM_THEME_PROMPT_SUFFIX=''
5457
RVM_THEME_PROMPT_PREFIX=''
@@ -58,29 +61,44 @@ RBENV_THEME_PROMPT_SUFFIX=''
5861
RBFU_THEME_PROMPT_PREFIX=''
5962
RBFU_THEME_PROMPT_SUFFIX=''
6063

61-
function __git-uptream-remote-logo_prompt() {
62-
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
64+
function _git-uptream-remote-logo() {
65+
[[ -z "$(_git-upstream)" ]] && SCM_GIT_CHAR="${SCM_GIT_CHAR_DEFAULT:-}"
6366

6467
local remote remote_domain
65-
remote=$(_git-upstream-remote)
66-
remote_domain=$(git config --get remote."$remote".url | awk -F'[@:.]' '{print $2}')
68+
remote="$(_git-upstream-remote)"
69+
remote_domain="$(git config --get remote."${remote}".url | awk -F'[@:.]' '{print $2}')"
6770

6871
# remove // suffix for https:// url
69-
remote_domain=${remote_domain//\//}
72+
remote_domain="${remote_domain//\//}"
7073

71-
case $remote_domain in
72-
github) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITHUB" ;;
73-
gitlab) SCM_GIT_CHAR="$SCM_GIT_CHAR_GITLAB" ;;
74-
bitbucket) SCM_GIT_CHAR="$SCM_GIT_CHAR_BITBUCKET" ;;
75-
*) SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" ;;
74+
case "${remote_domain}" in
75+
github) SCM_GIT_CHAR="${SCM_GIT_CHAR_GITHUB:-}" ;;
76+
gitlab) SCM_GIT_CHAR="${SCM_GIT_CHAR_GITLAB:-}" ;;
77+
bitbucket) SCM_GIT_CHAR="${SCM_GIT_CHAR_BITBUCKET:-}" ;;
78+
*) SCM_GIT_CHAR="${SCM_GIT_CHAR_DEFAULT:-}" ;;
7679
esac
7780

7881
echo "${purple?}$(scm_char)"
7982
}
8083

8184
function git_prompt_info() {
8285
git_prompt_vars
83-
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 "
86+
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:-}"
87+
}
88+
89+
function _exit-code() {
90+
if [[ "${1:-}" -ne 0 ]]; then
91+
exit_code=" ${purple?}${EXIT_CODE_ICON:-}${yellow?}${exit_code:-}${bold_orange?}"
92+
else
93+
exit_code="${bold_green?}"
94+
fi
95+
}
96+
97+
function _prompt() {
98+
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
99+
local scm_char scm_prompt_info
100+
101+
command_duration="$(_command_duration)"
84102
}
85103

86104
function __exit_prompt() {
@@ -141,23 +159,27 @@ function __ruby_prompt() {
141159

142160
function __ssh_prompt() {
143161
# Detect ssh
144-
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
145-
if [ "$HOST_INFO" = long ]; then
162+
if [[ -n "${SSH_CONNECTION:-}" && "${SSH_INFO:-}" == true ]]; then
163+
if [[ "${HOST_INFO:-}" == long ]]; then
146164
host="\H"
147165
else
148166
host="\h"
149167
fi
150-
echo "${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in "
168+
ssh_info="${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in"
151169
fi
152170
}
153171

154172
function __python_venv_prompt() {
155173
# Detect python venv
156-
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
157-
echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}${CONDA_DEFAULT_ENV} "
158-
elif [[ -n "${VIRTUAL_ENV}" ]]; then
159-
echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}$(basename "${VIRTUAL_ENV}") "
174+
if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
175+
python_venv="${PYTHON_VENV_CHAR:-}${CONDA_DEFAULT_ENV:-} "
176+
elif [[ -n "${VIRTUAL_ENV:-}" ]]; then
177+
python_venv="$PYTHON_VENV_CHAR${VIRTUAL_ENV##*/} "
160178
fi
179+
180+
scm_char="$(scm_char)"
181+
scm_prompt_info="$(scm_prompt_info)"
182+
PS1="\\n${ssh_info} ${purple}${scm_char}${python_venv}${dir_color}\\w${normal}${scm_prompt_info}${command_duration}${exit_code}"
161183
}
162184

163185
function __path_prompt() {
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
# shellcheck shell=bash
22
# shellcheck disable=SC2034 # Expected behavior for themes.
3-
# shellcheck disable=SC2154 #TODO: fix these all.
43

54
# Detect whether a reboot is required
65
function show_reboot_required() {
7-
if [ -n "$_bf_prompt_reboot_info" ]; then
8-
if [ -f /var/run/reboot-required ]; then
9-
printf "Reboot required!"
6+
if [[ -n "${_bf_prompt_reboot_info:-}" ]]; then
7+
if [[ -f /var/run/reboot-required ]]; then
8+
printf '%s' "Reboot required!"
109
fi
1110
fi
1211
}
1312

1413
# Set different host color for local and remote sessions
1514
function set_host_color() {
1615
# Detect if connection is through SSH
17-
if [[ -n $SSH_CLIENT ]]; then
18-
printf '%s' "${lime_yellow}"
16+
if [[ -n "${SSH_CLIENT:-}" ]]; then
17+
printf '%s' "${lime_yellow?}"
1918
else
20-
printf '%s' "${light_orange}"
19+
printf '%s' "${light_orange?}"
2120
fi
2221
}
2322

2423
# Set different username color for users and root
2524
function set_user_color() {
26-
case $(id -u) in
25+
case ${EUID:-$UID} in
2726
0)
28-
printf '%s' "${red}"
27+
printf '%s' "${red?}"
2928
;;
3029
*)
31-
printf '%s' "${cyan}"
30+
printf '%s' "${cyan?}"
3231
;;
3332
esac
3433
}
@@ -47,40 +46,48 @@ function set_custom_colors() {
4746
powder_blue="\[$(tput setaf 153)\]"
4847
}
4948

50-
__ps_time() {
51-
printf '%s' "$(clock_prompt)${normal}\n"
49+
function __ps_time() {
50+
local clock_prompt
51+
clock_prompt="$(clock_prompt)"
52+
printf '%s\n' "${clock_prompt}${normal?}"
5253
}
5354

5455
function prompt_command() {
55-
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
56+
local show_reboot_required set_user_color set_host_color scm_prompt ps_time
57+
show_reboot_required="$(show_reboot_required)"
58+
ps_reboot="${bright_yellow?}${show_reboot_required}${normal?}\n"
5659

57-
ps_username="$(set_user_color)\u${normal}"
58-
ps_uh_separator="${dark_grey}@${normal}"
59-
ps_hostname="$(set_host_color)\h${normal}"
60+
set_user_color="$(set_user_color)"
61+
ps_username="${set_user_color}\u${normal}"
62+
ps_uh_separator="${dark_grey?}@${normal}"
63+
set_host_color="$(set_host_color)"
64+
ps_hostname="${set_host_color}\h${normal}"
6065

61-
ps_path="${yellow}\w${normal}"
62-
ps_scm_prompt="${light_grey}$(scm_prompt)"
66+
ps_path="${yellow?}\w${normal}"
67+
scm_prompt="$(scm_prompt)"
68+
ps_scm_prompt="${light_grey?}${scm_prompt}"
6369

6470
ps_user_mark="${normal} ${normal}"
6571
ps_user_input="${normal}"
6672

6773
# Set prompt
68-
PS1="$ps_reboot$(__ps_time)$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
74+
ps_time="$(__ps_time)"
75+
PS1="$ps_reboot${ps_time}$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
6976
}
7077

7178
# Initialize custom colors
7279
set_custom_colors
7380

74-
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$dark_grey"}
81+
: "${THEME_CLOCK_COLOR:="$dark_grey"}"
7582

7683
# scm theming
7784
SCM_THEME_PROMPT_PREFIX=""
7885
SCM_THEME_PROMPT_SUFFIX=""
7986

80-
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${light_grey}"
81-
SCM_THEME_PROMPT_CLEAN=" ${green}${light_grey}"
82-
SCM_GIT_CHAR="${green}±${light_grey}"
83-
SCM_SVN_CHAR="${bold_cyan}${light_grey}"
84-
SCM_HG_CHAR="${bold_red}${light_grey}"
87+
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}${light_grey?}"
88+
SCM_THEME_PROMPT_CLEAN=" ${green?}${light_grey?}"
89+
SCM_GIT_CHAR="${green?}±${light_grey?}"
90+
SCM_SVN_CHAR="${bold_cyan?}${light_grey?}"
91+
SCM_HG_CHAR="${bold_red?}${light_grey?}"
8592

8693
safe_append_prompt_command prompt_command

themes/modern/modern.theme.bash

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# shellcheck shell=bash
22
# shellcheck disable=SC2034 # Expected behavior for themes.
3-
# shellcheck disable=SC2154 #TODO: fix these all.
43

54
SCM_THEME_PROMPT_PREFIX=""
65
SCM_THEME_PROMPT_SUFFIX=""
76

8-
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
9-
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
10-
SCM_GIT_CHAR="${bold_green}±${normal}"
11-
SCM_SVN_CHAR="${bold_cyan}${normal}"
12-
SCM_HG_CHAR="${bold_red}${normal}"
7+
SCM_THEME_PROMPT_DIRTY=" ${bold_red?}${normal?}"
8+
SCM_THEME_PROMPT_CLEAN=" ${bold_green?}${normal?}"
9+
SCM_GIT_CHAR="${bold_green?}±${normal?}"
10+
SCM_SVN_CHAR="${bold_cyan?}${normal?}"
11+
SCM_HG_CHAR="${bold_red?}${normal?}"
1312

14-
case $TERM in
13+
case "${TERM:-dumb}" in
1514
xterm*)
1615
TITLEBAR="\[\033]0;\w\007\]"
1716
;;
@@ -22,32 +21,34 @@ esac
2221

2322
PS3=">> "
2423

25-
is_vim_shell() {
26-
if [ -n "$VIMRUNTIME" ]; then
27-
echo "[${cyan}vim shell${normal}]"
24+
function is_vim_shell() {
25+
if [[ -n "${VIMRUNTIME:-}" ]]; then
26+
echo "[${cyan?}vim shell${normal?}]"
2827
fi
2928
}
3029

31-
detect_venv() {
32-
python_venv=""
30+
function detect_venv() {
31+
local python_venv=""
3332
# Detect python venv
34-
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
35-
python_venv="($PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV}) "
36-
elif [[ -n "${VIRTUAL_ENV}" ]]; then
37-
python_venv="($PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}")) "
33+
if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
34+
python_venv="(${PYTHON_VENV_CHAR}${CONDA_DEFAULT_ENV}) "
35+
elif [[ -n "${VIRTUAL_ENV:-}" ]]; then
36+
python_venv="(${PYTHON_VENV_CHAR}${VIRTUAL_ENV##*/}) "
3837
fi
3938
}
4039

41-
prompt() {
42-
SCM_PROMPT_FORMAT='[%s][%s]'
43-
retval=$?
40+
function prompt() {
41+
local retval=$? scm_prompt is_vim_shell python_venv
42+
local SCM_PROMPT_FORMAT='[%s][%s]'
43+
scm_prompt="$(scm_prompt)"
44+
is_vim_shell="$(is_vim_shell)"
4445
if [[ retval -ne 0 ]]; then
45-
PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n${bold_red}└─▪${normal} "
46+
PS1="${TITLEBAR:-}${bold_red?}┌─${reset_color?}${scm_prompt}[${cyan?}\u${normal?}][${cyan?}\w${normal?}]${is_vim_shell}\n${bold_red?}└─▪${normal?} "
4647
else
47-
PS1="${TITLEBAR}┌─$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n└─▪ "
48+
PS1="${TITLEBAR:-}┌─${scm_prompt}[${cyan?}\u${normal?}][${cyan?}\w${normal?}]${is_vim_shell}\n└─▪ "
4849
fi
4950
detect_venv
50-
PS1+="${python_venv}${dir_color}"
51+
PS1+="${python_venv?}${dir_color?}"
5152
}
5253

5354
PS2="└─▪ "

0 commit comments

Comments
 (0)