diff --git a/CHANGELOG.md b/CHANGELOG.md index c32a0a3..c42efc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ prevent the need to spawn subshells. - Make some scripts a bit easier to read by removing nesting branches. +* Introduce "wrap" functions for sash commands so they don't just + cause your shell to randomly exit, leaving you in an undiagnosed + state. ## 1.3.0 (October 14th, 2019) diff --git a/sash-command-handler.sh b/sash-command-handler.sh index a1830b7..fcdeb28 100755 --- a/sash-command-handler.sh +++ b/sash-command-handler.sh @@ -16,19 +16,19 @@ sash() { local split_stdin=($(__sash_split_str "${__sash_parse_results[__STDIN]}" " ")) if [[ "${split_stdin[0]}" == "add" ]]; then - sash:add + sash:add:wrap return $? fi if [[ "${split_stdin[0]}" == "package" ]]; then - sash:package "${split_stdin[@]:1}" + sash:package:wrap "${split_stdin[@]:1}" return $? fi if [[ "${split_stdin[0]}" == "show" ]]; then - sash:show "${split_stdin[@]:1}" + sash:show:wrap "${split_stdin[@]:1}" return $? fi if [[ "${split_stdin[0]}" == "time" ]]; then - sash:time + sash:time:wrap return $? fi diff --git a/subcommands/sash-add.sh b/subcommands/sash-add.sh index dd24e30..e9bdafa 100755 --- a/subcommands/sash-add.sh +++ b/subcommands/sash-add.sh @@ -112,10 +112,27 @@ sash:add() { echo "[+] Added, and sourced!" } +# sash:add:wrap() -> None +# +# Wraps sash:add in a subshell to ensure the shell is not exited. +sash:add:wrap() { + __sash_allow_errors + + ( \ + sash:add \ + ) + + local readonly rc="$?" + if [[ "$rc" -ne "0" ]]; then + (>&2 echo -e "Failed to run sash:add!") + fi + return "$rc" +} + # sash_add() # # alias to sash:add sash_add() { - sash:add + sash:add:wrap return $? } diff --git a/subcommands/sash-package.sh b/subcommands/sash-package.sh index 94cf42b..6fb0a09 100755 --- a/subcommands/sash-package.sh +++ b/subcommands/sash-package.sh @@ -248,10 +248,27 @@ sash:package() { fi } +# sash:package:wrap() -> None +# +# Wraps sash:package in a subshell to ensure the shell is not exited. +sash:package:wrap() { + __sash_allow_errors + + ( \ + sash:package "$@" \ + ) + + local readonly rc="$?" + if [[ "$rc" -ne "0" ]]; then + (>&2 echo -e "Failed to run sash:package!") + fi + return "$rc" +} + # sash_package() # -# alias to sash:package +# alias to sash:package:wrap sash_package() { - sash:package "$@" + sash:package:wrap "$@" return $? } diff --git a/subcommands/sash-show.sh b/subcommands/sash-show.sh index 94e47b4..ba3acbb 100755 --- a/subcommands/sash-show.sh +++ b/subcommands/sash-show.sh @@ -82,9 +82,26 @@ sash:show() { fi } +# sash:show:wrap() -> None +# +# Wraps sash:show in a subshell to ensure the shell is not exited. +sash:show:wrap() { + __sash_allow_errors + + ( \ + sash:show "$@" \ + ) + + local readonly rc="$?" + if [[ "$rc" -ne "0" ]]; then + (>&2 echo -e "Failed to run sash:show!") + fi + return "$rc" +} + # sash_show(category: Option, subcategory: Option) -> String # -# alias to sash:show +# alias to sash:show:wrap sash_show() { - sash:show "$@" + sash:show:wrap "$@" } diff --git a/subcommands/sash-time.sh b/subcommands/sash-time.sh index 37a80df..05387f6 100755 --- a/subcommands/sash-time.sh +++ b/subcommands/sash-time.sh @@ -11,6 +11,8 @@ # # prints out timing info gathered during startup. sash:time() { + __sash_guard_errors + local readonly keys=("${!__sash_timing_info[@]}") local key= @@ -20,10 +22,29 @@ sash:time() { done | sort -k4,4nr -k1,1 } +# sash:time:wrap() -> None +# +# Modifies Variables: None +# +# Wraps sash:time in a subshell to ensure the shell is not exited. +sash:time:wrap() { + __sash_allow_errors + + ( \ + sash:time \ + ) + + local readonly rc="$?" + if [[ "$rc" -ne "0" ]]; then + (>&2 echo -e "Failed to run sash:time!") + fi + return "$rc" +} + # sash_time() # -# alias to sash:time +# alias to sash:time:wrap sash_time() { - sash:time + sash:time:wrap return $? }