Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker!bloom-beacon!BACH.CS.BYU.EDU!thomas From: thomas@BACH.CS.BYU.EDU (Thomas McNeill) Newsgroups: comp.windows.x Subject: automatically setting DISPLAY variable Message-ID: <9008242049.AA12394@bach.cs.byu.edu> Date: 24 Aug 90 20:49:40 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 91 Here is a csh script/C program combination that will automatically set the DISPLAY environment variable to the proper value, whether you log on to the console or through rlogin. However, it will not work for more than one level of rlogin (that being beyond my meager abilities). The csh script "setdisplay" is: ================================================================== #! /bin/csh -f # setdisplay # Sets the DISPLAY environment variable to :0.0, or if # logged in remotely, to the remote machine. (Unfortunately # will not handle more than one level of rlogin.) # # written by Thomas G. McNeill # August 23, 1990 # Brigham Young University, Provo, UT # set t = `tty` set d = `who | grep $t:t | glogin` if ($d == "" || $d == ":0.0") then setenv DISPLAY "`hostname`:0.0" else setenv DISPLAY $d\:0.0 endif # end of setdisplay ================================================================== The C program "glogin.c" is: ================================================================== /* * glogin.c * written by Thomas G. McNeill * August 23, 1990 * Brigham Young University, Provo, UT * * glogin expects a line from the output of who as its standard input. * If there is a parenthesized string in its input, glogin copies it * to the output (without the parentheses). If there is no such string * in the input, glogin copies nothing to the output. * * There is probably a way to do this with awk, but writing this program * was easier than figuring out how to do it with awk. */ #include #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif void main(argc,argv) int argc; char **argv; { int c; int flag; while ((c = getchar()) != EOF) { if (c == ')') { flag = FALSE; } if (flag) { putchar(c); } if (c == '(') { flag = TRUE; } } } ================================================================== To use, first compile glogin, e.g., cc -o glogin glogin.c Next, make setdisplay executable: chmod +x setdisplay Finally, put the following line in your .login: setdisplay You must do this on every machine to which you log in, either on the console or remotely. Thomas G. McNeill Graduate Student, Computer Science Dept. Brigham Young University, Provo, UT thomas@bach.cs.byu.edu