Re: extra-prompt.sh

2007-07-29 Thread taipan67
Bruce Dubbs wrote:
 David Jensen wrote:
   
 Moving to dev. 
 

   
 Ag. D. Hatzimanikas wrote:
 
 Does this prompt (in /etc/profile) looks good to you? (it was suggested by 
 David Jensen)

 if [[ ${EUID} == 0 ]] ; then
 PS1='\[\e[1;31m\]\u [ \[\e[00m\]\w \[\e[1;31m\]]\$ \[\e[00m\]'
 else
 PS1='\[\e[1;32m\]\u [ \[\e[00m\]\w \[\e[1;32m\]]\$ \[\e[00m\]'
 fi
   

 This is too cryptic.  Use:

 NORMAL=\[\033[0;39m\]
 RED=\[\033[1;31m\]
 GREEN=\[\033[1;32m\]

 if [[ ${EUID} == 0 ]] ; then
   PS1=$RED\u [ $NORMAL\w$RED ]\$ $NORMAL
 else
   PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
 fi

   -- Bruce
   
I've also stolen coloured PS1 values from my current Gentoo-box,  they 
use the '\033' escape-sequence listed above, but in full, not through 
variable-names. They also define 'normal' as \[\033[00m\] (not sure of 
the difference).

However, Gentoo define them in /etc/bashrc,  have the line . 
/etc/bashrc (that's 'full-stop' 'space' 'filename') in /etc/profile, 
instead of a PS1 declaration. I found this to be necessary when booting 
into my LFS system. I also have a third colour defined for 
package-users, but that had to go in the pkgusr ~/.bashrc to work, 
presumably because they never boot the system, they are only su'd to by 
root.

There are additional pre-checks for the existence of /etc/dircolors  
that the terminal in use supports colour. For future builds, it's my 
intention to incorporate this into my base LFS-build, as dircolors is 
installed by coreutils fairly early in both chapters 5  6 - i haven't 
worked out the details yet...

taipan

-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


Re: extra-prompt.sh

2007-07-29 Thread Bruce Dubbs
David Jensen wrote:
 taipan67 wrote:
 if [[ ${EUID} == 0 ]] ; then
   PS1='\[\e[1;31m\]\u [ \[\e[00m\]\w \[\e[1;31m\]]\$ \[\e[00m\]'
 else
   PS1='\[\e[1;32m\]\u [ \[\e[00m\]\w \[\e[1;32m\]]\$ \[\e[00m\]'
 fi
   
 
 This is too cryptic.  Use:

 NORMAL=\[\033[0;39m\]
 RED=\[\033[1;31m\]
 GREEN=\[\033[1;32m\]
 
 I don't see \033 as preferable to \e, otherwise it looks OK.
 Perhaps the bold/bright, '1' could be dropped, most others likely don't 
 use a white on black xterm as I do.
 
 thus:
 NORMAL=\[\e[0m\]
 RED=\[\e[31m\]
 GREEN=\[\e[32m\]
 
 Maybe single quotes, though there is nothing, as is, that bash will mangle.

The single quote acts differently.  From the man page:

Enclosing  characters  in single quotes preserves the literal value of
each character within the quotes.  A single quote may not occur between
single  quotes,  even  when preceded by a backslash.

Enclosing  characters  in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, and \.

In this case, using single quotes may not be a problem because the
backslashes will then be interpreted when PS1 is evaluated.

 Does anyone know why the escaped bracketing is required, it is.
 It seems \e[1;31m should work but the cursor position and scrolling 
 get fouled.

The bash man page again has the answer.  Under PROMPTING:

  \[  begin  a  sequence  of  non-printing characters, which could
   be used toembed a terminal control sequence into the prompt
   \]  end a sequence of non-printing characters

I believe this is needed to tell bash not to count these characters when
determining when to wrap a line.

 snip They also define 'normal' as \[\033[00m\] (not sure of 
 the difference).

 This seems incorrect to me, 00m is default mode, not a color.  It does 
 however, set the default color and attribute.  Either '\e[00m' or 
 '\e[0;39m'  seem correct.

The sequence \e[m could also be used.  The usual sequence I've seen is
\e[00m. I believe \e[0;39m would only reset the foreground color and
not the background color.

 Reviewing this thread 
 http://linuxfromscratch.org/pipermail/blfs-dev/2007-March/016818.html
 it seems PS1 should not be exported, no decision was reached

It should not be exported because it does no good.  PS1 is reset for
each invocation.  From the bash man page:

An  interactive  shell is one started without non-option arguments and
without the -c option whose standard input and error are both connected
to terminals (as  determined by  isatty(3)),  or  one started with the
-i option.  PS1 is set and $- includes i if bash is interactive,
allowing a shell script or a startup file to test this state.

  -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


Re: extra-prompt.sh

2007-07-29 Thread Serge van Thillo

On Sun, 2007-07-29 at 09:58 -0500, Bruce Dubbs wrote:
 taipan67 wrote:
  Bruce Dubbs wrote:
  David Jensen wrote:
 
  NORMAL=\[\033[0;39m\]
  RED=\[\033[1;31m\]
  GREEN=\[\033[1;32m\]
 
  if [[ ${EUID} == 0 ]] ; then
PS1=$RED\u [ $NORMAL\w$RED ]\$ $NORMAL
  else
PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
  fi
 
-- Bruce

  I've also stolen coloured PS1 values from my current Gentoo-box,  they 
  use the '\033' escape-sequence listed above, but in full, not through 
  variable-names. They also define 'normal' as \[\033[00m\] (not sure of 
  the difference).
 
I prefer to use vi to enter the escape sequence, I am using
LC_ALL=en_US.UTF-8 as locate definition. When I use the \033 or \e the
positioning of the cursor isn't right, when I use the (CTRL-H esc) in
vi, everything is ok.

Serge

-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


Re: extra-prompt.sh

2007-07-29 Thread David Jensen
Bruce Dubbs wrote:
much snipped!
 Reviewing this thread 
 http://linuxfromscratch.org/pipermail/blfs-dev/2007-March/016818.html
 it seems PS1 should not be exported, no decision was reached
 

 It should not be exported because it does no good.  PS1 is reset for
 each invocation.  From the bash man page:

 An  interactive  shell is one started without non-option arguments and
 without the -c option whose standard input and error are both connected
 to terminals (as  determined by  isatty(3)),  or  one started with the
 -i option.  PS1 is set and $- includes i if bash is interactive,
 allowing a shell script or a startup file to test this state.

   
Thanks Bruce.


I suggest.
1).
Lose /etc/extra-prompt.sh.
2).
Lose export for PS1.
3).
Use:

NORMAL=\[\e[0m\]
RED=\[\e[1;31m\]
GREEN=\[\e[1;32m\]
if [[ ${EUID} == 0 ]] ; then
  PS1=$RED\u [ $NORMAL\w$RED ]# $NORMAL
else
  PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
fi

---
David Jensen


-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


[Diff] profile.xml. [Was: Re: extra-prompt.sh]

2007-07-29 Thread Ag. D. Hatzimanikas
On Sun, Jul 29, at 01:56 David Jensen wrote:
 
 I suggest.
 1).
 Lose /etc/extra-prompt.sh.
 2).
 Lose export for PS1.
 3).
 Use:
 
 NORMAL=\[\e[0m\]
 RED=\[\e[1;31m\]
 GREEN=\[\e[1;32m\]
 if [[ ${EUID} == 0 ]] ; then
   PS1=$RED\u [ $NORMAL\w$RED ]# $NORMAL
 else
   PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
 fi
 

Thanks a lot David,

Attached is a diff with your suggestions.

With this chance, I also updated the X.sh script (/X11R6/X11R7).

Please review it and as always suggestions are welcomed.

--
Ag
Index: postlfs/config/profile.xml
===
--- postlfs/config/profile.xml  (revision 6988)
+++ postlfs/config/profile.xml  (working copy)
@@ -140,9 +140,17 @@
 # Setup some environment variables.
 export HISTSIZE=1000
 export HISTIGNORE=amp;:[bf]g:exit
-#export PS1=[EMAIL PROTECTED] \w]\\$ 
-export PS1='[EMAIL PROTECTED]:\w\$ '
 
+# Setup a red prompt for root and a green one for users. 
+NORMAL=\[\e[0m\]
+RED=\[\e[1;31m\]
+GREEN=\[\e[1;32m\]
+if [[ $EUID == 0 ]] ; then
+  PS1=$RED\u [ $NORMAL\w$RED ]# $NORMAL
+else
+  PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
+fi
+
 for script in /etc/profile.d/*.sh ; do
 if [ -r $script ] ; then
 . $script
@@ -281,47 +289,28 @@
 primary sortas=e-etc-profile.d-X.sh/etc/profile.d/X.sh/primary
   /indexterm
 
-  paraIf applicationX/application is installed, the 
envarPATH/envar
-  and envarPKG_CONFIG_PATH/envar variables are also updated./para
+  paraIf applicationX/application is installed in
+  filename class=directory/usr/X11R7/filename directory, the
+  envarPATH/envar and envarPKG_CONFIG_PATH/envar variables are also
+  updated. emphasisNote/emphasis: Consult the xref linkend=xorg7/ 
or
+  the xref linkend=xfree86/ pages of the Book, and substitute 
/usr/X11R7
+  with the choosen envarXORG_PREFIX/envar for 
applicationXorg/application,
+  and the envarProjectRoot/envar in the case of 
applicationXFree86/application.
+  /para
 
 screen role=rootuserinputcat gt; /etc/profile.d/X.sh lt;lt; EOF
-literalif [ -x /usr/X11R6/bin/X ]; then
-pathappend /usr/X11R6/bin
+literalif [ -x /usr/X11R7/bin/X ]; then
+pathappend /usr/X11R7/bin
 fi
-if [ -d /usr/X11R6/lib/pkgconfig ] ; then
-pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
+if [ -d /usr/X11R7/lib/pkgconfig ] ; then
+pathappend /usr/X11R7/lib/pkgconfig PKG_CONFIG_PATH
 fi/literal
 EOF/userinput/screen
 
 /sect3
 
-sect3 id=extra-prompt.sh
-  title/etc/profile.d/extra-prompt.sh/title
-
-  indexterm zone=postlfs-config-profile extra-prompt.sh
-primary 
sortas=e-etc-profile.d-prompt.sh/etc/profile.d/extra-prompt.sh/primary
-  /indexterm
-
-  paraThis script shows an example of a different way of setting the
-  prompt.  The normal variable, envarPS1/envar, is supplemented by
-  envarPROMPT_COMMAND/envar. If set, the value of
-  envarPROMPT_COMMAND/envar is executed as a command prior to issuing
-  each primary prompt.  The sequence \e is an ESC character.  \a is a
-  BEL character.  For a reference on commandxterm/command escape
-  sequences, see ulink
-  url=http://rtfm.etla.org/xterm/ctlseq.html/./para
-
-screen role=rootuserinputcat gt; /etc/profile.d/extra-prompt.sh 
lt;lt; EOF
-literalPROMPT_COMMAND='echo -ne [EMAIL PROTECTED] : ${PWD}\e[0m\a'
-export PROMPT_COMMAND/literal
-EOF/userinput/screen
-
-paraThe escape sequences above are BOLD, NORMAL, and BEL./para
-
-/sect3
-
 sect3 id=i18n.sh
-  title'/etc/profile.d/i18n.sh'/title
+  title/etc/profile.d/i18n.sh/title
 
 indexterm zone=postlfs-config-profile i18n.sh
   primary 
sortas=e-etc-profile.d-i18n.sh/etc/profile.d/i18n.sh/primary
@@ -384,8 +373,14 @@
 # PS1 Environment Variable for a great case study behind this script
 # addendum.]
 
-#export PS1=[EMAIL PROTECTED] \w]\\$ 
-export PS1='[EMAIL PROTECTED]:\w\$ '
+NORMAL=\[\e[0m\]
+RED=\[\e[1;31m\]
+GREEN=\[\e[1;32m\]
+if [[ $EUID == 0 ]] ; then
+  PS1=$RED\u [ $NORMAL\w$RED ]# $NORMAL
+else
+  PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
+fi
 
 # End /etc/bashrc/literal
 EOF/userinput/screen
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Re: [Diff] profile.xml. [Was: Re: extra-prompt.sh]

2007-07-29 Thread David Jensen
Ag. D. Hatzimanikas wrote:


 Thanks a lot David,

 Attached is a diff with your suggestions.

 With this chance, I also updated the X.sh script (/X11R6/X11R7).
   
I was not aware we were making this change.  It works for me, /usr/X11R7 
is what I use.  We should put it to discussion?  Personally +1, but the 
xorg default instructions should match.

 Please review it and as always suggestions are welcomed.

   
OK here.

---
David Jensen

-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


Re: extra-prompt.sh

2007-07-28 Thread David Jensen
Moving to dev.

Ag. D. Hatzimanikas wrote:
 On Fri, Jul 27, at 09:07 Craig Jackson wrote:
   
 Hello,

 In BLFS-6.2, Chapter 3 - The Bash Startup Files, the
 /etc/profile.d/extra-prompt.sh provides interesting results.  I must
 have had this problem a dozen times now, and since it is a simple fix
 haven't reported it until now.  As written, if the user follows the
 entire instructions on the page to the letter, the following prompt is
 produced:

 @viper : /[EMAIL PROTECTED]:/#

 As soon as /etc/profile.d/extra-prompt.sh is removed, the prompt looks
 much more readable and reasonable:

 [EMAIL PROTECTED]:/#

 I looked hard for any warnings about this.  I'm wondering what the
 true purpose of the extra-prompt.sh script is.  I'm a big fan of a
 colorful but simple prompt, but this one seems broken in the way it is
 implemented.

 

 To be honest I also find this script useless, even for demonstration.
 So if there is no objection I will remove this script from the 
 Bash Startup Files page, unless someone has some use of it.

   
Well, it certainly yields a redundant prompt.  Unless there is some 
input or feedback to create an elegant composite prompt,  we should lose 
the extra-prompt script.
 Also, we had a discussion a while ago, to fix some issues in that same 
 page.
   
I remember the discussion.
 For instance, we can set up different colors in prompt for root and for
 users (red and green respectively) and then to avoid exporting the
 PS1 variable as it was discussed in that old thread.

 Does this prompt (in /etc/profile) looks good to you? (it was suggested by 
 David Jensen)

 if [[ ${EUID} == 0 ]] ; then
   PS1='\[\e[1;31m\]\u [ \[\e[00m\]\w \[\e[1;31m\]]\$ \[\e[00m\]'
 else
   PS1='\[\e[1;32m\]\u [ \[\e[00m\]\w \[\e[1;32m\]]\$ \[\e[00m\]'
 fi

   
As I said, in March, I think I stole the basics from 'Gentoo'.  Though I 
wrote an ansi emulator for 'BBS' browsing, it was 20 years ago, so  I'd 
like to see some feedback before using these.
 Comments for the prompt and the removal of the extra-prompt.sh script and
 additional suggestions for that same page are welcomed, especially since I
 am not using Bash and I am not really sure for the expected results.
   
---
David Jensen

-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


Re: extra-prompt.sh

2007-07-28 Thread Bruce Dubbs
David Jensen wrote:
 Moving to dev. 

 Ag. D. Hatzimanikas wrote:
 Does this prompt (in /etc/profile) looks good to you? (it was suggested by 
 David Jensen)

 if [[ ${EUID} == 0 ]] ; then
  PS1='\[\e[1;31m\]\u [ \[\e[00m\]\w \[\e[1;31m\]]\$ \[\e[00m\]'
 else
  PS1='\[\e[1;32m\]\u [ \[\e[00m\]\w \[\e[1;32m\]]\$ \[\e[00m\]'
 fi

This is too cryptic.  Use:

NORMAL=\[\033[0;39m\]
RED=\[\033[1;31m\]
GREEN=\[\033[1;32m\]

if [[ ${EUID} == 0 ]] ; then
  PS1=$RED\u [ $NORMAL\w$RED ]\$ $NORMAL
else
  PS1=$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL
fi

  -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page


Re: extra-prompt.sh

2005-09-19 Thread Bruce Dubbs
Torsten Vollmann wrote:
 Hi.
 
 Two issues with extra-prompt.sh which popped up during my work on the 
 alfs-profile for blfs-6.1, see:
 
 http://archives.linuxfromscratch.org/mail-archives/alfs-discuss/2005-September/007000.html
 
 
 First the minor one: If my understandig of extra-prompt.sh as it is in the 
 book is right, the output should replace the one from $PS1, cause if both are 
 set to the normal values the output looks like
 
 [EMAIL PROTECTED]: [EMAIL PROTECTED] workdir

No, it *supplements* PS1.  As the book says:
The normal variable, PS1, is supplemented by PROMPT_COMMAND. If set,
the value of PROMPT_COMMAND is executed as a command prior to issuing
each primary prompt.

It is meant as an example.  We expect users to use it or not use it as
desired, but in any case, play around with it.

 So I think there should be some more wording instructing to modify $PS1 in 
 the 
 bash scripts if using extra-prompt.sh unmodified.
 
 
 Second: I think there is an error in extra-prompt.sh (Joachim Beckers and I 
 both checked the script installed by the profile and it is exactly the same 
 one as described in the book)
 
 the output of the script if logged in as root is ALWAYS:
 
 [EMAIL PROTECTED]: /root]  
 
 It does not matter what directory you are in. If I'm not mistaken the error 
 is 
 that the values of $USER, $HOSTNAME and $PWD are filled in when the script is 
 run at startup and not when the prompt is written to the screen resulting in 
 the static output.

You are right, that is an error.  The single and double quotes are
backward and need to be reversed.  I'll fix that.

  -- Bruce
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page