From 522c7208feb4bf117c79cb58d245638c3a09b675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 14 Aug 2012 12:08:43 +0200 Subject: [PATCH] Fix shell detection Faster detection based only on BASH_VERSION/ZSH_VERSION variables. Fixes shell detection (sub shell detection broken in 7e8fc0e). Should better fail when started with an other shell than bash/zsh. --- liquidprompt | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/liquidprompt b/liquidprompt index 0db4578..ec0a896 100755 --- a/liquidprompt +++ b/liquidprompt @@ -37,17 +37,8 @@ # See the README.md file for a summary of features. -_LP_WORKING_SHELL=${SHELL##*/} - -# A login shell starts with a "-" -if [[ "$_LP_WORKING_SHELL" == "-bash" ]]; then - _LP_WORKING_SHELL="bash" -fi - -if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then - # Check for recent enough version of bash. - [[ -z "$BASH_VERSION" || -z "$PS1" || -z "$TERM" ]] && return; - +# Check for recent enough version of bash. +if test -n "$BASH_VERSION" -a -n "$PS1" -a -n "$TERM" ; then bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} if [[ $bmajor -lt 3 ]] || [[ $bmajor -eq 3 && $bminor -lt 2 ]]; then unset bash bmajor bminor @@ -55,15 +46,20 @@ if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then fi unset bash bmajor bminor + _LP_WORKING_SHELL=bash _LP_OPEN_ESC="\[" _LP_CLOSE_ESC="\]" _LP_USER_SYMBOL="\u" _LP_HOST_SYMBOL="\h" -elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then +elif test -n "$ZSH_VERSION" ; then + _LP_WORKING_SHELL=zsh _LP_OPEN_ESC="%{" _LP_CLOSE_ESC="%}" _LP_USER_SYMBOL="%n" _LP_HOST_SYMBOL="%m" +else + echo "liquidprompt: shell not supported" >&2 + return fi @@ -933,8 +929,6 @@ prompt_on() LP_OLD_PROMPT_COMMAND="$PROMPT_COMMAND" elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then LP_OLD_PROMPT_COMMAND="$precmd" - else - echo "${RED}Shell $_LP_WORKING_SHELL not supported $NO_COL" fi fi if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then