Ticket #11790: 11790_sage_sh.patch

File 11790_sage_sh.patch, 4.6 KB (added by Jeroen Demeyer, 11 years ago)
  • spkg/bin/sage

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1331326341 -3600
    # Node ID 73ca3b4b745cb7d6432daea06f538ea20f9fcd5c
    # Parent  1e53642df7f2fb7c3bbb34b19cbcade8ccdc288b
    Clean up "sage --sh"
    fix some shell prompts, don't print messages when calling "sage --sh -c ..."
    
    diff --git a/spkg/bin/sage b/spkg/bin/sage
    a b  
    477477    # AUTHORS:
    478478    #   Carl Witty and William Stein: initial version
    479479    #   Craig Citro: add options for not loading profile
     480    #   Martin Albrecht: fix zshell prompt (#11866)
     481    #   John Palmieri: shorten the prompts, and don't print messages if
     482    #      there are more arguments to 'sage -sh' (#11790)
    480483    cd "$CUR"
    481484    shift
    482     echo ""
    483     echo "Starting subshell with Sage environment variables set."
    484     echo "Be sure to exit when you are done and do not do anything"
    485     echo "with other copies of Sage!"
    486     echo ""
    487     SHELL_NAME=`basename $SHELL`
    488     echo "Bypassing shell configuration files ..."
    489     echo
    490485    # We must start a new shell with no .profile or .bashrc files
    491486    # processed, so that we know our path is correct
    492     PS1="SAGE_ROOT=${SAGE_ROOT}\n(sage subshell) \h:\W \u\$ "
    493     case $SHELL_NAME in
     487    SHELL_NAME=`basename "$SHELL"`
     488    # Check for SAGE_SHPROMPT.  If defined, use for the prompt.  If
     489    # not, check for already-defined $PS1, and if defined use that.
     490    # $PS1 should only be available if it is defined in
     491    # $DOT_SAGE/.sagerc.
     492    if [ -n "$SAGE_SHPROMPT" ]; then
     493        oldPS1=$SAGE_SHPROMPT
     494    elif [ -n "$PS1" ]; then
     495        oldPS1=$PS1
     496    fi
     497    # Set the default prompt.  If available, use reverse video to
     498    # highlight the string "(sage-sh)".
     499    if [ -x /usr/bin/tput ] && tput rev >&/dev/null; then
     500        color_prompt=yes
     501    else
     502        color_prompt=
     503    fi
     504    case "$SHELL_NAME" in
    494505        bash)
    495506            SHELL_OPTS=" --norc"
     507            if [ "$color_prompt" = yes ]; then
     508                PS1="\[$(tput rev)\](sage-sh)\[$(tput sgr0)\] \u@\h:\W\$ "
     509            else
     510                PS1="(sage-sh) \u@\h:\w\$ "
     511            fi
     512            export PS1
    496513            ;;
    497514        csh)
     515            # csh doesn't seem to allow the specification of a different
     516            # .cshrc file, and the prompt can only be set in this file, so
     517            # don't bother changing the prompt.
    498518            SHELL_OPTS=" -f"
    499519            ;;
    500520        ksh)
    501521            SHELL_OPTS=" -p"
     522            if [ "$color_prompt" = yes ] ; then
     523                PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
     524            else
     525                PS1="(sage-sh) $USER@`hostname -s`:\${PWD##*/}$ "
     526            fi
     527            export PS1
    502528            ;;
    503529        sh)
    504             SHELL_OPTS=" --norc"
     530            # If sh is derived from bash, then the following is okay,
     531            # but we shouldn't assume this.
     532            #SHELL_OPTS=" --norc"
     533            if [ "$color_prompt" = yes ] ; then
     534                PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
     535            else
     536                PS1="(sage-sh) $USER@`hostname -s`:\${PWD}$ "
     537            fi
     538            export PS1
    505539            ;;
    506540        tcsh)
     541            # tcsh doesn't seem to allow the specification of a different
     542            # .tcshrc file, and the prompt can only be set in this file, so
     543            # don't bother changing the prompt.
    507544            SHELL_OPTS=" -f"
    508545            ;;
    509546        zsh)
    510 PS1="SAGE_ROOT=${SAGE_ROOT}
    511 (sage subshell) %m:%~ %n$ "
     547            PS1="%S(sage-sh)%s %n@%m:%~$ "
    512548            SHELL_OPTS=" -f -d"
     549            export PS1
    513550            ;;
    514551        *)
    515552            echo >&2 "Unknown shell: $SHELL!"
    516             echo >&2 "Exiting Sage."
     553            echo >&2 "Aborting."
    517554            exit 1
    518555    esac
    519     export PS1
    520 
    521     $SHELL_NAME $SHELL_OPTS "$@"
    522 
    523     status=$?
    524     echo "Exited Sage subshell."
     556    if [ -n "$oldPS1" ]; then
     557        PS1="$oldPS1"
     558        export PS1
     559    fi
     560    if [ $# -eq 0 ]; then
     561        # No arguments, so print informative message...
     562        echo "" 1>&2
     563        echo "Starting subshell with Sage environment variables set." 1>&2
     564        echo "Be sure to exit when you are done and do not do anything" 1>&2
     565        echo "with other copies of Sage!" 1>&2
     566        echo "" 1>&2
     567        echo "Bypassing shell configuration files ..." 1>&2
     568        echo "" 1>&2
     569        "$SHELL" $SHELL_OPTS "$@"
     570        status=$?
     571        echo "Exited Sage subshell." 1>&2
     572    else
     573        exec "$SHELL" $SHELL_OPTS "$@"
     574        # If 'exec' returns, an error occurred:
     575        status=$?
     576        echo >&2 "Fatal error: 'exec \"$SHELL\" \"$@\"' failed!"
     577    fi
    525578    exit $status
    526579fi
    527580