On a Mac, inside the shell, how can I say that I have a GUI?

Because you (beautiful) people are always so curious about the original intentions of the posters, here are mine:

If I am on a Mac and have a graphical interface (unlike, for example, an ssh session), I want to install $EDITOR mate_wait. (And go with vimotherwise.)

And you have an answer for that. So do I. It even works. Here. Sometimes.

So I want you to desperately study it:

Skip input

I can say that I am on a Mac by checking:

[ `uname` = 'Darwin' ]

And I think I can say that I have a GUI by checking:

[ "$TERM_PROGRAM" = 'Apple_Terminal' ]
  # or
[ "$DISPLAY" ]

Now, theoretically, it is possible that I have an Aqua-less Open Darwin installation with X11. It is also possible that I am running a fully licking Mac GUI, but using a different terminal application.

, xterm Apple X11, OS X. mate_wait $EDITOR.

OCD , , .

, , un-reckless-fy .

+3
2

, , , , . 1:

[ -z "$SSH_CLIENT" ]

2:

[ -n "$SSH_CLIENT" ]

3: lickable mac GUI

[ -n "`ps -fe | grep '[W]indowServer'`" ]

, :

if [ -z "$SSH_CLIENT" -a -n "`ps -fe | grep '[W]indowServer'`" ]; then
     EDITOR="matew"
else
     EDITOR=vim
fi

script, "matew", :

#!/bin/sh
exec mate -w "$*"

EDITOR , ww ( , ).

+2

launchctl, .

if [ "$(launchctl managername)" == Aqua ]; then
    EDITOR="matew";
else
    EDITOR="vim";
fi;
0

Source: https://habr.com/ru/post/1717125/


All Articles