More cleanup and shellcheck compliance
parent
13265500e9
commit
d20dfdd523
|
|
@ -137,6 +137,7 @@ themes/powerline
|
||||||
themes/powerline-multiline
|
themes/powerline-multiline
|
||||||
themes/powerline-naked
|
themes/powerline-naked
|
||||||
themes/powerline-plain
|
themes/powerline-plain
|
||||||
|
themes/powerturk
|
||||||
themes/pure
|
themes/pure
|
||||||
themes/purity
|
themes/purity
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
. "$BASH_IT/themes/powerline/powerline.base.bash"
|
. "$BASH_IT/themes/powerline/powerline.base.bash"
|
||||||
|
|
||||||
function __powerline_last_status_prompt {
|
function __powerline_last_status_prompt {
|
||||||
|
# shellcheck disable=SC2154
|
||||||
[[ "$1" -ne 0 ]] && echo "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR}" -) ${1} ${normal}"
|
[[ "$1" -ne 0 ]] && echo "$(set_color "${LAST_STATUS_THEME_PROMPT_COLOR}" -) ${1} ${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ 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
|
||||||
|
# shellcheck disable=SC2154
|
||||||
LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
|
LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
@ -40,7 +41,8 @@ function __powerline_prompt_command {
|
||||||
|
|
||||||
## left prompt ##
|
## left prompt ##
|
||||||
for segment in $POWERLINE_PROMPT; do
|
for segment in $POWERLINE_PROMPT; do
|
||||||
local info="$(__powerline_"${segment}"_prompt)"
|
local info
|
||||||
|
info="$(__powerline_"${segment}"_prompt)"
|
||||||
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
|
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
# shellcheck shell=bash
|
||||||
# Power-Turk theme for bash-it
|
# Power-Turk theme for bash-it
|
||||||
# Author (C) 2015 Ahmed Seref Guneysu
|
# Author (C) 2015 Ahmed Seref Guneysu
|
||||||
|
|
||||||
|
|
@ -29,156 +29,159 @@ CWD_THEME_PROMPT_COLOR=240
|
||||||
LAST_STATUS_THEME_PROMPT_COLOR=52
|
LAST_STATUS_THEME_PROMPT_COLOR=52
|
||||||
|
|
||||||
_collapsed_wd() {
|
_collapsed_wd() {
|
||||||
# echo -e "\u2771\u276d\u276f"
|
# echo -e "\u2771\u276d\u276f"
|
||||||
echo $(pwd | perl -pe "
|
pwd | perl -pe "
|
||||||
BEGIN {
|
BEGIN {
|
||||||
binmode STDIN, ':encoding(UTF-8)';
|
binmode STDIN, ':encoding(UTF-8)';
|
||||||
binmode STDOUT, ':encoding(UTF-8)';
|
binmode STDOUT, ':encoding(UTF-8)';
|
||||||
}; s|^$HOME|<HOME>|g; s|/([^/])[^/]*(?=/)|/\$1|g") | \
|
}; s|^$HOME|<HOME>|g; s|/([^/])[^/]*(?=/)|/\$1|g" \
|
||||||
sed -re "s/\// /g"
|
| sed -re "s/\// /g"
|
||||||
}
|
}
|
||||||
|
|
||||||
_swd(){
|
# shellcheck disable=SC2120
|
||||||
# Adapted from http://stackoverflow.com/a/2951707/1766716
|
_swd() {
|
||||||
begin="" # The unshortened beginning of the path.
|
# Adapted from http://stackoverflow.com/a/2951707/1766716
|
||||||
shortbegin="" # The shortened beginning of the path.
|
begin="" # The unshortened beginning of the path.
|
||||||
current="" # The section of the path we're currently working on.
|
shortbegin="" # The shortened beginning of the path.
|
||||||
end="${2:-${PWD}}/" # The unmodified rest 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
|
INHOME=1
|
||||||
end="${end#$HOME}" #strip /home/username from start of string
|
end="${end#$HOME}" #strip /home/username from start of string
|
||||||
begin="$HOME" #start expansion from the right spot
|
begin="$HOME" #start expansion from the right spot
|
||||||
else
|
else
|
||||||
INHOME=0
|
INHOME=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
end="${end#/}" # Strip the first /
|
end="${end#/}" # Strip the first /
|
||||||
shortenedpath="$end" # The whole path, to check the length.
|
shortenedpath="$end" # The whole path, to check the length.
|
||||||
maxlength="${1:-0}"
|
maxlength="${1:-0}"
|
||||||
|
|
||||||
shopt -q nullglob && NGV="-s" || NGV="-u" # Store the value for later.
|
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 */*/*/...
|
shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/...
|
||||||
|
|
||||||
while [[ "$end" ]] && (( ${#shortenedpath} > maxlength ))
|
while [[ "$end" ]] && ((${#shortenedpath} > maxlength)); do
|
||||||
do
|
current="${end%%/*}" # everything before the first /
|
||||||
current="${end%%/*}" # everything before the first /
|
end="${end#*/}" # everything after the first /
|
||||||
end="${end#*/}" # everything after the first /
|
|
||||||
|
|
||||||
shortcur="$current"
|
shortcur="$current"
|
||||||
shortcurstar="$current" # No star if we don't shorten it.
|
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}"
|
subcurrent="${current:0:i}"
|
||||||
matching=("$begin/$subcurrent"*) # Array of all files that start with $subcurrent.
|
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"
|
shortcur="$subcurrent"
|
||||||
shortcurstar="$subcurrent*"
|
shortcurstar="$subcurrent*"
|
||||||
done
|
done
|
||||||
|
|
||||||
#advance
|
#advance
|
||||||
begin="$begin/$current"
|
begin="$begin/$current"
|
||||||
shortbegin="$shortbegin/$shortcurstar"
|
shortbegin="$shortbegin/$shortcurstar"
|
||||||
shortenedpath="$shortbegin/$end"
|
shortenedpath="$shortbegin/$end"
|
||||||
done
|
done
|
||||||
|
|
||||||
shortenedpath="${shortenedpath%/}" # strip trailing /
|
shortenedpath="${shortenedpath%/}" # strip trailing /
|
||||||
shortenedpath="${shortenedpath#/}" # strip leading /
|
shortenedpath="${shortenedpath#/}" # strip leading /
|
||||||
|
|
||||||
# Replaces slashes with except first occurence.
|
# Replaces slashes with except first occurence.
|
||||||
if [ $INHOME -eq 1 ]; then
|
if [ $INHOME -eq 1 ]; then
|
||||||
echo "~/$shortenedpath" | sed "s/\///2g" # make sure it starts with ~/
|
# shellcheck disable=SC2088
|
||||||
else
|
echo "~/$shortenedpath" | sed "s/\///2g" # make sure it starts with ~/
|
||||||
echo "/$shortenedpath" | sed "s/\///2g" # Make sure it starts with /
|
else
|
||||||
fi
|
echo "/$shortenedpath" | sed "s/\///2g" # Make sure it starts with /
|
||||||
|
fi
|
||||||
|
|
||||||
shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function.
|
shopt "$NGV" nullglob # Reset nullglob in case this is being used as a function.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_rgb_color {
|
function set_rgb_color {
|
||||||
if [[ "${1}" != "-" ]]; then
|
if [[ "${1}" != "-" ]]; then
|
||||||
fg="38;5;${1}"
|
fg="38;5;${1}"
|
||||||
fi
|
fi
|
||||||
if [[ "${2}" != "-" ]]; then
|
if [[ "${2}" != "-" ]]; then
|
||||||
bg="48;5;${2}"
|
bg="48;5;${2}"
|
||||||
[[ -n "${fg}" ]] && bg=";${bg}"
|
[[ -n "${fg}" ]] && bg=";${bg}"
|
||||||
fi
|
fi
|
||||||
echo -e "\[\033[${fg}${bg}m\]"
|
echo -e "\[\033[${fg}${bg}m\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_shell_prompt {
|
function powerline_shell_prompt {
|
||||||
if [[ -n "${SSH_CLIENT}" ]]; then
|
if [[ -n "${SSH_CLIENT}" ]]; then
|
||||||
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}"
|
# shellcheck disable=SC2154
|
||||||
LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR}
|
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}"
|
||||||
else
|
LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR}
|
||||||
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) ${normal}"
|
else
|
||||||
LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
|
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) ${normal}"
|
||||||
fi
|
LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_virtualenv_prompt {
|
function powerline_virtualenv_prompt {
|
||||||
local environ=""
|
local environ=""
|
||||||
|
|
||||||
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
|
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
|
||||||
environ="conda: $CONDA_DEFAULT_ENV"
|
environ="conda: $CONDA_DEFAULT_ENV"
|
||||||
elif [[ -n "$VIRTUAL_ENV" ]]; then
|
elif [[ -n "$VIRTUAL_ENV" ]]; then
|
||||||
environ=$(basename "$VIRTUAL_ENV")
|
environ=$(basename "$VIRTUAL_ENV")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$environ" ]]; then
|
if [[ -n "$environ" ]]; then
|
||||||
VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}"
|
VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}"
|
||||||
LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR}
|
LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR}
|
||||||
else
|
else
|
||||||
VIRTUALENV_PROMPT=""
|
VIRTUALENV_PROMPT=""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_scm_prompt {
|
function powerline_scm_prompt {
|
||||||
scm_prompt_vars
|
scm_prompt_vars
|
||||||
|
|
||||||
if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
|
if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
|
||||||
if [[ "${SCM_DIRTY}" -eq 3 ]]; then
|
if [[ "${SCM_DIRTY}" -eq 3 ]]; then
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||||
elif [[ "${SCM_DIRTY}" -eq 2 ]]; then
|
elif [[ "${SCM_DIRTY}" -eq 2 ]]; then
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||||
elif [[ "${SCM_DIRTY}" -eq 1 ]]; then
|
elif [[ "${SCM_DIRTY}" -eq 1 ]]; then
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||||
else
|
else
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
||||||
fi
|
fi
|
||||||
if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then
|
if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then
|
||||||
SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
|
SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
|
||||||
fi
|
fi
|
||||||
SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}"
|
SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}"
|
||||||
LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR}
|
LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR}
|
||||||
else
|
else
|
||||||
SCM_PROMPT=""
|
SCM_PROMPT=""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_cwd_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}
|
LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR}
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_last_status_prompt {
|
function powerline_last_status_prompt {
|
||||||
if [[ "$1" -eq 0 ]]; then
|
if [[ "$1" -eq 0 ]]; then
|
||||||
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
||||||
else
|
else
|
||||||
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_prompt_command() {
|
function powerline_prompt_command() {
|
||||||
local LAST_STATUS="$?"
|
local LAST_STATUS="$?"
|
||||||
|
|
||||||
powerline_shell_prompt
|
powerline_shell_prompt
|
||||||
powerline_virtualenv_prompt
|
powerline_virtualenv_prompt
|
||||||
powerline_scm_prompt
|
powerline_scm_prompt
|
||||||
powerline_cwd_prompt
|
powerline_cwd_prompt
|
||||||
powerline_last_status_prompt LAST_STATUS
|
powerline_last_status_prompt LAST_STATUS
|
||||||
|
|
||||||
PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} "
|
PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} "
|
||||||
}
|
}
|
||||||
|
|
||||||
PROMPT_COMMAND=powerline_prompt_command
|
PROMPT_COMMAND=powerline_prompt_command
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue