Skip to content

Commit

Permalink
Add $- ~= i check as well as --no-activate override
Browse files Browse the repository at this point in the history
While the $TERM checks might be antiquated, $TERM needs to be set for
our color formatting to work, so they are still safe. Add the $- check
here too, just in case. This should make loading Liquidprompt for tests
quite safe.

This whole line should be super POSIX safe. This is because we need to
quietly exit without error if Liquidprompt is loaded in a
non-interactive shell, even ones that aren't supported by the rest of
Liquidprompt.

The "x" prefixes on the vars are probably not needed, but some older
shells might interpret a "-f" or similar as a flag to the "test" or "["
command instead of a string to compare. This ugly fix prevents that from
happening.

Also add the "${TERM-}" format so that if $TERM is not set while
running under 'set -u', we can exit quietly instead of crash.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent a4aa823 commit f2276fc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
# See the README.md file for a summary of features.

# Issue #161: do not load if not an interactive shell
test -z "$TERM" -o "x$TERM" = xdumb && return
# Do not exit if '--no-activate' flag was passed, as it overrides this check
[ "x${-##*i}" = "x$-" ] || [ -z "${TERM-}" ] || [ "x${TERM-}" = xdumb ] && [ "x${1-}" != "x--no-activate" ] && return

if test -n "${BASH_VERSION-}"; then
# Check for recent enough version of bash.
Expand Down

0 comments on commit f2276fc

Please sign in to comment.