Skip to content

Commit

Permalink
Replace true/false with 1/0 in shell type vars
Browse files Browse the repository at this point in the history
It is actually faster to do a (( var )) check than $var expanding to
"true" or "false". But the larger reason is that it is the only variable
in the whole program checked this way.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent a35032f commit f681cdf
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ if test -n "${BASH_VERSION-}"; then
return
fi

_LP_SHELL_bash=true
_LP_SHELL_zsh=false
_LP_SHELL_bash=1
_LP_SHELL_zsh=0
_LP_OPEN_ESC="\["
_LP_CLOSE_ESC="\]"

Expand All @@ -59,8 +59,8 @@ if test -n "${BASH_VERSION-}"; then
ret="${1//\\/\\\\}"
}
elif test -n "${ZSH_VERSION-}" ; then
_LP_SHELL_bash=false
_LP_SHELL_zsh=true
_LP_SHELL_bash=0
_LP_SHELL_zsh=1
_LP_OPEN_ESC="%{"
_LP_CLOSE_ESC="%}"

Expand Down Expand Up @@ -360,7 +360,7 @@ __lp_source_config() {
if [[ -n "${LP_DISABLED_VCS_PATH-}" ]]; then
echo "liquidprompt: LP_DISABLED_VCS_PATH is deprecated. Update your config to use LP_DISABLED_VCS_PATHS array." >&2

$_LP_SHELL_zsh && setopt local_options && setopt sh_word_split
(( _LP_SHELL_zsh )) && setopt local_options && setopt sh_word_split
local path IFS=:
for path in $LP_DISABLED_VCS_PATH; do
LP_DISABLED_VCS_PATHS+=("$path")
Expand Down Expand Up @@ -388,7 +388,7 @@ __lp_source_config() {
}

lp_activate() {
if $_LP_SHELL_bash; then
if (( _LP_SHELL_bash )); then
# Disable the DEBUG trap used by the RUNTIME feature
# (in case we are reloading LP in the same shell after disabling
# the feature in .liquidpromptrc)
Expand Down Expand Up @@ -507,7 +507,7 @@ lp_activate() {
# Will never change
lp_path=$LP_PATH_DEFAULT

if $_LP_SHELL_bash && [[ -n ${PROMPT_DIRTRIM-} ]]; then
if (( _LP_SHELL_bash )) && [[ -n ${PROMPT_DIRTRIM-} ]]; then
__lp_path() {
__lp_set_dirtrim
}
Expand All @@ -519,7 +519,7 @@ lp_activate() {
_LP_RUNTIME_LAST_SECONDS=$SECONDS

if (( LP_ENABLE_RUNTIME || LP_ENABLE_RUNTIME_BELL)); then
if $_LP_SHELL_zsh; then
if (( _LP_SHELL_zsh )); then
add-zsh-hook preexec __lp_runtime_before
add-zsh-hook precmd __lp_runtime_after
else
Expand Down Expand Up @@ -1959,7 +1959,7 @@ _lp_runtime_format() {
fi
}

if $_LP_SHELL_zsh; then
if (( _LP_SHELL_zsh )); then
__lp_runtime_before() {
_LP_RUNTIME_LAST_SECONDS=$SECONDS
}
Expand Down Expand Up @@ -2424,7 +2424,7 @@ prompt_on() {
# if Liquid Prompt has not been already set
if [[ -z "${LP_OLD_PS1-}" ]]; then
LP_OLD_PS1="$PS1"
if $_LP_SHELL_bash; then
if (( _LP_SHELL_bash )); then
LP_OLD_PROMPT_COMMAND="${PROMPT_COMMAND-}"
_LP_OLD_SHOPT="$(shopt -p promptvars)"
else # zsh
Expand All @@ -2447,7 +2447,7 @@ prompt_on() {
done
fi
fi
if $_LP_SHELL_bash; then
if (( _LP_SHELL_bash )); then
# Prevent some cases where the user shoots in his own foot.
# PROMPT_COMMAND is not exported by default, but some users
# incorrectly export it from their profile/bashrc (GitHub #450),
Expand Down Expand Up @@ -2484,7 +2484,7 @@ prompt_on() {
# Come back to the old prompt
prompt_off() {
PS1=$LP_OLD_PS1
if $_LP_SHELL_bash; then
if (( _LP_SHELL_bash )); then
eval "$_LP_OLD_SHOPT"
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
else # zsh
Expand All @@ -2497,7 +2497,7 @@ prompt_off() {
# Use an empty prompt: just the \$ mark
prompt_OFF() {
PS1="$_LP_MARK_SYMBOL "
if $_LP_SHELL_bash; then
if (( _LP_SHELL_bash )); then
shopt -u promptvars
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
else # zsh
Expand Down

0 comments on commit f681cdf

Please sign in to comment.