SCIENTIFIC-LINUX-USERS Archives

November 2017

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sat, 11 Nov 2017 08:10:14 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (52 lines)
On Fri, Nov 10, 2017 at 10:41 PM, jdow <[log in to unmask]> wrote:


> So I went through some documentation. Now I am back up to speed for
> ANSI escape sequences and the theoretical interaction of
> PROMPT_COMMAND and PS1. PROMPT_COMMAND is run then PS1 is displayed.
> PROMPT_COMMAND already has the \e0m in it. \e is bash for escape.

Are you sure that "PROMPT_COMMAND" has "\e[0m" in it?

You're missing the difference between "\e]0" and "\e[0m". The first is
to set an xterm window title and the second is to reset attributes.

"PROMPT_COMMAND" is executed before PS1 is evaluated and printed.

So if you set "PROMPT_COMMAND" to "pwd" it'll print the current
directory before displaying PS1:

th@localhost ~ $ PROMPT_COMMAND="pwd"
/home/th
th@localhost ~ $ cd /etc
/etc
th@localhost /etc $ cd
/home/th
th@localhost ~ $

But if you include "\e]0", the window title's set:

th@localhost ~ $ PROMPT_COMMAND='printf "\033]0;$(pwd)\007"'

You can run "PROMPT_COMMAND" from "PS1" with:

PROMPT_COMMAND='printf "\033]0;$(pwd)\007"'
PS1="\u@\h \w $ "

is the same as

PS1='$(printf "\033]0;$(pwd)\007")\u@\h \w $ '

If you run "PROMPT_COMMAND" from "PS1", you can use bash escapes:

PS1="\033]0;\w\007\u@\h \w $ "

This is the same as the "PS1" just above it except that it'll
substitute "~" for "$HOME".


> "\e[0m[\\u@\\h: \\w]\\$ " is what I should have used. The m makes it do its
> thing.

The "m" was definitely missing earlier :)

ATOM RSS1 RSS2