Merge branch 'master' of https://github.com/bash-it/bash-it into ira/cleanup

* 'master' of https://github.com/bash-it/bash-it:
  Fix save-and-reload-history command not found
  lib/utilities: new function `_bash-it-egrep()`
  lib/utilities: quote SC2295
  lib/utilities: XDG_CACHE_HOME
  use `\w`
  Update powerline.base.bash
  Fix home dir substitution
  lib/utilities: `_bash-it-component-help()`
  lib/utilities: simplify `_bash-it-array-dedup()`
  theme/powerline: fix an oops in the last patch
pull/1970/head
Ira Abramov 2021-10-19 14:19:25 +03:00
commit 4da06b7220
2 changed files with 15 additions and 13 deletions

View File

@ -11,7 +11,7 @@ function _bash-it-get-component-name-from-path() {
# filename without path
filename="${1##*/}"
# filename without path or priority
filename="${filename##*${BASH_IT_LOAD_PRIORITY_SEPARATOR?}}"
filename="${filename##*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}"}"
# filename without path, priority or extension
echo "${filename%.*.bash}"
}
@ -40,7 +40,7 @@ function _bash-it-get-component-type-from-path() {
# $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple'
# contains apple
#
# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then
# $ if _bash-it-array-contains-element pear "${fruits[@]}"; then
# echo "contains pear!"
# fi
# contains pear!
@ -54,10 +54,9 @@ function _bash-it-array-contains-element() {
return 1
}
# Dedupe a simple array of words without spaces.
# Dedupe an array (without embedded newlines).
function _bash-it-array-dedup() {
local IFS=$'\n'
echo "$@" | tr ' ' '\n' | sort -u
printf '%s\n' "$@" | sort -u
}
# Outputs a full path of the grep found on the filesystem
@ -66,6 +65,12 @@ function _bash-it-grep() {
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
}
# Runs `grep` with extended regular expressions
function _bash-it-egrep() {
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
}
###########################################################################
# Component-specific functions (component is either an alias, a plugin, or a
# completion).
@ -76,17 +81,16 @@ function _bash-it-component-help() {
component="$(_bash-it-pluralize-component "${1}")"
file="$(_bash-it-component-cache-file "${component}")"
if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then
rm -f "${file}" 2> /dev/null
func="_bash-it-${component}"
"${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' > "${file}"
"${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' >| "${file}"
fi
cat "${file}"
}
function _bash-it-component-cache-file() {
local component file
component="$(_bash-it-pluralize-component "${1}")"
file="${BASH_IT?}/tmp/cache/${component}"
component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")"
file="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}"
[[ -f "${file}" ]] || mkdir -p "${file%/*}"
printf '%s' "${file}"
}

View File

@ -142,9 +142,7 @@ function __powerline_scm_prompt() {
}
function __powerline_cwd_prompt() {
local cwd="${PWD/$HOME/\~}"
echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
echo "\w|${CWD_THEME_PROMPT_COLOR}"
}
function __powerline_hostname_prompt() {
@ -275,7 +273,7 @@ function __powerline_prompt_command() {
SEGMENTS_AT_LEFT=0
LAST_SEGMENT_COLOR=""
save-and-reload-history "${HISTORY_AUTOSAVE:-0}"
_save-and-reload-history "${HISTORY_AUTOSAVE:-0}"
if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then
LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR}" "${PROMPT_DISTRO_LOGO_COLORBG}")${PROMPT_DISTRO_LOGO}$(set_color - -)"