Merge pull request #1698 from davidpfarrell/themes/clean-powerline

Clean Powerline; Add Dir Support to Clean_Files
pull/1705/head
Noah Gorny 2020-11-05 19:22:29 +02:00 committed by GitHub
commit bcc3f4080b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 254 additions and 212 deletions

View File

@ -1,2 +1,29 @@
#######################################################################
# Allow-list of files to be lint-checked by CI
#
# Directory Suport
# Directory references are allowed within the file, ie:
#
# themes/powerline
#
# All files under the referenced directory will be checked
#
# Checking Files Locally
# You can manually invoke the check via:
#
# lint_clean_files.sh
#
# root directories
#
docs
# root files
#
.gitattributes
lint_clean_files.sh lint_clean_files.sh
themes/90210/90210.theme.bash
# themes
#
themes/90210
themes/powerline

View File

@ -1,7 +1,23 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Pull list of checkable files from clean_files.txt # Pull list of checkable files from clean_files.txt
# - Folder references are allowed
# - Empty lines are ignored
# - Comment lines (#) are ignored
# #
mapfile -t FILES < clean_files.txt # shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
mapfile -t FILES < <(
cat clean_files.txt \
| grep -v -E '^\s*$' \
| grep -v -E '^\s*#' \
| xargs -n1 -I{} find "{}" -type f
)
pre-commit run --files "${FILES[@]}" # We clear the BASH_IT variable to help the shellcheck checker
# identify source includes within our scripts that require a
# 'source' directive. For more information, see:
#
# "Shellcheck SC1090 - Can't follow non-constant source"
# https://www.shellcheck.net/wiki/SC1090
#
BASH_IT='' pre-commit run --files "${FILES[@]}"

View File

