Ticket #11790: 11790_review.patch

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

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1331328263 -3600
    # Node ID 057f9ed67c0fcdc4e73d5a39971096e6921ff525
    # Parent  d9ad27b20a8ffb90fd15820f72de219201652a67
    Reviewer patch for sage --sh
    
    diff --git a/spkg/bin/sage b/spkg/bin/sage
    a b  
    475475
    476476if [ "$1" = '-sh'  -o "$1" = '--sh' ]; then
    477477    # AUTHORS:
    478     #   Carl Witty and William Stein: initial version
    479     #   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)
     478    # - Carl Witty and William Stein: initial version
     479    # - 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)
    483483    cd "$CUR"
    484484    shift
     485    # If $SHELL is unset, default to bash
     486    if [ -z "$SHELL" ]; then
     487        export SHELL=bash
     488    fi
    485489    # We must start a new shell with no .profile or .bashrc files
    486490    # processed, so that we know our path is correct
    487491    SHELL_NAME=`basename "$SHELL"`
    488492    # Check for SAGE_SHPROMPT.  If defined, use for the prompt.  If
    489493    # not, check for already-defined $PS1, and if defined use that.
    490494    # $PS1 should only be available if it is defined in
    491     # $DOT_SAGE/.sagerc.
     495    # $DOT_SAGE/sagerc.
    492496    if [ -n "$SAGE_SHPROMPT" ]; then
    493497        oldPS1=$SAGE_SHPROMPT
    494498    elif [ -n "$PS1" ]; then
     
    496500    fi
    497501    # Set the default prompt.  If available, use reverse video to
    498502    # highlight the string "(sage-sh)".
    499     if [ -x /usr/bin/tput ] && tput rev >&/dev/null; then
     503    if tput rev &>/dev/null; then
    500504        color_prompt=yes
    501     else
    502         color_prompt=
    503505    fi
    504506    case "$SHELL_NAME" in
    505507        bash)
    506             SHELL_OPTS=" --norc"
     508            SHELL_OPTS="--norc"
    507509            if [ "$color_prompt" = yes ]; then
    508510                PS1="\[$(tput rev)\](sage-sh)\[$(tput sgr0)\] \u@\h:\W\$ "
    509511            else
     
    515517            # csh doesn't seem to allow the specification of a different
    516518            # .cshrc file, and the prompt can only be set in this file, so
    517519            # don't bother changing the prompt.
    518             SHELL_OPTS=" -f"
     520            SHELL_OPTS="-f"
    519521            ;;
    520522        ksh)
    521             SHELL_OPTS=" -p"
     523            SHELL_OPTS="-p"
    522524            if [ "$color_prompt" = yes ] ; then
    523525                PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
    524526            else
     
    527529            export PS1
    528530            ;;
    529531        sh)
    530             # If sh is derived from bash, then the following is okay,
    531             # but we shouldn't assume this.
    532             #SHELL_OPTS=" --norc"
     532            # We don't really know which shell "sh" is (it could be
     533            # bash, but this is not guaranteed), so we don't set
     534            # SHELL_OPTS.
    533535            if [ "$color_prompt" = yes ] ; then
    534536                PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
    535537            else
     
    541543            # tcsh doesn't seem to allow the specification of a different
    542544            # .tcshrc file, and the prompt can only be set in this file, so
    543545            # don't bother changing the prompt.
    544             SHELL_OPTS=" -f"
     546            SHELL_OPTS="-f"
    545547            ;;
    546548        zsh)
    547549            PS1="%S(sage-sh)%s %n@%m:%~$ "
    548             SHELL_OPTS=" -f -d"
     550            SHELL_OPTS="-f -d"
    549551            export PS1
    550552            ;;
    551553        *)
    552             echo >&2 "Unknown shell: $SHELL!"
    553             echo >&2 "Aborting."
    554             exit 1
     554            export PS1='(sage-sh) $ '
     555            ;;
    555556    esac
    556557    if [ -n "$oldPS1" ]; then
    557558        PS1="$oldPS1"
     
    564565        echo "Be sure to exit when you are done and do not do anything" 1>&2
    565566        echo "with other copies of Sage!" 1>&2
    566567        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
     568        if [ -n "$SHELL_OPTS" ]; then
     569            echo "Bypassing shell configuration files ..." 1>&2
     570            echo "" 1>&2
     571        fi
     572        "$SHELL" $SHELL_OPTS "$@"
     573        status=$?
     574        echo "Exited Sage subshell." 1>&2
    572575    else
    573576        exec "$SHELL" $SHELL_OPTS "$@"
    574577        # If 'exec' returns, an error occurred: