123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #!/bin/bash
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if [[ "$__bp_imported" == "defined" ]]; then
- return 0
- fi
- __bp_imported="defined"
-
-
-
-
-
- __bp_adjust_histcontrol() {
- local histcontrol
- histcontrol="${HISTCONTROL//ignorespace}"
-
- if [[ "$histcontrol" == *"ignoreboth"* ]]; then
- histcontrol="ignoredups:${histcontrol//ignoreboth}"
- fi;
- export HISTCONTROL="$histcontrol"
- }
-
-
-
-
-
-
- __bp_preexec_interactive_mode=""
-
- __bp_trim_whitespace() {
- local var=$@
- var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
- var="${var%"${var##*[![:space:]]}"}"
- echo -n "$var"
- }
-
-
-
-
- __bp_interactive_mode() {
- __bp_preexec_interactive_mode="on";
- }
-
-
-
-
- __bp_precmd_invoke_cmd() {
-
-
- local ret_value="$?"
-
-
- local precmd_function
- for precmd_function in ${precmd_functions[@]}; do
-
-
- if [[ -n $(type -t $precmd_function) ]]; then
- __bp_set_ret_value $ret_value
- $precmd_function
- fi
- done
- }
-
-
-
-
- __bp_set_ret_value() {
- return $1
- }
-
- __bp_in_prompt_command() {
-
- local prompt_command_array
- IFS=';' read -ra prompt_command_array <<< "$PROMPT_COMMAND"
-
- local trimmed_arg
- trimmed_arg=$(__bp_trim_whitespace "$1")
-
- local prompt_command_function
- for command in "${prompt_command_array[@]}"; do
- local trimmed_command
- trimmed_command=$(__bp_trim_whitespace "$command")
-
- if [[ "$trimmed_command" == "$trimmed_arg" ]]; then
- return 0
- fi
- done
-
- return 1
- }
-
-
-
-
-
- __bp_preexec_invoke_exec() {
-
- if [[ -n "$COMP_LINE" ]]
- then
-
-
- return
- fi
- if [[ -z "$__bp_preexec_interactive_mode" ]]
- then
-
-
- return
- else
-
-
-
-
-
- if [[ 0 -eq "$BASH_SUBSHELL" ]]
- then
- __bp_preexec_interactive_mode=""
- fi
- fi
-
- if __bp_in_prompt_command "$BASH_COMMAND"; then
-
-
-
- __bp_preexec_interactive_mode=""
- return
- fi
-
- local this_command="$(HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g")";
-
-
- if [[ -z "$this_command" ]]; then
- return
- fi
-
-
-
-
-
-
- local preexec_function
- for preexec_function in "${preexec_functions[@]}"; do
-
-
- if [[ -n $(type -t $preexec_function) ]]; then
- $preexec_function "$this_command"
- fi
- done
- }
-
-
- __bp_preexec_and_precmd_install() {
-
-
- if [[ -z "$BASH_VERSION" ]]; then
- return 1;
- fi
-
-
- if [[ "$PROMPT_COMMAND" == *"__bp_precmd_invoke_cmd"* ]]; then
- return 1;
- fi
-
-
- __bp_adjust_histcontrol
-
-
-
- local existing_prompt_command
-
- if [[ -n "$PROMPT_COMMAND" ]]; then
- existing_prompt_command=$(echo "$PROMPT_COMMAND" | sed '/; *$/!s/$/;/')
- else
- existing_prompt_command=""
- fi
-
-
- PROMPT_COMMAND="__bp_precmd_invoke_cmd; ${existing_prompt_command} __bp_interactive_mode;"
- trap '__bp_preexec_invoke_exec' DEBUG;
-
-
-
- precmd_functions+=(precmd)
- preexec_functions+=(preexec)
- }
-
-
- if [[ -z "$__bp_delay_install" ]]; then
- __bp_preexec_and_precmd_install
- fi;
|