* Bashrc distinguish between mintty and x-windows xterm
@ 2012-05-22 0:39 Andy
2012-05-22 3:09 ` Buchbinder, Barry (NIH/NIAID) [E]
0 siblings, 1 reply; 8+ messages in thread
From: Andy @ 2012-05-22 0:39 UTC (permalink / raw)
To: cygwin
My bashrc sets the color of the prompt depending on $TERM. My x-windows xterm
has a white background and the cygwin default terminal, which has a black
background, use to not have $TERM=xterm. I could distinguish between them in
the bashrc script, and set the prompt colours accordingly. Now with mintty
emulating an xterm, $TERM takes on the string "xterm" (but it has a black
background). I would like to find a simple bash script way to tell the
difference between when bashrc is being called from a mintty versus an actual
x-windows xterm. Can anyone suggest a way?
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: Bashrc distinguish between mintty and x-windows xterm
2012-05-22 0:39 Bashrc distinguish between mintty and x-windows xterm Andy
@ 2012-05-22 3:09 ` Buchbinder, Barry (NIH/NIAID) [E]
2012-06-20 3:08 ` Andy
0 siblings, 1 reply; 8+ messages in thread
From: Buchbinder, Barry (NIH/NIAID) [E] @ 2012-05-22 3:09 UTC (permalink / raw)
To: cygwin, Andy
Andy sent the following at Monday, May 21, 2012 8:39 PM
>My bashrc sets the color of the prompt depending on $TERM. My x-windows
>xterm has a white background and the cygwin default terminal, which has
>a black background, use to not have $TERM=xterm. I could distinguish
>between them in the bashrc script, and set the prompt colours
>accordingly. Now with mintty emulating an xterm, $TERM takes on the
>string "xterm" (but it has a black background). I would like to find a
>simple bash script way to tell the difference between when bashrc is
>being called from a mintty versus an actual x-windows xterm. Can anyone
>suggest a way?
(Not totally tested. YMMV.)
# Only set ThisTerm if not set.
if [ -z "${ThisTerm}" ]
then
if [ ${PPID} = 1 ]
then
ThisTerm=cmd
else
if [ "$(cat /proc/${PPID}/exename)" = '/usr/bin/mintty' ]
then
ThisTerm=mintty
else
# not minty, not cmd, so xterm
ThisTerm=xterm
fi
fi
fi
Then set colors by the value of ThisTerm.
- Barry
Disclaimer: Statements made herein are not made on behalf of NIAID.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Bashrc distinguish between mintty and x-windows xterm
2012-05-22 3:09 ` Buchbinder, Barry (NIH/NIAID) [E]
@ 2012-06-20 3:08 ` Andy
2012-06-25 1:46 ` Andy
0 siblings, 1 reply; 8+ messages in thread
From: Andy @ 2012-06-20 3:08 UTC (permalink / raw)
To: cygwin
Andy wrote:
| Ken Jackson <cygwin <at> jackson.io> writes:
|> ==== Fri, May 25, 2012 at 09:32AM -0400 Buchbinder, Barry
|> (NIH/NIAID) [E] wrote:
|>> Andrew Hancock sent the following at Friday, May 25, 2012 12:42 AM
|>>>Barry, it works flawlessly. Thanks immensely!
|>>
|>> But I forgot to export ThisTerm, otherwise it is always unset when
|>> a subshell is launched.
|>
|> Access to the /proc file system is fast, so you could forgo the
|> variable and access it directly:
|>
|> case "$(< /proc/$PPID/exename)" in
|> */xterm) echo "This is an xterm" ;;
|> */mintty) echo "This is a mintty" ;;
|> esac
|
|Barry, Ken,
|
|Thanks for your valuable scripting examples. It sent me scurrying back to the
|man page to figure out case/esac and command substitution. It's also a good
|reminder of the wealth of detail available in /proc.
For the record, this in .bashrc seems to work well in xterm's white background
and mintty's black background.
case "$(< /proc/$PPID/exename)" in
*/xterm) function setPS1() {
PS1="\[\033]0;\w\007\033[32m\]\u@\h \[\033[35m\w\033[0m\]\n$" ;
echo xterm
} ;;
*/mintty) function setPS1() {
PS1="\[\e]0;\w\a\]\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$" ;
echo mintty
} ;;
esac
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Bashrc distinguish between mintty and x-windows xterm
2012-06-20 3:08 ` Andy
@ 2012-06-25 1:46 ` Andy
0 siblings, 0 replies; 8+ messages in thread
From: Andy @ 2012-06-25 1:46 UTC (permalink / raw)
To: cygwin
Andy <AndyMHancock <at> gmail.com> writes:
> For the record, this in .bashrc seems to work well in xterm's white
> background > and mintty's black background.
>
> case "$(< /proc/$PPID/exename)" in
> */xterm) function setPS1() {
> PS1="\[\033]0;\w\007\033[32m\]\u@\h \[\033[35m\w\033[0m\]\n$" ;
> echo xterm
> } ;;
> */mintty) function setPS1() {
> PS1="\[\e]0;\w\a\]\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$" ;
> echo mintty
> } ;;
> esac
Actually, the above fails if bash is invoked from a process for which
/proc/$PPID/exename doesn't exist. For example, if I shell out of Windows-based
gvim, $PPID is 1. I found that the following works for this case too.
function setPS1() \
{ PS1="\[\e]0;\w\a\]\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$" ; }
if [ -a /proc/$PPID/exename ]; then
case "$(< /proc/$PPID/exename)" in
*/xterm) function setPS1() {
PS1="\[\033]0;\w\007\033[32m\]\u@\h \[\033[35m\w\033[0m\]\n$" ;
} ;;
esac
fi
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Bashrc distinguish between mintty and x-windows xterm
2012-05-25 14:53 ` Ken Jackson
@ 2012-05-26 21:10 ` Andy
0 siblings, 0 replies; 8+ messages in thread
From: Andy @ 2012-05-26 21:10 UTC (permalink / raw)
To: cygwin
Ken Jackson <cygwin <at> jackson.io> writes:
> ==== Fri, May 25, 2012 at 09:32AM -0400 Buchbinder, Barry
> (NIH/NIAID) [E] wrote:
>> Andrew Hancock sent the following at Friday, May 25, 2012 12:42 AM
>>>Barry, it works flawlessly. Thanks immensely!
>>
>> But I forgot to export ThisTerm, otherwise it is always unset when
>> a subshell is launched.
>
> Access to the /proc file system is fast, so you could forgo the
> variable and access it directly:
>
> case "$(< /proc/$PPID/exename)" in
> */xterm) echo "This is an xterm" ;;
> */mintty) echo "This is a mintty" ;;
> esac
Barry, Ken,
Thanks for your valuable scripting examples. It sent me scurrying back to the
man page to figure out case/esac and command substitution. It's also a good
reminder of the wealth of detail available in /proc.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Bashrc distinguish between mintty and x-windows xterm
2012-05-25 14:19 ` Buchbinder, Barry (NIH/NIAID) [E]
@ 2012-05-25 14:53 ` Ken Jackson
2012-05-26 21:10 ` Andy
0 siblings, 1 reply; 8+ messages in thread
From: Ken Jackson @ 2012-05-25 14:53 UTC (permalink / raw)
To: cygwin
==== Fri, May 25, 2012 at 09:32AM -0400 Buchbinder, Barry (NIH/NIAID) [E] wrote:
> Andrew Hancock sent the following at Friday, May 25, 2012 12:42 AM
> >Barry, it works flawlessly. Thanks immensely!
>
> But I forgot to export ThisTerm, otherwise it is always unset when
> a subshell is launched.
Access to the /proc file system is fast, so you could forgo the
variable and access it directly:
case "$(< /proc/$PPID/exename)" in
*/xterm) echo "This is an xterm" ;;
*/mintty) echo "This is a mintty" ;;
esac
I don't have a need for this, but I had wondered how I would do it
if I did. So I'm glad you posted this.
-Ken Jackson
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: Bashrc distinguish between mintty and x-windows xterm
2012-05-25 6:56 ` Andrew Hancock
@ 2012-05-25 14:19 ` Buchbinder, Barry (NIH/NIAID) [E]
2012-05-25 14:53 ` Ken Jackson
0 siblings, 1 reply; 8+ messages in thread
From: Buchbinder, Barry (NIH/NIAID) [E] @ 2012-05-25 14:19 UTC (permalink / raw)
To: cygwin, Andrew Hancock
Andrew Hancock sent the following at Friday, May 25, 2012 12:42 AM
>Barry, it works flawlessly. Thanks immensely!
You are very welcome.
But I forgot to export ThisTerm, otherwise it is always unset when
a subshell is launched.
# Only set ThisTerm if not set.
if [ -z "${ThisTerm}" ]
then
if [ ${PPID} = 1 ]
then
ThisTerm=cmd
else
if [ "$(cat /proc/${PPID}/exename)" = '/usr/bin/mintty' ]
then
ThisTerm=mintty
else
# not minty, not cmd, so xterm
ThisTerm=xterm
fi
fi
export ThisTerm
fi
One could test exename for /usr/bin/xterm instead of assigning by
the process of elimination.
- Barry
Disclaimer: Statements made herein are not made on behalf of NIAID.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Bashrc distinguish between mintty and x-windows xterm
[not found] <CAGU3OVyzt3r+raKuFEnb1AKkqfzHQy1DPFukJSU8mQyR_3gr9g@mail.gmail.com>
@ 2012-05-25 6:56 ` Andrew Hancock
2012-05-25 14:19 ` Buchbinder, Barry (NIH/NIAID) [E]
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Hancock @ 2012-05-25 6:56 UTC (permalink / raw)
To: cygwin
Buchbinder, Barry (NIH/NIAID) [E] <BBuchbinder <at> niaid.nih.gov> writes:
>
> # Only set ThisTerm if not set.
> if [ -z "${ThisTerm}" ]
> then
> if [ ${PPID} = 1 ]
> then
> ThisTerm=cmd
> else
> if [ "$(cat /proc/${PPID}/exename)" = '/usr/bin/mintty' ]
> then
> ThisTerm=mintty
> else
> # not minty, not cmd, so xterm
> ThisTerm=xterm
> fi
> fi
> fi
>
> Then set colors by the value of ThisTerm.
Barry, it works flawlessly. Thanks immensely!
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-06-25 1:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-22 0:39 Bashrc distinguish between mintty and x-windows xterm Andy
2012-05-22 3:09 ` Buchbinder, Barry (NIH/NIAID) [E]
2012-06-20 3:08 ` Andy
2012-06-25 1:46 ` Andy
[not found] <CAGU3OVyzt3r+raKuFEnb1AKkqfzHQy1DPFukJSU8mQyR_3gr9g@mail.gmail.com>
2012-05-25 6:56 ` Andrew Hancock
2012-05-25 14:19 ` Buchbinder, Barry (NIH/NIAID) [E]
2012-05-25 14:53 ` Ken Jackson
2012-05-26 21:10 ` Andy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).