120633Re: Determining if Vim is running in text-console mode or X Windows
- Feb 1, 2011On 02/02/11 09:25, Benjamin R. Haskell wrote:
> On Wed, 2 Feb 2011, Steve Laurie wrote:Thanks Ben,
>> Both in text console and in gnome-terminal, :echo $DISPLAY returns 0
>> (int, not a string) - still no difference between tty text mode and
>> terminal emulator.
> Maybe I'm misunderstanding something in your response, but you
> shouldn't test the return value of echo. Test the $DISPLAY env var:
> if exists('$DISPLAY')
> " running under X11
> " running on console
>> I have had some success using:
>> if &term=~'cons25'
>> colorscheme myvim
>> elseif &term=~'xterm'
>> set t_Co=256
>> colorscheme calmar256-dark
>> but the strange thing is, if $TERM is set to xterm and not
>> xterm-256color, gkrellm locks up... something to do with the email
>> part of it.
>> If I could just find where xterm is being set and change it to
>> xterm-256color without altering tty mode's TERM settings (i.e.
>> cons25) I'd be laughing.
> For me, here are some environment variables that are different between
> a shell running on a virtual console and a shell session running under
> rxvt-unicode under X11:
> X11: TERM=rxvt-unicode256 console: TERM=linux
> X11: SHLVL=4 console: SHLVL=1
> These are not present at all on a vt:
> You shouldn't have a DISPLAY variable set under a console session, as
> it's meaningless. (Doesn't mean you won't get one -- might be
> erroneously set up by default.)
> You're also right to question a TERM=cons25 when running under X11;
> that sounds as broken as $DISPLAY. Do you have something in a
> .profile, .bash_profile, or .bashrc?
> Actually, on a FreeBSD box that I have access to, the .profile file
> from /etc/skel/ has:
> TERM=cons25; export TERM
> Maybe that's the problem.
> Otherwise, I would think $SHLVL and $WINDOWID would be your best chances.
> if exists('$SHLVL') && $SHLVL < 2
> " probably running on console
> " running under X11
> if exists('$WINDOWID')
> " under X11
> " on console
the $DISPLAY version doesn't work (I get red screen and flashing text in
however, both $WINDOWID and ('$SHLVL') && $SHLVL < 2 do work.
I think I like the $WINDOWID version best. It feels ... ??cleaner??. I
don't know why because, without looking it up, I don't even know what
$SHLVL is. I suspect it's shell level and if we're running in the first
level of the shell, then it's likely to be text console given that
that's what I first log into. Am I right?
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic Next post in topic >>