Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion etc/profile.d/codespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,18 @@ if [ `id -u` -ne 0 ]; then
# No helper matched: offer the duck the failed command's output to explain.
# If there's no output (e.g., grep with no match, or a program exiting 1), there's
# nothing to explain, and any button still showing is about an earlier command.
# $1 is the output, $2 the command line; the duck gets both, as a transcript.
_helpless() {
if [[ -z "${1//[[:space:]]/}" ]]; then
_help50_hide
return
fi
_alert "$(_ansi "🦆 Click \`help50\` above for help with that error.")"
_help50_button ask "$1"
if [[ -n "$2" ]]; then
_help50_button ask "$ $2"$'\n'"$1"
else
_help50_button ask "$1"
fi
}

# Command succeeded: hide the button, if showing
Expand Down
9 changes: 9 additions & 0 deletions tests/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ if run "$IMAGE" bash --login -c 'test -f /etc/profile.d/help50.sh -a -f /opt/cs5
test -z "$(_helpless " " 2>&1)" &&
_helpless "cat: x: No such file" 2>&1 | grep -q help50'

# _help50_button discards command50's output, so stub it to see the payload
check "the duck gets the command line and output as a transcript (or output alone without a command)"
run "$IMAGE" bash --login -c '
_alert() { :; }
_help50_button() { printf "%s" "$2"; }
test "$(_helpless "cat: x: No such file" "cat x")" = "$(printf "%s\n%s" "$ cat x" "cat: x: No such file")" &&
test "$(_helpless "cat: x: No such file")" = "cat: x: No such file" &&
test -z "$(_helpless " " "cat x")"'

check "root shells (Sysadmins profile) do not start help50"
run --user root "$IMAGE" bash --login -c 'test -z "${HELP50:-}" && ! declare -F _helpful > /dev/null'
else
Expand Down