Ticket #11790: trac_11790-sage-sh.patch

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

scripts repo

  • sage-sage

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1301090570 25200
    # Node ID c9433e01d7bf169c6a8c0c36389456c8ba512834
    # Parent  c72bcd4b708a65b59507729071011236ee751e71
    #11790: clean up "sage -sh": fix some shell prompts,
    and don't print messages when calling "sage -sh -c ..."
    
    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: fix some more prompts, and don't print messages if
     472    #      '-c' is the first argument 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
     475    if [ "$1" = '-c' ]; then
     476        exec $SHELL "$@"
     477        # If 'exec' returns, an error occurred:
     478        status=$?
     479        echo >&2 "Fatal error: 'exec \"$SHELL\" \"$@\"' failed!"
     480        exit $status # Always non-zero, but return the code the shell gave.
     481    fi
     482    # -c is not the first option, so print informative messages...
     483    echo "" 1>&2
     484    echo "Starting subshell with Sage environment variables set." 1>&2
     485    echo "Be sure to exit when you are done and do not do anything" 1>&2
     486    echo "with other copies of Sage!" 1>&2
     487    echo "" 1>&2
     488    echo "Bypassing shell configuration files ..." 1>&2
     489    echo "" 1>&2
    480490    # We must start a new shell with no .profile or .bashrc files
    481491    # processed, so that we know our path is correct
    482     PS1="SAGE_ROOT=${SAGE_ROOT}\n(sage subshell) \h:\W \u\$ "
     492    SHELL_NAME=`basename $SHELL`
    483493    case $SHELL_NAME in
    484494        bash)
    485495            SHELL_OPTS=" --norc"
     496            PS1="SAGE_ROOT=${SAGE_ROOT}\n(sage subshell) \h:\W \u\$ "
     497            export PS1
    486498            ;;
    487499        csh)
     500            # csh doesn't seem to allow the specification of a different
     501            # .cshrc file, and the prompt can only be set in this file, so
     502            # don't bother changing the prompt.
    488503            SHELL_OPTS=" -f"
    489504            ;;
    490505        ksh)
    491506            SHELL_OPTS=" -p"
     507            PS1="SAGE_ROOT=${SAGE_ROOT}
     508(sage subshell) `hostname -s`:\${PWD##*/} $USER$ "
     509            export PS1
    492510            ;;
    493511        sh)
    494512            SHELL_OPTS=" --norc"
     513            PS1="SAGE_ROOT=${SAGE_ROOT}
     514(sage subshell) `hostname -s`:\${PWD##*/} $USER$ "
     515            export PS1
    495516            ;;
    496517        tcsh)
     518            # tcsh doesn't seem to allow the specification of a different
     519            # .tcshrc file, and the prompt can only be set in this file, so
     520            # don't bother changing the prompt.
    497521            SHELL_OPTS=" -f"
    498522            ;;
    499523        zsh)
    500524PS1="SAGE_ROOT=${SAGE_ROOT}
    501525(sage subshell) %m:%~ %n$ "
    502526            SHELL_OPTS=" -f -d"
     527            export PS1
    503528            ;;
    504529        *)
    505530            echo >&2 "Unknown shell: $SHELL!"
    506             echo >&2 "Exiting Sage."
     531            echo >&2 "Aborting."
    507532            exit 1
    508533    esac
    509     export PS1
    510 
    511     $SHELL_NAME $SHELL_OPTS "$@"
    512 
     534    $SHELL $SHELL_OPTS "$@"
    513535    status=$?
    514     echo "Exited Sage subshell."
     536    echo "Exited Sage subshell." 1>&2
    515537    exit $status
    516538fi
    517539