Open vbraun opened 10 years ago
Branch: u/vbraun/pimp_my_shell
Commit: 2678e8d
Branch pushed to git repo; I updated commit sha1. New commits:
2678e8d | also display staged as red |
Author: Volker Braun
Description changed:
---
+++
@@ -1 +1 @@
-
+This patch reorganizes the "sage -sh" shell. If you are using bash, it also introduces a PS1 that includes git branch status. This can be very useful for beginners to keep an eye on the repository status.
Description changed:
---
+++
@@ -1 +1,13 @@
This patch reorganizes the "sage -sh" shell. If you are using bash, it also introduces a PS1 that includes git branch status. This can be very useful for beginners to keep an eye on the repository status.
+
+```
+Sage: desktop 02:53:17 {t/15590/pimp_my_shell|modified} ~/Sage/git
+$ git add .
+Sage: desktop 02:53:20 {t/15590/pimp_my_shell|staged} ~/Sage/git
+$ git commit -m 'also display staged as red'
+[t/15590/pimp_my_shell 2678e8d] also display staged as red
+ 1 file changed, 36 insertions(+), 30 deletions(-)
+Sage: desktop 02:53:35 (t/15590/pimp_my_shell) ~/Sage/git
+$ git st
+```
+but with colors.
Branch pushed to git repo; I updated commit sha1. New commits:
f2b46b4 | support for old git versions |
This is not working for me on OS X. On one machine, $SHELL
is set to /bin/bash
but I don't get an interesting prompt: I just get bash-3.2$
. As far as I can tell, this is not loading my .bashrc
file (I put an echo command in there to see, and nothing is printed). So I don't think it's loading src/ext/shell/bashrc
, either. On another OS X machine, it's running bash but $SHELL
is set to /bin/sh
. I tried making the following changes, but it didn't help: the prompt remained sh-3.2$
.
diff --git a/src/bin/sage b/src/bin/sage
index c01fea2..8770a57 100755
--- a/src/bin/sage
+++ b/src/bin/sage
@@ -278,6 +278,21 @@ if [ "$1" = '-sh' -o "$1" = '--sh' ]; then
export ZDOTDIR="$SAGE_EXTCODE/shell"
set -- "$SHELL" -d "$@"
;;
+ sh)
+ # see http://stackoverflow.com/a/3327022/1401572
+ if [ -n $BASH ]; then
+ set -- "$SHELL" --rcfile "$SAGE_EXTCODE/shell/bashrc" "$@"
+ elif [ -n $ZSH_NAME ]; then
+ export ZDOTDIR="$SAGE_EXTCODE/shell"
+ set -- "$SHELL" -d "$@"
+ elif [ -n $KSH_VERSION ]; then
+ export ENV="$SAGE_EXTCODE/shell/kshrc"
+ set -- "$SHELL" "$@"
+ else
+ source "$_SAGE_ENV_SCRIPT"
+ set -- "$SHELL" "$@"
+ fi
+ ;;
*)
# We don't know how to specify alternate startup file, you are on your own
source "$_SAGE_ENV_SCRIPT"
(I added some echo commands here, too, and it is entering the appropriate case, the sh
case with $BASH
set.)
Branch pushed to git repo; I updated commit sha1. New commits:
1a8fefc | workaround for lack of "echo -e" on OSX |
You need to rebuild sage (run "make"), because the scripts are loaded from SAGE_ROOT/local/share/sage/ext/shell
and not from SAGE_ROOT/src/ext/shell
.
I think if $SHELL
is not set to bash then you either explicitly don't want bash features used or your OS is old/weird and its doubtful that bash works as it should. Where did you see the SHELL=/bin/sh
environment?
While trying this out I noticed that OSX doesn't support echo -e
to expand \e
, this is now also fixed.
I saw SHELL=/bin/sh
on one OS X 10.8 machine. It may have to do with how the sysadmins have set up that machine, but that's my shell there. I've also seen some references to this happening on other systems, for example in the stackoverflow answer I cited in my patch. (See also http://stackoverflow.com/q/5166657/1401572, and I'm sure I saw it other places.)
I'm trying again with the new version. Currently running make
, which is taking a little while...
Branch pushed to git repo; I updated commit sha1. New commits:
fb5b848 | more workarounds for weird $SHELL, OSX ksh |
On a machine with SHELL=/bin/bash
, it works well. On the machine with SHELL=/bin/sh
, it is entering the appropriate case ("bash)
"), but the bashrc file in local/share/sage/ext/shell
is not loaded. If I replace "$SHELL"
with `command -v bash`
, it is loaded — this is in the line
set -- "$SHELL" --rcfile "$SAGE_EXTCODE/shell/bashrc" "$@"
In this case, it works, but not perfectly: the prompt comes out as
\033]0;palmieri@jpalmieri: ~/Desktop/Sage_stuff/git/sage\007\c
Sage: jpalmieri 12:11:42 {new_shell|modified} ~/Desktop/Sage_stuff/git/sage
$
with the middle line appropriately colored. (On the first machine, the prompt looks better: it doesn't include the first line. It's running a slightly newer version of bash, 3.2.51 instead of 3.2.48; it's also running OS X 10.9 instead of 10.8, and as mentioned, it has SHELL=/bin/bash
.)
It may be that there is no good way to deal with bash
if it is run as /bin/sh
, I don't know. A different question, though: if I don't like the bash prompt defined like this, can I override it? Should we load $DOT_SAGE/bashrc
or some similarly named file at the end of local/share/sage/ext/shell/bashrc
?
You don't have to use the sage shell at all. I never use it. But imho we should offer something nice for those that don't want to customize their own shell prompt.
But to be on the safe side I think we should just fall back to something safe if SHELL is not set to /bin/bash.
Branch pushed to git repo; I updated commit sha1. New commits:
232ef94 | no guessing what SHELL is |
Replying to @vbraun:
You don't have to use the sage shell at all. I never use it. But imho we should offer something nice for those that don't want to customize their own shell prompt.
My point is that in my .bashrc file, I've already customized my shell prompt for use with sage -sh
, and these changes override my customizations. It seems bad to force a choice of prompt on users. (I'm talking about the machines where SHELL=/bin/bash
, by the way.)
New commits:
232ef94 | no guessing what SHELL is |
Thats what I'm talking about, if you like the way you have set up your shell then just don't use the Sage shell. This ticket doesn't change the fact that the Sage shell overrides the prompt, it just overrides it with a nicer prompt. I dont' see a reliable way to figure out if the prompt has already been changed away from the default, there are many different "defaults" that distros set up.
Sometimes if I'm trying to debug on spkg, I want to go to local/var/tmp/sage/build/...
and then run make
or configure
or whatever, and it's convenient to be running the Sage shell before doing this. That is, sage -sh
is a useful tool. I don't want to be dissuaded from using it because I dislike the new prompt. So why not put something like this at the bottom of the proposed Sage bashrc file:
if [ -f "$DOT_SAGE/bashrc" ]; then
. "$DOT_SAGE/bashrc"
fi
Branch pushed to git repo; I updated commit sha1. New commits:
d1f9154 | hook to supply a user DOT_SAGE/bashrc |
Sounds good to me...
I use a much shorter function in my zshrc to set up the git status, the
idea being that the shell should be fast in initialization and in returning
the prompt. So, the only command that is run is git status
and everything
else is gleaned from that using shell operations. Also, I use RPROMPT
so
that the left prompt is short. The RPROMPT
disappears automatically once
the user starts typing too long commands.
function __check_git__() {
local _s="$( git status 2>&1 )"
[[ "${_s}" = "fatal:"* ]] && echo "" && return
_s="$( echo "${_s}" | sed -e '/^#.*modified:.*(untracked content)$/d' )"
local _g_s="$( echo "$_s" | sed -n -e '1s@^On branch @@p;q' )"
if [[ "$_s" = *modified:* || \
"$_s" = *"new file:"* || \
"$_s" = *"Your branch is behind"* || \
"$_s" = *deleted:* || \
"$_s" = *renamed:* \
]]; then
echo "[%20>...>%{$fg[red]%}$_g_s%{$fg[white]%}%>>]"
elif [[ -n "$_g_s" ]]; then
echo "[%20>...>%{$fg[green]%}$_g_s%{$fg[white]%}%>>]"
else
echo "%{$fg[yellow]%}[?]%{$fg[white]%}"
fi
}
RPROMPT="%{$fg[white]%}•$(__check_git__)%{$fg[cyan]%}%n%{$fg[white]%}|%{$fg[green]%}%m%{$reset_color%}"
Work Issues: merge conflicts
Changed branch from u/vbraun/pimp_my_shell to u/jhpalmieri/pimp_my_shell
Changed work issues from merge conflicts to none
Somehow, I do not get colors here but only an inverted prompt. It seems that tput colors
does not return 0 whereas tput rev
does. That is strange since tput colors
does return 0 if I invoke it manually. I have not had a chance to debug this further. The changes seem fine to me and I think they could be a positive review even if it does not work for me (maybe my setup is just somehow screwed up.)
This still is set as open for review. Is it so?
I don't think I will work on it, but feel free to take a look if it interests you. If it looks worthwhile, maybe it will revive my interest.
It definitely looks neat. Is there any serious problem remaining on this, or just bikeshedding about how to support every shell under the sun?
No one has touched it in 3 years, but I think it was in okay shape then. It might be better to do this one shell at a time, letting people who actually use ksh
, zsh
, etc., implement and test. I don't care that much about it, in any case.
The naming scheme looks inconsistent:
src/ext/shell/.zshrc
src/ext/shell/bashrc
src/ext/shell/kshrc
Any reason for it?
As to zsh, it is coming in macos 10.15, so it's getting more users soon...
Replying to @dimpase:
The naming scheme looks inconsistent:
src/ext/shell/.zshrc src/ext/shell/bashrc src/ext/shell/kshrc
Any reason for it?
It was like 5 years ago. I have no idea.
As to zsh, it is coming in macos 10.15, so it's getting more users soon...
I rather like my PS1 the way it is; this should be optional at a minimum.
Ultimately I don't think we should be adding more internet bling bling into the sagemath codebase at this point. Anyone who wants this can enable it himself by following e.g.
https://git-scm.com/book/uz/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash
which is "trivial" to do and works in zsh as well.
This patch reorganizes the "sage -sh" shell. If you are using bash, it also introduces a PS1 that includes git branch status. This can be very useful for beginners to keep an eye on the repository status.
but with colors.
CC: @novoselt @videlec @orlitzky
Component: scripts
Author: Volker Braun
Branch/Commit: u/jhpalmieri/pimp_my_shell @
58fa20d
Issue created by migration from https://trac.sagemath.org/ticket/15590