Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Themes: Fix shellcheck (SC2154); Part C #1954

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 deletions themes/barbuk/barbuk.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ SCALEWAY_PROFILE_CHAR=${BARBUK_SCALEWAY_PROFILE_CHAR:=" scw "}
GCLOUD_CHAR=${BARBUK_GCLOUD_CHAR:=" google "}

# Command duration
COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-1}
: "${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?}✓"
Expand All @@ -49,6 +50,8 @@ 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'
NVM_THEME_PROMPT_PREFIX=''
NVM_THEME_PROMPT_SUFFIX=''
RVM_THEME_PROMPT_PREFIX=''
Expand All @@ -58,29 +61,44 @@ RBENV_THEME_PROMPT_SUFFIX=''
RBFU_THEME_PROMPT_PREFIX=''
RBFU_THEME_PROMPT_SUFFIX=''

function __git-uptream-remote-logo_prompt() {
[[ "$(_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

echo "${purple?}$(scm_char)"
}

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?}"
else
exit_code="${bold_green?}"
fi
}

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)"
}

function __exit_prompt() {
Expand Down Expand Up @@ -141,23 +159,27 @@ function __ruby_prompt() {

function __ssh_prompt() {
# 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
echo "${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in "
ssh_info="${bold_blue?}\u${bold_orange?}@${cyan?}$host ${bold_orange?}in"
fi
}

function __python_venv_prompt() {
# Detect python venv
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}${CONDA_DEFAULT_ENV} "
elif [[ -n "${VIRTUAL_ENV}" ]]; then
echo "${bold_purple?}$PYTHON_VENV_CHAR${normal?}$(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

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}"
}

function __path_prompt() {
Expand Down
57 changes: 32 additions & 25 deletions themes/binaryanomaly/binaryanomaly.theme.bash
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
# 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
}

# 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
}
Expand All @@ -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
45 changes: 23 additions & 22 deletions themes/modern/modern.theme.bash
Original file line number Diff line number Diff line change
@@ -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\]"
;;
Expand All @@ -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="└─▪ "
Expand Down
Loading