Ticket #11790: trac_11790-sage-sh.v3.patch

File trac_11790-sage-sh.v3.patch, 5.1 KB (added by John Palmieri, 11 years ago)

scripts repo

  • sage-env

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1301090570 25200
    # Node ID f500aa284b850556dfa98f4acdcd5893ab6614ef
    # Parent  828672a64b0d8a16e36525dd309a4c8a6d18753f
    #11790: clean up "sage -sh": fix some shell prompts,
    and don't print messages when calling "sage -sh -c ..."
    
    diff --git a/sage-env b/sage-env
    a b export UNAME 
    365365export CC
    366366export CFLAGS
    367367
     368# You can set environment variables in ./sage/.sagerc.  For example,
     369# setting PS1 there will set your prompt when you run "sage -sh".
     370if [ -r "$DOT_SAGE/.sagerc" ]; then
     371    source "$DOT_SAGE/.sagerc"
     372    if [ $? -ne 0 ]; then
     373        echo >&2 "Error sourcing \$DOT_SAGE/.sagerc"
     374        exit $?
     375    fi
     376fi
     377
    368378if [ 1 = 2 ]; then
    369379echo "AR=$AR"
    370380echo "AS=$AS"
  • sage-sage

    diff --git a/sage-sage b/sage-sage
    a b if [ "$1" = '-sh' -o "$1" = '--sh' ]; t 
    467467    # AUTHORS:
    468468    #   Carl Witty and William Stein: initial version
    469469    #   Craig Citro: add options for not loading profile
     470    #   Martin Albrecht: fix zshell prompt (#11866)
     471    #   John Palmieri: shorten the prompts, and don't print messages if
     472    #      there are more arguments to 'sage -sh' (#11790)
    470473    cd "$CUR"
    471474    shift
    472     echo ""
    473     echo "Starting subshell with Sage environment variables set."
    474     echo "Be sure to exit when you are done and do not do anything"
    475     echo "with other copies of Sage!"
    476     echo ""
    477     SHELL_NAME=`basename $SHELL`
    478     echo "Bypassing shell configuration files ..."
    479     echo
    480475    # We must start a new shell with no .profile or .bashrc files
    481476    # processed, so that we know our path is correct
    482     PS1="SAGE_ROOT=${SAGE_ROOT}\n(sage subshell) \h:\W \u\$ "
    483     case $SHELL_NAME in
     477    SHELL_NAME=`basename "$SHELL"`
     478    # Check for SAGE_SHPROMPT.  If defined, use for the prompt.  If
     479    # not, check for already-defined $PS1, and if defined use that.
     480    # $PS1 should only be available if it is defined in
     481    # $DOT_SAGE/.sagerc.
     482    if [ -n "$SAGE_SHPROMPT" ]; then
     483        oldPS1=$SAGE_SHPROMPT
     484    elif [ -n "$PS1" ]; then
     485        oldPS1=$PS1
     486    fi
     487    # Set the default prompt.  If available, use reverse video to
     488    # highlight the string "(sage-sh)".
     489    if [ -x /usr/bin/tput ] && tput rev >&/dev/null; then
     490        color_prompt=yes
     491    else
     492        color_prompt=
     493    fi
     494    case "$SHELL_NAME" in
    484495        bash)
    485496            SHELL_OPTS=" --norc"
     497            if [ "$color_prompt" = yes ]; then
     498                PS1="\[$(tput rev)\](sage-sh)\[$(tput sgr0)\] \u@\h:\W\$ "
     499            else
     500                PS1="(sage-sh) \u@\h:\w\$ "
     501            fi
     502            export PS1
    486503            ;;
    487504        csh)
     505            # csh doesn't seem to allow the specification of a different
     506            # .cshrc file, and the prompt can only be set in this file, so
     507            # don't bother changing the prompt.
    488508            SHELL_OPTS=" -f"
    489509            ;;
    490510        ksh)
    491511            SHELL_OPTS=" -p"
     512            if [ "$color_prompt" = yes ] ; then
     513                PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
     514            else
     515                PS1="(sage-sh) $USER@`hostname -s`:\${PWD##*/}$ "
     516            fi
     517            export PS1
    492518            ;;
    493519        sh)
    494             SHELL_OPTS=" --norc"
     520            # If sh is derived from bash, then the following is okay,
     521            # but we shouldn't assume this.
     522            #SHELL_OPTS=" --norc"
     523            if [ "$color_prompt" = yes ] ; then
     524                PS1="$(tput rev)(sage-sh)$(tput sgr0) $USER@`hostname -s`:\${PWD##*/}$ "
     525            else
     526                PS1="(sage-sh) $USER@`hostname -s`:\${PWD}$ "
     527            fi
     528            export PS1
    495529            ;;
    496530        tcsh)
     531            # tcsh doesn't seem to allow the specification of a different
     532            # .tcshrc file, and the prompt can only be set in this file, so
     533            # don't bother changing the prompt.
    497534            SHELL_OPTS=" -f"
    498535            ;;
    499536        zsh)
    500 PS1="SAGE_ROOT=${SAGE_ROOT}
    501 (sage subshell) %m:%~ %n$ "
     537            PS1="%S(sage-sh)%s %n@%m:%~$ "
    502538            SHELL_OPTS=" -f -d"
     539            export PS1
    503540            ;;
    504541        *)
    505542            echo >&2 "Unknown shell: $SHELL!"
    506             echo >&2 "Exiting Sage."
     543            echo >&2 "Aborting."
    507544            exit 1
    508545    esac
    509     export PS1
    510 
    511     $SHELL_NAME $SHELL_OPTS "$@"
    512 
    513     status=$?
    514     echo "Exited Sage subshell."
     546    if [ -n "$oldPS1" ]; then
     547        PS1="$oldPS1"
     548        export PS1
     549    fi
     550    if [ $# -eq 0 ]; then
     551        # No arguments, so print informative message...
     552        echo "" 1>&2
     553        echo "Starting subshell with Sage environment variables set." 1>&2
     554        echo "Be sure to exit when you are done and do not do anything" 1>&2
     555        echo "with other copies of Sage!" 1>&2
     556        echo "" 1>&2
     557        echo "Bypassing shell configuration files ..." 1>&2
     558        echo "" 1>&2
     559        "$SHELL" $SHELL_OPTS "$@"
     560        status=$?
     561        echo "Exited Sage subshell." 1>&2
     562    else
     563        exec "$SHELL" $SHELL_OPTS "$@"
     564        # If 'exec' returns, an error occurred:
     565        status=$?
     566        echo >&2 "Fatal error: 'exec \"$SHELL\" \"$@\"' failed!"
     567    fi
    515568    exit $status
    516569fi
    517570