Skip to content

Commit

Permalink
Add --no-activate flag
Browse files Browse the repository at this point in the history
The trick is in getting Liquidprompt to be testable. My first attempt
kinda works, but more is needed. Liquidprompt has a lot of hacks to
check if the environment it is launched in is actually a valid
interactive shell, and bail if not. The issue is that a test environment
isn't an interactive shell, but we still need Liquidprompt to load all
its functions so we can test them.

The removal of the '$PS1' check in Bash is simply because it isn't a
good test for an interactive Bash shell. PS1 could be unset by a user,
and it could be set (pointlessly) by a script. The [[ "$-" == *i* ]]
test is much better. We tell users to use that in the docs, but it might
be a good idea to add it to our auto-starting check.

This flag when set will skip the hooking in of Liquidprompt to the
shell, so that functions will be loaded into the environment, but not
run.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent 46918f6 commit e122d21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
test -z "$TERM" -o "x$TERM" = xdumb && return

# Check for recent enough version of bash.
if test -n "${BASH_VERSION-}" -a -n "$PS1" ; then
if test -n "${BASH_VERSION-}"; then
if (( ${BASH_VERSINFO[0]:-0} < 3 || ( ${BASH_VERSINFO[0]:-0} == 3 && ${BASH_VERSINFO[1]:-0} < 2 ) )); then
echo "liquidprompt: Bash version $BASH_VERSION not supported" 2>&1
return
Expand Down Expand Up @@ -1967,6 +1967,8 @@ prompt_OFF()
}

# By default, sourcing liquidprompt will activate Liquid Prompt
prompt_on
if [ "${1-}" != "--no-activate" ]; then
prompt_on
fi

# vim: set et sts=4 sw=4 tw=120 ft=sh:
2 changes: 1 addition & 1 deletion tests/test_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function test_parameter_expansion_replace {
assertEquals "Parameter expansion replace start" cdabcd "${var/#ab}"
assertEquals "Parameter expansion replace start no match" $var "${var/#b}"

assertEquals "Parame'ter expansion replace end" abcdab "${var/%cd}"
assertEquals "Parameter expansion replace end" abcdab "${var/%cd}"
assertEquals "Parameter expansion replace end no match" $var "${var/%c}"
}

Expand Down

0 comments on commit e122d21

Please sign in to comment.