More cleanup and shellcheck compliance

pull/1970/head
Ira Abramov 2021-10-11 13:57:25 +03:00
parent 13265500e9
commit d20dfdd523
4 changed files with 118 additions and 111 deletions

View File

@ -137,6 +137,7 @@ themes/powerline
themes/powerline-multiline
themes/powerline-naked
themes/powerline-plain
themes/powerturk
themes/pure
themes/purity

View File

@ -2,6 +2,7 @@
. "$BASH_IT/themes/powerline/powerline.base.bash"
function __powerline_last_status_prompt {
# shellcheck disable=SC2154
[[ "$1" -ne 0 ]] && echo "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR}" -) ${1} ${normal}"
}

View File

@ -19,6 +19,7 @@ function __powerline_left_segment {
# Since the previous segment wasn't the last segment, add padding, if needed
#
if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR}" -eq 0 ]]; then
# shellcheck disable=SC2154
LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
fi
fi
@ -40,7 +41,8 @@ function __powerline_prompt_command {
## left prompt ##
for segment in $POWERLINE_PROMPT; do
local info="$(__powerline_"${segment}"_prompt)"
local info
info="$(__powerline_"${segment}"_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
done

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# Power-Turk theme for bash-it
# Author (C) 2015 Ahmed Seref Guneysu
@ -30,22 +30,23 @@ LAST_STATUS_THEME_PROMPT_COLOR=52
_collapsed_wd() {
# echo -e "\u2771\u276d\u276f"
echo $(pwd | perl -pe "
pwd | perl -pe "
BEGIN {
binmode STDIN, ':encoding(UTF-8)';
binmode STDOUT, ':encoding(UTF-8)';
}; s|^$HOME|<HOME>|g; s|/([^/])[^/]*(?=/)|/\$1|g") | \
sed -re "s/\//  /g"
}; s|^$HOME|<HOME>|g; s|/([^/])[^/]*(?=/)|/\$1|g" \
| sed -re "s/\//  /g"
}
_swd(){
# Adapted from http://stackoverflow.com/a/2951707/1766716
# shellcheck disable=SC2120
_swd() {
# Adapted from http://stackoverflow.com/a/2951707/1766716
begin="" # The unshortened beginning of the path.
shortbegin="" # The shortened beginning of the path.
current="" # The section of the path we're currently working on.
end="${2:-${PWD}}/" # The unmodified rest of the path.
if [[ "$end" =~ "$HOME" ]]; then
if [[ "$end" =~ $HOME ]]; then
INHOME=1
end="${end#$HOME}" #strip /home/username from start of string
begin="$HOME" #start expansion from the right spot
@ -60,18 +61,17 @@ _swd(){
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
while [[ "$end" ]] && ((${#shortenedpath} > maxlength)); do
current="${end%%/*}" # everything before the first /
end="${end#*/}" # everything after the first /
shortcur="$current"
shortcurstar="$current" # No star if we don't shorten it.
for ((i=${#current}-2; i>=0; i--)); do
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.
((${#matching[*]} != 1)) && break # Stop shortening if more than one file matches.
shortcur="$subcurrent"
shortcurstar="$subcurrent*"
done
@ -87,6 +87,7 @@ _swd(){
# Replaces slashes with  except first occurence.
if [ $INHOME -eq 1 ]; then
# shellcheck disable=SC2088
echo "~/$shortenedpath" | sed "s/\///2g" # make sure it starts with ~/
else
echo "/$shortenedpath" | sed "s/\///2g" # Make sure it starts with /
@ -95,6 +96,7 @@ _swd(){
shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function.
}
function set_rgb_color {
if [[ "${1}" != "-" ]]; then
fg="38;5;${1}"
@ -108,6 +110,7 @@ function set_rgb_color {
function powerline_shell_prompt {
if [[ -n "${SSH_CLIENT}" ]]; then
# shellcheck disable=SC2154
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}"
LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR}
else
@ -157,7 +160,7 @@ function powerline_scm_prompt {
}
function powerline_cwd_prompt {
CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}$(set_rgb_color 0 ${CWD_THEME_PROMPT_COLOR}) $(_swd)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}$(set_rgb_color 0 ${CWD_THEME_PROMPT_COLOR}) $(_swd)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR}
}