@ -1,7 +1,7 @@
# 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}
function set_color { function set_color() {
set +u set +u
if [[ "${1}" != "-" ]]; then if [[ "${1}" != "-" ]]; then
fg="38;5;${1}" fg="38;5;${1}"
@ -13,7 +13,7 @@ function set_color {
echo -e "\[\033[${fg}${bg}m\]" echo -e "\[\033[${fg}${bg}m\]"
} }
function __powerline_user_info_prompt { function __powerline_user_info_prompt() {
local user_info="" local user_info=""
local color=${USER_INFO_THEME_PROMPT_COLOR} local color=${USER_INFO_THEME_PROMPT_COLOR}
@ -39,7 +39,7 @@ function __powerline_user_info_prompt {
[[ -n "${user_info}" ]] && echo "${user_info}|${color}" [[ -n "${user_info}" ]] && echo "${user_info}|${color}"
} }
function __powerline_terraform_prompt { function __powerline_terraform_prompt() {
local terraform_workspace="" local terraform_workspace=""
if [ -d .terraform ]; then if [ -d .terraform ]; then
@ -48,14 +48,14 @@ function __powerline_terraform_prompt {
fi fi
} }
function __powerline_node_prompt { function __powerline_node_prompt() {
local node_version="" local node_version=""
node_version="$(node_version_prompt)" node_version="$(node_version_prompt)"
[[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}" [[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}"
} }
function __powerline_ruby_prompt { function __powerline_ruby_prompt() {
local ruby_version="" local ruby_version=""
if _command_exists rvm; then if _command_exists rvm; then
@ -67,7 +67,7 @@ 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 __powerline_k8s_context_prompt { function __powerline_k8s_context_prompt() {
local kubernetes_context="" local kubernetes_context=""
if _command_exists kubectl; then if _command_exists kubectl; then
@ -77,7 +77,7 @@ function __powerline_k8s_context_prompt {
[[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}" [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}"
} }
function __powerline_python_venv_prompt { function __powerline_python_venv_prompt() {
set +u set +u
local python_venv="" local python_venv=""
@ -91,7 +91,7 @@ function __powerline_python_venv_prompt {
[[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}" [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}"
} }
function __powerline_scm_prompt { function __powerline_scm_prompt() {
local color="" local color=""
local scm_prompt="" local scm_prompt=""
@ -120,25 +120,25 @@ function __powerline_scm_prompt {
fi fi
} }
function __powerline_cwd_prompt { function __powerline_cwd_prompt() {
local cwd=$(pwd | sed "s|^${HOME}|~|") local cwd=$(pwd | sed "s|^${HOME}|~|")
echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
} }
function __powerline_hostname_prompt { function __powerline_hostname_prompt() {
echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}" echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}"
} }
function __powerline_wd_prompt { function __powerline_wd_prompt() {
echo "\W|${CWD_THEME_PROMPT_COLOR}" echo "\W|${CWD_THEME_PROMPT_COLOR}"
} }
function __powerline_clock_prompt { function __powerline_clock_prompt() {
echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}" echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}"
} }
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)"
@ -157,27 +157,27 @@ function __powerline_battery_prompt {
fi fi
} }
function __powerline_in_vim_prompt { function __powerline_in_vim_prompt() {
if [ -n "$VIMRUNTIME" ]; then if [ -n "$VIMRUNTIME" ]; then
echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}"
fi fi
} }
function __powerline_aws_profile_prompt { function __powerline_aws_profile_prompt() {
if [[ -n "${AWS_PROFILE}" ]]; then if [[ -n "${AWS_PROFILE}" ]]; then
echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}" echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}"
fi fi
} }
function __powerline_shlvl_prompt { function __powerline_shlvl_prompt() {
if [[ "${SHLVL}" -gt 1 ]]; then if [[ "${SHLVL}" -gt 1 ]]; then
local prompt="${SHLVL_THEME_PROMPT_CHAR}" local prompt="${SHLVL_THEME_PROMPT_CHAR}"
local level=$(( ${SHLVL} - 1)) local level=$((SHLVL - 1))
echo "${prompt}${level}|${SHLVL_THEME_PROMPT_COLOR}" echo "${prompt}${level}|${SHLVL_THEME_PROMPT_COLOR}"
fi fi
} }
function __powerline_dirstack_prompt { function __powerline_dirstack_prompt() {
if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then
local depth=$((${#DIRSTACK[@]} - 1)) local depth=$((${#DIRSTACK[@]} - 1))
local prompt="${DIRSTACK_THEME_PROMPT_CHAR}" local prompt="${DIRSTACK_THEME_PROMPT_CHAR}"
@ -188,18 +188,17 @@ function __powerline_dirstack_prompt {
fi fi
} }
function __powerline_history_number_prompt { function __powerline_history_number_prompt() {
echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR}" echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR}"
} }
function __powerline_command_number_prompt { function __powerline_command_number_prompt() {
echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}" echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}"
} }
function __powerline_left_segment { function __powerline_left_segment() {
local OLD_IFS="${IFS}"; IFS="|" local params
local params=( $1 ) IFS="|" read -ra params <<< "${1}"
IFS="${OLD_IFS}"
local pad_before_segment=" " local pad_before_segment=" "
if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then if [[ "${SEGMENTS_AT_LEFT}" -eq 0 ]]; then
@ -213,29 +212,29 @@ function __powerline_left_segment {
# Since the previous segment wasn't the last segment, add padding, if needed # Since the previous segment wasn't the last segment, add padding, if needed
# #
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then
LEFT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
fi fi
if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then if [[ "${LAST_SEGMENT_COLOR}" -eq "${params[1]}" ]]; then
LEFT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR})${POWERLINE_LEFT_SEPARATOR_SOFT}${normal}" LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}")${POWERLINE_LEFT_SEPARATOR_SOFT}${normal}"
else else
LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} ${params[1]})${POWERLINE_LEFT_SEPARATOR}${normal}" LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR}" "${params[1]}")${POWERLINE_LEFT_SEPARATOR}${normal}"
fi fi
fi fi
LEFT_PROMPT+="$(set_color - ${params[1]})${pad_before_segment}${params[0]}${normal}" LEFT_PROMPT+="$(set_color - "${params[1]}")${pad_before_segment}${params[0]}${normal}"
LAST_SEGMENT_COLOR=${params[1]} LAST_SEGMENT_COLOR=${params[1]}
((SEGMENTS_AT_LEFT += 1)) ((SEGMENTS_AT_LEFT += 1))
} }
function __powerline_left_last_segment_padding { function __powerline_left_last_segment_padding() {
LEFT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR}) ${normal}" LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
} }
function __powerline_last_status_prompt { function __powerline_last_status_prompt() {
[[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}" [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}"
} }
function __powerline_prompt_command { function __powerline_prompt_command() {
local last_status="$?" ## always the first local last_status="$?" ## always the first
local separator_char="${POWERLINE_PROMPT_CHAR}" local separator_char="${POWERLINE_PROMPT_CHAR}"
@ -243,18 +242,17 @@ function __powerline_prompt_command {
SEGMENTS_AT_LEFT=0 SEGMENTS_AT_LEFT=0
LAST_SEGMENT_COLOR="" LAST_SEGMENT_COLOR=""
if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then
LEFT_PROMPT+="$(set_color ${PROMPT_DISTRO_LOGO_COLOR} ${PROMPT_DISTRO_LOGO_COLORBG})${PROMPT_DISTRO_LOGO}$(set_color - -)" LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR}" "${PROMPT_DISTRO_LOGO_COLORBG}")${PROMPT_DISTRO_LOGO}$(set_color - -)"
fi fi
## left prompt ## ## left prompt ##
for segment in $POWERLINE_PROMPT; do for segment in $POWERLINE_PROMPT; do
local info="$(__powerline_${segment}_prompt)" local info="$(__powerline_"${segment}"_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}" [[ -n "${info}" ]] && __powerline_left_segment "${info}"
done done
[[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status}) [[ "${last_status}" -ne 0 ]] && __powerline_left_segment "$(__powerline_last_status_prompt ${last_status})"
if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then if [[ -n "${LEFT_PROMPT}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT}" -eq 0 ]]; then
__powerline_left_last_segment_padding __powerline_left_last_segment_padding
@ -262,9 +260,9 @@ function __powerline_prompt_command {
# By default we try to match the prompt to the adjacent segment's background color, # By default we try to match the prompt to the adjacent segment's background color,
# but when part of the prompt exists within that segment, we instead match the foreground color. # but when part of the prompt exists within that segment, we instead match the foreground color.
local prompt_color="$(set_color ${LAST_SEGMENT_COLOR} -)" local prompt_color="$(set_color "${LAST_SEGMENT_COLOR}" -)"
if [[ -n "${LEFT_PROMPT}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" ]]; then if [[ -n "${LEFT_PROMPT}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" ]]; then
LEFT_PROMPT+="$(set_color - ${LAST_SEGMENT_COLOR})${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}"
prompt_color="${normal}" prompt_color="${normal}"
fi fi
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="${prompt_color}${separator_char}${normal}" [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="${prompt_color}${separator_char}${normal}"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck source=../../themes/powerline/powerline.base.bash
. "$BASH_IT/themes/powerline/powerline.base.bash" . "$BASH_IT/themes/powerline/powerline.base.bash"
PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""} PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""}