Loading ...
Sorry, an error occurred while loading the content.

120633Re: Determining if Vim is running in text-console mode or X Windows

Expand Messages
  • Steve Laurie
    Feb 1, 2011
    • 0 Attachment
      On 02/02/11 09:25, Benjamin R. Haskell wrote:
      > On Wed, 2 Feb 2011, Steve Laurie wrote:
      >
      >> [...]
      >>
      >> 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
      > else
      > " running on console
      > endif
      >
      >
      >> I have had some success using:
      >>
      >> if &term=~'cons25'
      >> colorscheme myvim
      >> elseif &term=~'xterm'
      >> set t_Co=256
      >> colorscheme calmar256-dark
      >> endif
      >>
      >> 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:
      >
      > COLORTERM=rxvt
      > DISPLAY=:0.0
      > WINDOWID=92274697
      > WINDOWPATH=7
      > XAUTHLOCALHOSTNAME=bhaskell-pc
      > XAUTHORITY=/home/bhaskell/.Xauthority
      >
      > 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.
      >
      > e.g.
      >
      > if exists('$SHLVL') && $SHLVL < 2
      > " probably running on console
      > else
      > " running under X11
      > endif
      >
      > or:
      >
      > if exists('$WINDOWID')
      > " under X11
      > else
      > " on console
      > endif
      >
      Thanks Ben,

      the $DISPLAY version doesn't work (I get red screen and flashing text in
      text mode)

      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
    • Show all 15 messages in this topic