Skip to content

Commit

Permalink
wrap command functions for no exiting of shells
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythra committed Nov 17, 2019
1 parent 6a58cf5 commit 6b0157c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions sash-command-handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion subcommands/sash-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
}
21 changes: 19 additions & 2 deletions subcommands/sash-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
}
21 changes: 19 additions & 2 deletions subcommands/sash-show.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, subcategory: Option<String>) -> String
#
# alias to sash:show
# alias to sash:show:wrap
sash_show() {
sash:show "$@"
sash:show:wrap "$@"
}
25 changes: 23 additions & 2 deletions subcommands/sash-time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#
# prints out timing info gathered during startup.
sash:time() {
__sash_guard_errors

local readonly keys=("${!__sash_timing_info[@]}")

local key=
Expand All @@ -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 $?
}

0 comments on commit 6b0157c

Please sign in to comment.