diff --git a/README.md b/README.md index 26758c9..2ac7389 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,28 @@ -MIAOU-BASH -=========== +# MIAOU-BASH -MIAOU-BASH is a collection of settings and helpers aiming for leveraging BASH. -Developer-friendly, it may be used as a solo package or combined with other miaou-* utilities. +MIAOU-BASH is a mix of scripts and settings aiming for leveraging +your terminal experience. As the name suggests, it is based on Bash +and expect to work on any modern GNU/Linux. + +Actually the installation process supports only 2 distros: Debian and Arch Linux. +This package works either standalone or as a core dependency of any other +miaou-* utilities. + +Be aware (uppercase) MIAOU-BASH refer to a bunch of scripts and configuration settings. +Meanwhile (downcase) `miaou-bash` refer to one of these scripts, +maybe the most useful one! + +This is free software and licensed as: Affero GPL v3 + +Any feedback would be appreciated. +[contact@artcode.re](mailto:contact@artcode.re) ## Featuring +* [x] miaou-bash +* [x] semver-git_tag * [x] some aliases (l, ll, ltr, ...) -* [x] a smart prompt - * [x] git, lxd, failure aware -* [x] simple vim and micro settings -* [x] Debian and Archlinux support - -It's Free Software (AGPLv3), help yourself. -Any feedback would be appreciated. [contact@artcode.re](mailto:contact@artcode.re) +* [x] smart prompt + * [x] git, failure aware ## install @@ -40,20 +49,9 @@ Any feedback would be appreciated. [contact@artcode.re](mailto:contact@artcode.r * source /opt/miaou-bash/lib/functions.bash -## bindkeys - -### by default - -* CTRL + C => stop program -* CTRL + V => display bindkey -* CTRL + Z => interrupt for background job (fg, bg) - -* SHIFT + CTRL + C => copy -* SHIFT + CTRL + V => paste - -### customized +## extra bindkeys -* CTRL LEFT, RIGHT => move between words +* CTRL LEFT, RIGHT => move around words, back and forward * CTRL DELETE, BACKSPACE => delete word * ALT DELETE, BACKSPACE => delete line from cursor * CTRL + SHIFT + / => undo diff --git a/bin/miaou-bash b/bin/miaou-bash index aa4b259..02eb3a3 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -85,23 +85,26 @@ function on_return { # overridden function which permits backtracing of the original `exit` statement function exit { - error_source=("${BASH_SOURCE[@]}") - error_lineno=("${BASH_LINENO[@]}") - error_funcname=("${FUNCNAME[@]}") - unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]' - unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]' - error_funcname[-1]='
' - error_source=("${error_source[@]}") - error_lineno=("${error_lineno[@]}") - error_funcname=("${error_funcname[@]}") - - failure_code=${1:-0} - failure_type="EXIT" - failure_payload="${error_funcname[0]}" - - miaou_debug "" - print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}" - builtin exit "$failure_code" + code=${1:-0} + if [[ $code -gt 0 ]]; then + error_source=("${BASH_SOURCE[@]}") + error_lineno=("${BASH_LINENO[@]}") + error_funcname=("${FUNCNAME[@]}") + unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]' + unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]' + error_funcname[-1]='
' + error_source=("${error_source[@]}") + error_lineno=("${error_lineno[@]}") + error_funcname=("${error_funcname[@]}") + + failure_code=${1:-0} + failure_type="EXIT" + failure_payload="${error_funcname[0]}" + + miaou_debug "" + print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}" + fi + builtin exit "$code" } function tty_ansi { @@ -135,7 +138,8 @@ function add_miaou_error { function on_error { trap - RETURN failure_code="${1:-200}" - >&4 printf '\r' # TODO: force carriage return explicitly, is it really useful? + + # >&4 printf '\r' # TODO: force carriage return explicitly, is it really useful? miaou_debug "" diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 896735f..1b48e9a 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -6,13 +6,15 @@ function assert { ((test_count++)) - if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null; then - echo -n . - else - echo -n F - failures+=("$1") - return 1 + if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null 2>/dev/null 3>_miaou; then + if [[ -s _miaou ]]; then + echo -n . + return + fi fi + echo -n F + failures+=("$1") + return 1 } # assert performing '$1:script' successfully + output must contain '$2:content' @@ -71,32 +73,35 @@ set -uo pipefail test_count=0 failures=() -assert success -assert_grep success_with_args 'count args: 2' -- 'A B' C - -fail_type subshell_term SUBSHELL_ERROR -fail_type unbound_variable UNBOUND_VARIABLE -fail_type unbound_associative UNBOUND_VARIABLE -fail_type false FALSE -fail_type last_false COMMAND_ERROR -fail_type command_error COMMAND_ERROR -fail_type subshell_term SUBSHELL_ERROR -fail_type exit EXIT -fail_type command_not_found COMMAND_NOT_FOUND -fail_type source_not_found SOURCE_NOT_FOUND -fail_type file_not_found FILE_NOT_FOUND -fail_type child_error CHILD_ERROR 'prefer source than child process' - +TIMEFORMAT=$'\nelapsed: %Rs' + +time { + assert success + assert exit_0 + assert_grep success_with_args 'count args: 2' -- 'A B' C + + fail_type subshell_term SUBSHELL_ERROR + fail_type unbound_variable UNBOUND_VARIABLE + fail_type unbound_associative UNBOUND_VARIABLE + fail_type false FALSE + fail_type last_false COMMAND_ERROR + fail_type command_error COMMAND_ERROR + fail_type subshell_term SUBSHELL_ERROR + fail_type exit EXIT + fail_type command_not_found COMMAND_NOT_FOUND + fail_type source_not_found SOURCE_NOT_FOUND + fail_type file_not_found FILE_NOT_FOUND + fail_type child_error CHILD_ERROR 'prefer source than child process' +} failed=${#failures[@]} success=$((test_count - failed)) -echo if [[ $failed -gt 0 ]]; then ratio=$((100 * success / test_count)) echo "${ratio}% passed, ${test_count} tests, ${failed} failed!" echo failures: for failure in "${failures[@]}"; do - echo -e "\t- $failure" + echo -e "\t- $failure => replay: ./test/stub/scenario.bash $failure" done exit 1 else diff --git a/test/stub/extra/onemore.bash b/test/stub/extra/onemore.bash index 256934c..4e3e042 100755 --- a/test/stub/extra/onemore.bash +++ b/test/stub/extra/onemore.bash @@ -9,7 +9,7 @@ function onemore { function do_next { echo do_next - exit 10 # youpi + exit 13 # youpi grep nope nope echo $nope command_not_found diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 2c4c613..ade21ee 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -76,14 +76,20 @@ function do_success { return } +function do_exit_0 { + echo success + exit 0 + echo SHOULD NOT APPEAR +} + function do_success_with_args { echo "count args: $#" } function do_unbound_variable { a=5 - echo "a=${a}" - echo "b=${b}" + echo -n "content: " + echo -n "a=${a} b=${b}" } function do_source_not_found {