Merge branch 'master' of https://github.com/Bash-it/bash-it into ira/fix-dirs
* 'master' of https://github.com/Bash-it/bash-it: (22 commits) main: variable name cleanup lib/history: new functions `_bash-it-history-auto-*()` plugin/history*search: no need to load after `plugin/history` plugin/history-eternal: Use `readonly` instead of `export` plugin/history: don't use `export` lib/preview: add full completion lib/helpers: add `preview` to `bash-it` spaghetti lib/preview: refactor into a function completion/system: correctly load version when not linked main: adopt `_bash-it-log-prefix-by-path()` main: Glob for *.bash properly when path contains spaces completion/aliases: rename init function test/battery: require matching battery identifier test/battery: add multiple-battery edge case plugin/battery: split `upower` to two variables completion/alias: add stub file completion/alias: fix tests completion/alias: rename completion/alias: `shfmt` && `shellcheck` completion/alias: eliminate use of `eval` ...pull/2086/head
commit
16bf32be65
140
bash_it.sh
140
bash_it.sh
|
|
@ -1,145 +1,111 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# shellcheck source-path=SCRIPTDIR/lib source-path=SCRIPTDIR/scripts
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
#
|
||||||
# Initialize Bash It
|
# Initialize Bash It
|
||||||
BASH_IT_LOG_PREFIX="core: main: "
|
BASH_IT_LOG_PREFIX="core: main: "
|
||||||
|
: "${BASH_IT:=${BASH_SOURCE%/*}}"
|
||||||
# Only set $BASH_IT if it's not already set
|
: "${BASH_IT_CUSTOM:=${BASH_IT}/custom}"
|
||||||
if [ -z "${BASH_IT:-}" ]; then
|
: "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM}/themes"}"
|
||||||
# Setting $BASH to maintain backwards compatibility
|
: "${BASH_IT_BASHRC:=${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}}"
|
||||||
export BASH_IT=$BASH
|
|
||||||
BASH="$(bash -c 'echo $BASH')"
|
|
||||||
export BASH
|
|
||||||
BASH_IT_OLD_BASH_SETUP=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load composure first, so we support function metadata
|
# Load composure first, so we support function metadata
|
||||||
# shellcheck disable=SC1090
|
# shellcheck source-path=SCRIPTDIR/vendor/github.com/erichs/composure
|
||||||
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
|
source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
|
||||||
|
|
||||||
# Declare our end-of-main finishing hook
|
|
||||||
declare -a _bash_it_library_finalize_hook
|
|
||||||
|
|
||||||
# We need to load logging module early in order to be able to log
|
|
||||||
# shellcheck source-path=SCRIPTDIR/lib
|
|
||||||
source "${BASH_IT}/lib/log.bash"
|
|
||||||
|
|
||||||
# We can only log it now
|
|
||||||
[ -z "${BASH_IT_OLD_BASH_SETUP:-}" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
|
|
||||||
|
|
||||||
# For backwards compatibility, look in old BASH_THEME location
|
|
||||||
if [ -z "${BASH_IT_THEME:-}" ]; then
|
|
||||||
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
|
|
||||||
export BASH_IT_THEME="${BASH_THEME:-}"
|
|
||||||
unset BASH_THEME
|
|
||||||
fi
|
|
||||||
|
|
||||||
# support 'plumbing' metadata
|
# support 'plumbing' metadata
|
||||||
cite _about _param _example _group _author _version
|
cite _about _param _example _group _author _version
|
||||||
cite about-alias about-plugin about-completion
|
cite about-alias about-plugin about-completion
|
||||||
|
|
||||||
|
# Declare our end-of-main finishing hook, but don't use `declare`/`typeset`
|
||||||
|
_bash_it_library_finalize_hook=()
|
||||||
|
|
||||||
|
# We need to load logging module early in order to be able to log
|
||||||
|
source "${BASH_IT}/lib/log.bash"
|
||||||
|
|
||||||
# libraries, but skip appearance (themes) for now
|
# libraries, but skip appearance (themes) for now
|
||||||
_log_debug "Loading libraries(except appearance)..."
|
_log_debug "Loading libraries(except appearance)..."
|
||||||
LIB="${BASH_IT}/lib/*.bash"
|
|
||||||
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
|
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
|
||||||
for _bash_it_config_file in $LIB; do
|
for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do
|
||||||
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
|
[[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue
|
||||||
filename=${_bash_it_config_file##*/}
|
_bash-it-log-prefix-by-path "${_bash_it_main_file_lib}"
|
||||||
filename=${filename%.bash}
|
_log_debug "Loading library file..."
|
||||||
BASH_IT_LOG_PREFIX="lib: ${filename}: "
|
# shellcheck disable=SC1090
|
||||||
_log_debug "Loading library file..."
|
source "$_bash_it_main_file_lib"
|
||||||
# shellcheck disable=SC1090
|
BASH_IT_LOG_PREFIX="core: main: "
|
||||||
source "$_bash_it_config_file"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
BASH_IT_LOG_PREFIX="core: main: "
|
# Load the global "enabled" directory, then enabled aliases, completion, plugins
|
||||||
# Load the global "enabled" directory
|
# "_bash_it_main_file_type" param is empty so that files get sourced in glob order
|
||||||
# "family" param is empty so that files get sources in glob order
|
for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do
|
||||||
# shellcheck source=./scripts/reloader.bash
|
BASH_IT_LOG_PREFIX="core: reloader: "
|
||||||
source "${BASH_IT}/scripts/reloader.bash"
|
source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type"
|
||||||
|
BASH_IT_LOG_PREFIX="core: main: "
|
||||||
# Load enabled aliases, completion, plugins
|
|
||||||
for file_type in "aliases" "plugins" "completion"; do
|
|
||||||
# shellcheck source=./scripts/reloader.bash
|
|
||||||
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Load theme, if a theme was set
|
# Load theme, if a theme was set
|
||||||
if [[ -n "${BASH_IT_THEME}" ]]; then
|
# shellcheck source-path=SCRIPTDIR/themes
|
||||||
_log_debug "Loading \"${BASH_IT_THEME}\" theme..."
|
if [[ -n "${BASH_IT_THEME:-}" ]]; then
|
||||||
|
_log_debug "Loading theme '${BASH_IT_THEME}'."
|
||||||
BASH_IT_LOG_PREFIX="themes: githelpers: "
|
BASH_IT_LOG_PREFIX="themes: githelpers: "
|
||||||
# shellcheck source=./themes/githelpers.theme.bash
|
|
||||||
source "${BASH_IT}/themes/githelpers.theme.bash"
|
source "${BASH_IT}/themes/githelpers.theme.bash"
|
||||||
BASH_IT_LOG_PREFIX="themes: p4helpers: "
|
BASH_IT_LOG_PREFIX="themes: p4helpers: "
|
||||||
# shellcheck source=./themes/p4helpers.theme.bash
|
|
||||||
source "${BASH_IT}/themes/p4helpers.theme.bash"
|
source "${BASH_IT}/themes/p4helpers.theme.bash"
|
||||||
BASH_IT_LOG_PREFIX="themes: command_duration: "
|
BASH_IT_LOG_PREFIX="themes: command_duration: "
|
||||||
# shellcheck source=./themes/command_duration.theme.bash
|
|
||||||
source "${BASH_IT}/themes/command_duration.theme.bash"
|
source "${BASH_IT}/themes/command_duration.theme.bash"
|
||||||
BASH_IT_LOG_PREFIX="themes: base: "
|
BASH_IT_LOG_PREFIX="themes: base: "
|
||||||
# shellcheck source=./themes/base.theme.bash
|
|
||||||
source "${BASH_IT}/themes/base.theme.bash"
|
source "${BASH_IT}/themes/base.theme.bash"
|
||||||
|
|
||||||
BASH_IT_LOG_PREFIX="lib: appearance: "
|
BASH_IT_LOG_PREFIX="lib: appearance: "
|
||||||
# appearance (themes) now, after all dependencies
|
# appearance (themes) now, after all dependencies
|
||||||
# shellcheck source=./lib/appearance.bash
|
# shellcheck source=SCRIPTDIR/lib/appearance.bash
|
||||||
source "$APPEARANCE_LIB"
|
source "$APPEARANCE_LIB"
|
||||||
|
BASH_IT_LOG_PREFIX="core: main: "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASH_IT_LOG_PREFIX="core: main: "
|
|
||||||
_log_debug "Loading custom aliases, completion, plugins..."
|
_log_debug "Loading custom aliases, completion, plugins..."
|
||||||
for file_type in "aliases" "completion" "plugins"; do
|
for _bash_it_main_file_type in "aliases" "completion" "plugins"; do
|
||||||
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then
|
_bash_it_main_file_custom="${BASH_IT}/${_bash_it_main_file_type}/custom.${_bash_it_main_file_type}.bash"
|
||||||
BASH_IT_LOG_PREFIX="${file_type}: custom: "
|
if [[ -s "${_bash_it_main_file_custom}" ]]; then
|
||||||
|
_bash-it-log-prefix-by-path "${_bash_it_main_file_custom}"
|
||||||
_log_debug "Loading component..."
|
_log_debug "Loading component..."
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
|
source "${_bash_it_main_file_custom}"
|
||||||
fi
|
fi
|
||||||
|
BASH_IT_LOG_PREFIX="core: main: "
|
||||||
done
|
done
|
||||||
|
|
||||||
# Custom
|
# Custom
|
||||||
BASH_IT_LOG_PREFIX="core: main: "
|
|
||||||
_log_debug "Loading general custom files..."
|
_log_debug "Loading general custom files..."
|
||||||
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
|
for _bash_it_main_file_custom in "${BASH_IT_CUSTOM}"/*.bash "${BASH_IT_CUSTOM}"/*/*.bash; do
|
||||||
for _bash_it_config_file in $CUSTOM; do
|
if [[ -s "${_bash_it_main_file_custom}" ]]; then
|
||||||
if [ -e "${_bash_it_config_file}" ]; then
|
_bash-it-log-prefix-by-path "${_bash_it_main_file_custom}"
|
||||||
filename=$(basename "${_bash_it_config_file}")
|
|
||||||
filename=${filename%*.bash}
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
BASH_IT_LOG_PREFIX="custom: $filename: "
|
|
||||||
_log_debug "Loading custom file..."
|
_log_debug "Loading custom file..."
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$_bash_it_config_file"
|
source "$_bash_it_main_file_custom"
|
||||||
fi
|
fi
|
||||||
|
BASH_IT_LOG_PREFIX="core: main: "
|
||||||
done
|
done
|
||||||
|
|
||||||
unset _bash_it_config_file
|
|
||||||
if [[ -n "${PROMPT:-}" ]]; then
|
if [[ -n "${PROMPT:-}" ]]; then
|
||||||
export PS1="\[""$PROMPT""\]"
|
PS1="${PROMPT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Adding Support for other OSes
|
# Adding Support for other OSes
|
||||||
PREVIEW="less"
|
if _command_exists gloobus-preview; then
|
||||||
|
|
||||||
if [ -s /usr/bin/gloobus-preview ]; then
|
|
||||||
PREVIEW="gloobus-preview"
|
PREVIEW="gloobus-preview"
|
||||||
elif [ -s /Applications/Preview.app ]; then
|
elif [[ -d /Applications/Preview.app ]]; then
|
||||||
# shellcheck disable=SC2034
|
|
||||||
PREVIEW="/Applications/Preview.app"
|
PREVIEW="/Applications/Preview.app"
|
||||||
|
else
|
||||||
|
PREVIEW="less"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# BASH_IT_RELOAD_LEGACY is set.
|
# BASH_IT_RELOAD_LEGACY is set.
|
||||||
if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
|
if [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]] && ! _command_exists reload; then
|
||||||
case $OSTYPE in
|
# shellcheck disable=SC2139
|
||||||
darwin*)
|
alias reload="builtin source '${BASH_IT_BASHRC?}'"
|
||||||
alias reload='source ~/.bash_profile'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
alias reload='source ~/.bashrc'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
|
for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
|
||||||
eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
|
eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
|
||||||
done
|
done
|
||||||
unset "${!_bash_it_library_finalize_@}"
|
unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}"
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,10 @@ completion/available/wpscan.completion.bash
|
||||||
# libraries
|
# libraries
|
||||||
lib/colors.bash
|
lib/colors.bash
|
||||||
lib/helpers.bash
|
lib/helpers.bash
|
||||||
|
lib/history.bash
|
||||||
lib/log.bash
|
lib/log.bash
|
||||||
lib/preexec.bash
|
lib/preexec.bash
|
||||||
|
lib/preview.bash
|
||||||
lib/search.bash
|
lib/search.bash
|
||||||
lib/utilities.bash
|
lib/utilities.bash
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
|
about-plugin 'Automatic completion of aliases'
|
||||||
|
# Load after all aliases and completions to understand what needs to be completed
|
||||||
|
# BASH_IT_LOAD_PRIORITY: 800
|
||||||
|
|
||||||
|
# References:
|
||||||
|
# http://superuser.com/a/437508/119764
|
||||||
|
# http://stackoverflow.com/a/1793178/1228454
|
||||||
|
|
||||||
|
# Automatically add completion for all aliases to commands having completion functions
|
||||||
|
function _bash-it-component-completion-callback-on-init-aliases() {
|
||||||
|
local namespace="alias_completion"
|
||||||
|
local tmp_file completion_loader alias_name line completions
|
||||||
|
local alias_arg_words new_completion compl_func compl_wrapper alias_defn
|
||||||
|
|
||||||
|
# create array of function completion triggers, keeping multi-word triggers together
|
||||||
|
IFS=$'\n' read -d '' -ra completions < <(complete -p)
|
||||||
|
((${#completions[@]} == 0)) && return 0
|
||||||
|
|
||||||
|
completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s)
|
||||||
|
completions=("${completions[@]#complete -}") # strip anything missed
|
||||||
|
completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s)
|
||||||
|
|
||||||
|
# create temporary file for wrapper functions and completions
|
||||||
|
tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1
|
||||||
|
|
||||||
|
completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')"
|
||||||
|
|
||||||
|
# read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
|
||||||
|
# some aliases do have backslashes that needs to be interpreted
|
||||||
|
# shellcheck disable=SC2162
|
||||||
|
while read line; do
|
||||||
|
line="${line#alias }"
|
||||||
|
alias_name="${line%%=*}"
|
||||||
|
alias_defn="${line#*=}" # alias definition
|
||||||
|
alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias
|
||||||
|
alias_cmd="${alias_cmd:1}" # lose opening quotation mark
|
||||||
|
alias_args="${alias_defn#*[[:space:]]}" # everything after first word
|
||||||
|
alias_args="${alias_args%\'}" # lose ending quotation mark
|
||||||
|
|
||||||
|
# skip aliases to pipes, boolean control structures and other command lists
|
||||||
|
[[ "${alias_args}" =~ [\|\&\;\)\(\n] ]] && continue
|
||||||
|
# avoid expanding wildcards
|
||||||
|
read -a alias_arg_words <<< "$alias_args"
|
||||||
|
|
||||||
|
# skip alias if there is no completion function triggered by the aliased command
|
||||||
|
if ! _bash-it-array-contains-element "$alias_cmd" "${completions[@]}"; then
|
||||||
|
if [[ -n "$completion_loader" ]]; then
|
||||||
|
# force loading of completions for the aliased command
|
||||||
|
"${completion_loader:?}" "${alias_cmd}"
|
||||||
|
# 124 means completion loader was successful
|
||||||
|
[[ $? -eq 124 ]] || continue
|
||||||
|
completions+=("$alias_cmd")
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
|
||||||
|
|
||||||
|
# create a wrapper inserting the alias arguments if any
|
||||||
|
if [[ -n $alias_args ]]; then
|
||||||
|
compl_func="${new_completion/#* -F /}"
|
||||||
|
compl_func="${compl_func%% *}"
|
||||||
|
# avoid recursive call loops by ignoring our own functions
|
||||||
|
if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
|
||||||
|
compl_wrapper="_${namespace}::${alias_name}"
|
||||||
|
echo "function $compl_wrapper {
|
||||||
|
local compl_word=\$2
|
||||||
|
local prec_word=\$3
|
||||||
|
# check if prec_word is the alias itself. if so, replace it
|
||||||
|
# with the last word in the unaliased form, i.e.,
|
||||||
|
# alias_cmd + ' ' + alias_args.
|
||||||
|
if [[ \$COMP_LINE == \"\$prec_word \$compl_word\" ]]; then
|
||||||
|
prec_word='$alias_cmd $alias_args'
|
||||||
|
prec_word=\${prec_word#* }
|
||||||
|
fi
|
||||||
|
(( COMP_CWORD += ${#alias_arg_words[@]} ))
|
||||||
|
COMP_WORDS=($alias_cmd $alias_args \${COMP_WORDS[@]:1})
|
||||||
|
(( COMP_POINT -= \${#COMP_LINE} ))
|
||||||
|
COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args}
|
||||||
|
(( COMP_POINT += \${#COMP_LINE} ))
|
||||||
|
$compl_func \"$alias_cmd\" \"\$compl_word\" \"\$prec_word\"
|
||||||
|
}" >> "$tmp_file"
|
||||||
|
new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# replace completion trigger by alias
|
||||||
|
if [[ -n $new_completion ]]; then
|
||||||
|
new_completion="${new_completion% *} $alias_name"
|
||||||
|
echo "$new_completion" >> "$tmp_file"
|
||||||
|
fi
|
||||||
|
done < <(alias -p)
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$tmp_file" && command rm -f "$tmp_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
_bash-it-component-completion-callback-on-init-aliases
|
||||||
|
|
@ -13,7 +13,7 @@ function _bash-it() {
|
||||||
prev="${COMP_WORDS[COMP_CWORD - 1]}"
|
prev="${COMP_WORDS[COMP_CWORD - 1]}"
|
||||||
verb="${COMP_WORDS[1]}"
|
verb="${COMP_WORDS[1]}"
|
||||||
file_type="${COMP_WORDS[2]:-}"
|
file_type="${COMP_WORDS[2]:-}"
|
||||||
candidates=('disable' 'enable' 'help' 'migrate' 'reload' 'restart' 'profile' 'doctor' 'search' 'show' 'update' 'version')
|
candidates=('disable' 'enable' 'help' 'migrate' 'reload' 'restart' 'preview' 'profile' 'doctor' 'search' 'show' 'update' 'version')
|
||||||
case "${verb}" in
|
case "${verb}" in
|
||||||
show)
|
show)
|
||||||
candidates=('aliases' 'completions' 'plugins')
|
candidates=('aliases' 'completions' 'plugins')
|
||||||
|
|
@ -59,6 +59,10 @@ function _bash-it() {
|
||||||
_compreply_candidates
|
_compreply_candidates
|
||||||
;;
|
;;
|
||||||
migrate | reload | restart | search | version) ;;
|
migrate | reload | restart | search | version) ;;
|
||||||
|
preview)
|
||||||
|
_bash-it-preview # completes itself
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
enable | disable)
|
enable | disable)
|
||||||
if [[ "${verb}" == "enable" ]]; then
|
if [[ "${verb}" == "enable" ]]; then
|
||||||
suffix="disabled"
|
suffix="disabled"
|
||||||
|
|
|
||||||
|
|
@ -14,31 +14,24 @@ else
|
||||||
__bash_it_restore_nounset=false
|
__bash_it_restore_nounset=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090 disable=SC1091
|
||||||
if [[ -r "${BASH_COMPLETION:-}" ]]; then
|
if [[ -r "${BASH_COMPLETION:-}" ]]; then
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "${BASH_COMPLETION}"
|
source "${BASH_COMPLETION}"
|
||||||
|
|
||||||
elif [[ -r /etc/bash_completion ]]; then
|
elif [[ -r /etc/bash_completion ]]; then
|
||||||
# shellcheck disable=SC1091
|
|
||||||
source /etc/bash_completion
|
source /etc/bash_completion
|
||||||
|
|
||||||
# Some distribution makes use of a profile.d script to import completion.
|
# Some distribution makes use of a profile.d script to import completion.
|
||||||
elif [[ -r /etc/profile.d/bash_completion.sh ]]; then
|
elif [[ -r /etc/profile.d/bash_completion.sh ]]; then
|
||||||
# shellcheck disable=SC1091
|
|
||||||
source /etc/profile.d/bash_completion.sh
|
source /etc/profile.d/bash_completion.sh
|
||||||
|
|
||||||
elif _bash_it_homebrew_check; then
|
elif _bash_it_homebrew_check; then
|
||||||
: "${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}"
|
: "${BASH_COMPLETION_COMPAT_DIR:=${BASH_IT_HOMEBREW_PREFIX}/etc/bash_completion.d}"
|
||||||
|
|
||||||
case "${BASH_VERSION}" in
|
case "${BASH_VERSION}" in
|
||||||
1* | 2* | 3.0* | 3.1*)
|
1* | 2* | 3.0* | 3.1*)
|
||||||
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
|
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
|
||||||
;;
|
;;
|
||||||
3.2* | 4.0* | 4.1*)
|
3.2* | 4.0* | 4.1*)
|
||||||
# Import version 1.x of bash-completion, if installed.
|
# Import version 1.x of bash-completion, if installed.
|
||||||
BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion"
|
BASH_COMPLETION="${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@1/etc/bash_completion"
|
||||||
if [[ -r "$BASH_COMPLETION" ]]; then
|
if [[ -r "$BASH_COMPLETION" ]]; then
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$BASH_COMPLETION"
|
source "$BASH_COMPLETION"
|
||||||
else
|
else
|
||||||
unset BASH_COMPLETION
|
unset BASH_COMPLETION
|
||||||
|
|
@ -46,9 +39,8 @@ elif _bash_it_homebrew_check; then
|
||||||
;;
|
;;
|
||||||
4.2* | 5* | *)
|
4.2* | 5* | *)
|
||||||
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
|
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
|
||||||
if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
|
if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@2/etc/profile.d/bash_completion.sh" ]]; then
|
||||||
# shellcheck disable=SC1091
|
source "${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@2/etc/profile.d/bash_completion.sh"
|
||||||
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ Examples:
|
||||||
# Disable theming
|
# Disable theming
|
||||||
export BASH_IT_THEME=""
|
export BASH_IT_THEME=""
|
||||||
|
|
||||||
You can easily preview the themes in your own shell using ``BASH_PREVIEW=true bash-it reload``.
|
You can easily preview the themes in your own shell using ``bash-it preview``.
|
||||||
|
|
||||||
If you've created your own custom prompts, we'd love it if you shared them with everyone else! Just submit a Pull Request.
|
If you've created your own custom prompts, we'd love it if you shared them with everyone else! Just submit a Pull Request.
|
||||||
You can see theme screenshots on `wiki/Themes <https://github.com/Bash-it/bash-it/wiki/Themes>`_.
|
You can see theme screenshots on `wiki/Themes <https://github.com/Bash-it/bash-it/wiki/Themes>`_.
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ alias reload_plugins="$(_make_reload_alias plugin plugins)"
|
||||||
|
|
||||||
function bash-it() {
|
function bash-it() {
|
||||||
about 'Bash-it help and maintenance'
|
about 'Bash-it help and maintenance'
|
||||||
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] '
|
param '1: verb [one of: help | show | enable | disable | migrate | update | search | preview | version | reload | restart | doctor ] '
|
||||||
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
|
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
|
||||||
param '3: specific component [optional]'
|
param '3: specific component [optional]'
|
||||||
example '$ bash-it show plugins'
|
example '$ bash-it show plugins'
|
||||||
|
|
@ -108,6 +108,8 @@ function bash-it() {
|
||||||
example '$ bash-it migrate'
|
example '$ bash-it migrate'
|
||||||
example '$ bash-it update'
|
example '$ bash-it update'
|
||||||
example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]'
|
example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]'
|
||||||
|
example '$ bash-it preview'
|
||||||
|
example '$ bash-it preview essential'
|
||||||
example '$ bash-it version'
|
example '$ bash-it version'
|
||||||
example '$ bash-it reload'
|
example '$ bash-it reload'
|
||||||
example '$ bash-it restart'
|
example '$ bash-it restart'
|
||||||
|
|
@ -142,6 +144,10 @@ function bash-it() {
|
||||||
_bash-it-search "$component" "$@"
|
_bash-it-search "$component" "$@"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
preview)
|
||||||
|
_bash-it-preview "$component" "$@"
|
||||||
|
return
|
||||||
|
;;
|
||||||
update)
|
update)
|
||||||
func="_bash-it-update-$component"
|
func="_bash-it-update-$component"
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
|
#
|
||||||
|
# Functions for working with Bash's command history.
|
||||||
|
|
||||||
|
function _bash-it-history-init() {
|
||||||
|
safe_append_preexec '_bash-it-history-auto-save'
|
||||||
|
safe_append_prompt_command '_bash-it-history-auto-load'
|
||||||
|
}
|
||||||
|
|
||||||
|
function _bash-it-history-auto-save() {
|
||||||
|
case $HISTCONTROL in
|
||||||
|
*'noauto'* | *'autoload'*)
|
||||||
|
: # Do nothing, as configured.
|
||||||
|
;;
|
||||||
|
*'auto'*)
|
||||||
|
# Append new history from this session to the $HISTFILE
|
||||||
|
history -a
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Append *only* if shell option `histappend` has been enabled.
|
||||||
|
shopt -q histappend && history -a && return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function _bash-it-history-auto-load() {
|
||||||
|
case $HISTCONTROL in
|
||||||
|
*'noauto'*)
|
||||||
|
: # Do nothing, as configured.
|
||||||
|
;;
|
||||||
|
*'autosave'*)
|
||||||
|
# Append new history from this session to the $HISTFILE
|
||||||
|
history -a
|
||||||
|
;;
|
||||||
|
*'autoloadnew'*)
|
||||||
|
# Read new entries from $HISTFILE
|
||||||
|
history -n
|
||||||
|
;;
|
||||||
|
*'auto'*)
|
||||||
|
# Blank in-memory history, then read entire $HISTFILE fresh from disk.
|
||||||
|
history -a && history -c && history -r
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
: # Do nothing, default.
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_bash_it_library_finalize_hook+=('_bash-it-history-init')
|
||||||
|
|
@ -1,19 +1,34 @@
|
||||||
if [[ "${BASH_PREVIEW:-}" ]];
|
# shellcheck shell=bash
|
||||||
then
|
#
|
||||||
unset BASH_PREVIEW #Prevent infinite looping
|
# Displays the prompt from each _Bash It_ theme.
|
||||||
echo "
|
|
||||||
|
|
||||||
Previewing Bash-it Themes
|
function _bash-it-preview() {
|
||||||
|
local BASH_IT_THEME BASH_IT_LOG_LEVEL
|
||||||
|
local themes IFS=$'\n' cur
|
||||||
|
|
||||||
"
|
if [[ $# -gt '0' ]]; then
|
||||||
|
themes=("$@")
|
||||||
|
else
|
||||||
|
themes=("${BASH_IT?}/themes"/*/*.theme.bash)
|
||||||
|
themes=("${themes[@]##*/}")
|
||||||
|
themes=("${themes[@]%.theme.bash}")
|
||||||
|
fi
|
||||||
|
|
||||||
THEMES="$BASH_IT/themes/*/*.theme.bash"
|
if [[ ${COMP_CWORD:-} -gt '0' ]]; then
|
||||||
for theme in $THEMES
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
do
|
read -d '' -ra COMPREPLY < <(compgen -W "all${IFS}${themes[*]}" -- "${cur}")
|
||||||
BASH_IT_THEME=${theme%.theme.bash}
|
return
|
||||||
BASH_IT_THEME=${BASH_IT_THEME##*/}
|
fi
|
||||||
echo "
|
printf '\n\n\t%s\n\n' "Previewing Bash-it Themes"
|
||||||
$BASH_IT_THEME"
|
|
||||||
echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i
|
# shellcheck disable=SC2034
|
||||||
done
|
for BASH_IT_THEME in "${themes[@]}"; do
|
||||||
|
BASH_IT_LOG_LEVEL=0
|
||||||
|
bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"'
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -n "${BASH_PREVIEW:-}" ]]; then
|
||||||
|
_bash-it-preview "${BASH_PREVIEW}" "$@"
|
||||||
|
unset BASH_PREVIEW #Prevent infinite looping
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,105 +1,5 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
# Load after the other completions to understand what needs to be completed
|
# stub for renamed file
|
||||||
# BASH_IT_LOAD_PRIORITY: 365
|
|
||||||
|
|
||||||
cite about-plugin
|
_enable-completion aliases && _disable-plugin alias-completion
|
||||||
about-plugin 'Automatic completion of aliases'
|
source "${BASH_IT?}/completion/aliases.completion.bash"
|
||||||
|
|
||||||
# References:
|
|
||||||
# http://superuser.com/a/437508/119764
|
|
||||||
# http://stackoverflow.com/a/1793178/1228454
|
|
||||||
|
|
||||||
# This needs to be a plugin so it gets executed after the completions and the aliases have been defined.
|
|
||||||
# Bash-it loads its components in the order
|
|
||||||
# 1) Aliases
|
|
||||||
# 2) Completions
|
|
||||||
# 3) Plugins
|
|
||||||
# 4) Custom scripts
|
|
||||||
|
|
||||||
# Automatically add completion for all aliases to commands having completion functions
|
|
||||||
function alias_completion {
|
|
||||||
local namespace="alias_completion"
|
|
||||||
local tmp_file completion_loader alias_name alias_tokens line completions
|
|
||||||
local alias_arg_words new_completion compl_func compl_wrapper
|
|
||||||
|
|
||||||
# parse function based completion definitions, where capture group 2 => function and 3 => trigger
|
|
||||||
local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)'
|
|
||||||
# parse alias definitions, where capture group 1 => trigger, 2 => command, 3 => command arguments
|
|
||||||
local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'"
|
|
||||||
|
|
||||||
# create array of function completion triggers, keeping multi-word triggers together
|
|
||||||
eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
|
|
||||||
((${#completions[@]} == 0)) && return 0
|
|
||||||
|
|
||||||
# create temporary file for wrapper functions and completions
|
|
||||||
tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1
|
|
||||||
|
|
||||||
completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')"
|
|
||||||
|
|
||||||
# read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
|
|
||||||
# some aliases do have backslashes that needs to be interpreted
|
|
||||||
# shellcheck disable=SC2162
|
|
||||||
while read line; do
|
|
||||||
eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error
|
|
||||||
# shellcheck disable=SC2154 # see `eval` above
|
|
||||||
alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }"
|
|
||||||
|
|
||||||
# skip aliases to pipes, boolean control structures and other command lists
|
|
||||||
# (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters)
|
|
||||||
eval "alias_arg_words=($alias_args)" 2> /dev/null || continue
|
|
||||||
# avoid expanding wildcards
|
|
||||||
read -a alias_arg_words <<< "$alias_args"
|
|
||||||
|
|
||||||
# skip alias if there is no completion function triggered by the aliased command
|
|
||||||
if ! _bash-it-array-contains-element "$alias_cmd" "${completions[@]}"; then
|
|
||||||
if [[ -n "$completion_loader" ]]; then
|
|
||||||
# force loading of completions for the aliased command
|
|
||||||
eval "$completion_loader $alias_cmd"
|
|
||||||
# 124 means completion loader was successful
|
|
||||||
[[ $? -eq 124 ]] || continue
|
|
||||||
completions+=("$alias_cmd")
|
|
||||||
else
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
|
|
||||||
|
|
||||||
# create a wrapper inserting the alias arguments if any
|
|
||||||
if [[ -n $alias_args ]]; then
|
|
||||||
compl_func="${new_completion/#* -F /}"
|
|
||||||
compl_func="${compl_func%% *}"
|
|
||||||
# avoid recursive call loops by ignoring our own functions
|
|
||||||
if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
|
|
||||||
compl_wrapper="_${namespace}::${alias_name}"
|
|
||||||
echo "function $compl_wrapper {
|
|
||||||
local compl_word=\$2
|
|
||||||
local prec_word=\$3
|
|
||||||
# check if prec_word is the alias itself. if so, replace it
|
|
||||||
# with the last word in the unaliased form, i.e.,
|
|
||||||
# alias_cmd + ' ' + alias_args.
|
|
||||||
if [[ \$COMP_LINE == \"\$prec_word \$compl_word\" ]]; then
|
|
||||||
prec_word='$alias_cmd $alias_args'
|
|
||||||
prec_word=\${prec_word#* }
|
|
||||||
fi
|
|
||||||
(( COMP_CWORD += ${#alias_arg_words[@]} ))
|
|
||||||
COMP_WORDS=($alias_cmd $alias_args \${COMP_WORDS[@]:1})
|
|
||||||
(( COMP_POINT -= \${#COMP_LINE} ))
|
|
||||||
COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args}
|
|
||||||
(( COMP_POINT += \${#COMP_LINE} ))
|
|
||||||
$compl_func \"$alias_cmd\" \"\$compl_word\" \"\$prec_word\"
|
|
||||||
}" >> "$tmp_file"
|
|
||||||
new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# replace completion trigger by alias
|
|
||||||
if [[ -n $new_completion ]]; then
|
|
||||||
new_completion="${new_completion% *} $alias_name"
|
|
||||||
echo "$new_completion" >> "$tmp_file"
|
|
||||||
fi
|
|
||||||
done < <(alias -p | sed -Ene "s/$alias_regex/\2 '\3' '\4'/p")
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
source "$tmp_file" && command rm -f "$tmp_file"
|
|
||||||
}
|
|
||||||
|
|
||||||
alias_completion
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
about-plugin 'display info about your battery charge level'
|
about-plugin 'display info about your battery charge level'
|
||||||
|
|
||||||
function ac_adapter_connected() {
|
function ac_adapter_connected() {
|
||||||
|
local batteries
|
||||||
if _command_exists upower; then
|
if _command_exists upower; then
|
||||||
upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'charging\|fully-charged'
|
batteries="$(upower -e | grep --max-count=1 -i BAT)"
|
||||||
|
upower -i "${batteries}" | grep 'state' | grep -q 'charging\|fully-charged'
|
||||||
elif _command_exists acpi; then
|
elif _command_exists acpi; then
|
||||||
acpi -a | grep -q "on-line"
|
acpi -a | grep -q "on-line"
|
||||||
elif _command_exists pmset; then
|
elif _command_exists pmset; then
|
||||||
|
|
@ -16,8 +18,10 @@ function ac_adapter_connected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ac_adapter_disconnected() {
|
function ac_adapter_disconnected() {
|
||||||
|
local batteries
|
||||||
if _command_exists upower; then
|
if _command_exists upower; then
|
||||||
upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'discharging'
|
batteries="$(upower -e | grep --max-count=1 -i BAT)"
|
||||||
|
upower -i "${batteries}" | grep 'state' | grep -q 'discharging'
|
||||||
elif _command_exists acpi; then
|
elif _command_exists acpi; then
|
||||||
acpi -a | grep -q "off-line"
|
acpi -a | grep -q "off-line"
|
||||||
elif _command_exists pmset; then
|
elif _command_exists pmset; then
|
||||||
|
|
@ -33,16 +37,17 @@ function battery_percentage() {
|
||||||
about 'displays battery charge as a percentage of full (100%)'
|
about 'displays battery charge as a percentage of full (100%)'
|
||||||
group 'battery'
|
group 'battery'
|
||||||
|
|
||||||
local command_output="no"
|
local command_output batteries
|
||||||
|
|
||||||
if _command_exists upower; then
|
if _command_exists upower; then
|
||||||
command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT)" | grep percentage | grep -o "[0-9]\+" | head -1)
|
batteries="$(upower --enumerate | grep --max-count=1 -i BAT)"
|
||||||
|
command_output="$(upower --show-info "${batteries:-}" | grep percentage | grep -o '[0-9]\+' | head -1)"
|
||||||
elif _command_exists acpi; then
|
elif _command_exists acpi; then
|
||||||
command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}')
|
command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}')
|
||||||
elif _command_exists pmset; then
|
elif _command_exists pmset; then
|
||||||
command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1)
|
command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o '[0-9]\+' | head -1)
|
||||||
elif _command_exists ioreg; then
|
elif _command_exists ioreg; then
|
||||||
command_output=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o "[0-9]\+" | head -1)
|
command_output=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o '[0-9]\+' | head -1)
|
||||||
elif _command_exists WMIC; then
|
elif _command_exists WMIC; then
|
||||||
command_output=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
|
command_output=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
about-plugin 'eternal bash history'
|
about-plugin 'eternal bash history'
|
||||||
|
|
||||||
# Load after the history plugin
|
if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then
|
||||||
# BASH_IT_LOAD_PRIORITY: 375
|
_log_warning "Bash version 4.3 introduced the 'unlimited' history size capability."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Modify history sizes before changing location to avoid unintentionally
|
# Modify history sizes before changing location to avoid unintentionally
|
||||||
# truncating the history file early.
|
# truncating the history file early.
|
||||||
|
|
||||||
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
|
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
|
||||||
export HISTSIZE=-1
|
readonly HISTSIZE=-1 2> /dev/null || true
|
||||||
|
|
||||||
# "Non-numeric values and numeric values less than zero inhibit truncation"
|
# "Non-numeric values and numeric values less than zero inhibit truncation"
|
||||||
export HISTFILESIZE='unlimited'
|
readonly HISTFILESIZE='unlimited' 2> /dev/null || true
|
||||||
|
|
||||||
# Use a custom history file location so history is not truncated
|
# Use a custom history file location so history is not truncated
|
||||||
# if the environment ever loses this "eternal" configuration.
|
# if the environment ever loses this "eternal" configuration.
|
||||||
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
|
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
|
||||||
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
|
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
|
||||||
export HISTFILE="${HISTDIR?}/history"
|
readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null || true
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
about-plugin 'search history using the prefix already entered'
|
about-plugin 'search history using the prefix already entered'
|
||||||
|
|
||||||
# Load after the history plugin
|
|
||||||
# BASH_IT_LOAD_PRIORITY: 375
|
|
||||||
|
|
||||||
# enter a few characters and press UpArrow/DownArrow
|
# enter a few characters and press UpArrow/DownArrow
|
||||||
# to search backwards/forwards through the history
|
# to search backwards/forwards through the history
|
||||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
about-plugin 'search history using the substring already entered'
|
about-plugin 'search history using the substring already entered'
|
||||||
|
|
||||||
# Load after the history plugin
|
|
||||||
# BASH_IT_LOAD_PRIORITY: 375
|
|
||||||
|
|
||||||
# enter a few characters and press UpArrow/DownArrow
|
# enter a few characters and press UpArrow/DownArrow
|
||||||
# to search backwards/forwards through the history
|
# to search backwards/forwards through the history
|
||||||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,13 @@ about-plugin 'improve history handling with sane defaults'
|
||||||
# variable when the shell exits, rather than overwriting the file.
|
# variable when the shell exits, rather than overwriting the file.
|
||||||
shopt -s histappend
|
shopt -s histappend
|
||||||
|
|
||||||
# erase duplicates; alternative option: export HISTCONTROL=ignoredups
|
# 'ignorespace': don't save command lines which begin with a space to history
|
||||||
export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
|
# 'erasedups' (alternative 'ignoredups'): don't save duplicates to history
|
||||||
|
# 'autoshare': automatically share history between multiple running shells
|
||||||
|
: "${HISTCONTROL:=ignorespace:erasedups:autoshare}"
|
||||||
|
|
||||||
# resize history to 100x the default (500)
|
# resize history to 100x the default (500)
|
||||||
export HISTSIZE=${HISTSIZE:-50000}
|
: "${HISTSIZE:=50000}"
|
||||||
|
|
||||||
# Flush history to disk after each command.
|
|
||||||
export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}"
|
|
||||||
|
|
||||||
function top-history() {
|
function top-history() {
|
||||||
about 'print the name and count of the most commonly run tools'
|
about 'print the name and count of the most commonly run tools'
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
# This is the default profile of Bash-it
|
# This is the default profile of Bash-it
|
||||||
|
|
||||||
# plugins
|
# plugins
|
||||||
plugins alias-completion
|
|
||||||
plugins base
|
plugins base
|
||||||
|
|
||||||
# completion
|
# completion
|
||||||
|
completion aliases
|
||||||
completion bash-it
|
completion bash-it
|
||||||
completion system
|
completion system
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,26 @@
|
||||||
load ../test_helper
|
load ../test_helper
|
||||||
load ../test_helper_libs
|
load ../test_helper_libs
|
||||||
|
|
||||||
|
# Load something, anything...
|
||||||
load ../../completion/available/capistrano.completion
|
load ../../completion/available/capistrano.completion
|
||||||
|
|
||||||
@test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" {
|
@test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" {
|
||||||
alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative"
|
alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative"
|
||||||
load ../../plugins/available/alias-completion.plugin
|
run load ../../completion/available/aliases.completion
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" {
|
@test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" {
|
||||||
alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative'
|
alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative'
|
||||||
load ../../plugins/available/alias-completion.plugin
|
run load ../../completion/available/aliases.completion
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "alias-completion: See that having aliased rm command does not output unnecessary output" {
|
@test "alias-completion: See that having aliased rm command does not output unnecessary output" {
|
||||||
alias rm='rm -v'
|
alias rm='rm -v'
|
||||||
load ../../plugins/available/alias-completion.plugin
|
run load ../../completion/available/aliases.completion
|
||||||
|
|
||||||
refute_output
|
refute_output
|
||||||
}
|
}
|
||||||
|
|
@ -81,32 +81,32 @@ function __check_completion () {
|
||||||
|
|
||||||
@test "completion bash-it: show options" {
|
@test "completion bash-it: show options" {
|
||||||
run __check_completion 'bash-it '
|
run __check_completion 'bash-it '
|
||||||
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version"
|
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "completion bash-it: bash-ti - show options" {
|
@test "completion bash-it: bash-ti - show options" {
|
||||||
run __check_completion 'bash-ti '
|
run __check_completion 'bash-ti '
|
||||||
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version"
|
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "completion bash-it: shit - show options" {
|
@test "completion bash-it: shit - show options" {
|
||||||
run __check_completion 'shit '
|
run __check_completion 'shit '
|
||||||
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version"
|
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "completion bash-it: bashit - show options" {
|
@test "completion bash-it: bashit - show options" {
|
||||||
run __check_completion 'bashit '
|
run __check_completion 'bashit '
|
||||||
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version"
|
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "completion bash-it: batshit - show options" {
|
@test "completion bash-it: batshit - show options" {
|
||||||
run __check_completion 'batshit '
|
run __check_completion 'batshit '
|
||||||
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version"
|
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "completion bash-it: bash_it - show options" {
|
@test "completion bash-it: bash_it - show options" {
|
||||||
run __check_completion 'bash_it '
|
run __check_completion 'bash_it '
|
||||||
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version"
|
assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "completion bash-it: profile - show options" {
|
@test "completion bash-it: profile - show options" {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
# plugins
|
# plugins
|
||||||
plugins alias-completion
|
|
||||||
plugins base
|
plugins base
|
||||||
|
|
||||||
# completion
|
# completion
|
||||||
|
completion aliases
|
||||||
completion bash-it
|
completion bash-it
|
||||||
completion system
|
completion system
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
# plugins
|
# plugins
|
||||||
plugins alias-completion
|
|
||||||
plugins base
|
plugins base
|
||||||
# Bad type
|
# Bad type
|
||||||
pluugins alias-completion
|
compleetion aliases
|
||||||
|
|
||||||
# completion
|
# completion
|
||||||
|
completion aliases
|
||||||
completion bash-it
|
completion bash-it
|
||||||
completion system
|
completion system
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ function local_setup {
|
||||||
|
|
||||||
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
|
assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
|
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
|
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,7 @@ function local_setup {
|
||||||
|
|
||||||
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
|
assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
|
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
|
||||||
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
|
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
|
||||||
}
|
}
|
||||||
|
|
@ -356,7 +356,7 @@ function local_setup {
|
||||||
run _bash-it-profile-load "test"
|
run _bash-it-profile-load "test"
|
||||||
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
||||||
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
||||||
assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
|
assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash"
|
||||||
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
|
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
|
||||||
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash"
|
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash"
|
||||||
}
|
}
|
||||||
|
|
@ -384,7 +384,7 @@ function local_setup {
|
||||||
|
|
||||||
@test "helpers: profile load corrupted profile file: bad subdirectory" {
|
@test "helpers: profile load corrupted profile file: bad subdirectory" {
|
||||||
run _bash-it-profile-load "test-bad-type"
|
run _bash-it-profile-load "test-bad-type"
|
||||||
assert_line -n 1 -p "Bad line(#5) in profile, aborting load..."
|
assert_line -n 1 -p "Bad line(#4) in profile, aborting load..."
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "helpers: profile rm sanity" {
|
@test "helpers: profile rm sanity" {
|
||||||
|
|
|
||||||
|
|
@ -193,11 +193,26 @@ function setup_acpi {
|
||||||
# Creates a `upower` function that simulates output like the real `upower` command.
|
# Creates a `upower` function that simulates output like the real `upower` command.
|
||||||
# The passed in parameter is used for the remaining battery percentage.
|
# The passed in parameter is used for the remaining battery percentage.
|
||||||
function setup_upower {
|
function setup_upower {
|
||||||
percent="$1"
|
percent="$1"
|
||||||
|
BAT0="/org/freedesktop/UPower/devices/battery_BAT$RANDOM"
|
||||||
|
|
||||||
function upower {
|
|
||||||
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}"
|
function upower {
|
||||||
}
|
case $1 in
|
||||||
|
'-e'|'--enumerate')
|
||||||
|
echo "$BAT0"
|
||||||
|
echo "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery"
|
||||||
|
;;
|
||||||
|
'-i'|'--show-info')
|
||||||
|
if [[ $2 == "$BAT0" ]]
|
||||||
|
then
|
||||||
|
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}"
|
||||||
|
else
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins battery: battery-percentage with upower, 100%' {
|
@test 'plugins battery: battery-percentage with upower, 100%' {
|
||||||
|
|
|
||||||
|
|
@ -584,6 +584,7 @@ function aws_profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _save-and-reload-history() {
|
function _save-and-reload-history() {
|
||||||
local autosave=${1:-0}
|
local autosave="${1:-${HISTORY_AUTOSAVE:-0}}"
|
||||||
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
[[ ${autosave} -eq 1 ]] && local HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autoshare"
|
||||||
|
_bash-it-history-auto-save && _bash-it-history-auto-load
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue