From owner-freebsd-questions Wed Sep 18 23: 4:39 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7AA2D37B401 for ; Wed, 18 Sep 2002 23:04:37 -0700 (PDT) Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2F7DD43E6A for ; Wed, 18 Sep 2002 23:04:36 -0700 (PDT) (envelope-from keramida@ceid.upatras.gr) Received: from hades.hell.gr (patr530-a149.otenet.gr [212.205.215.149]) by mailsrv.otenet.gr (8.12.4/8.12.4) with ESMTP id g8J64WU8028755; Thu, 19 Sep 2002 09:04:33 +0300 (EEST) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.3/8.12.3) with ESMTP id g8J64XBZ058428; Thu, 19 Sep 2002 09:04:34 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by hades.hell.gr (8.12.3/8.12.3/Submit) id g8J64RoH058422; Thu, 19 Sep 2002 09:04:28 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Thu, 19 Sep 2002 09:04:25 +0300 From: Giorgos Keramidas To: Peter Leftwich Cc: FreeBSD-Questions@FreeBSD.ORG Subject: Re: ~/.terminalrc challenge Message-ID: <20020919060425.GD39149@hades.hell.gr> References: <20020919013316.C83658-100000@earl-grey.cloud9.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020919013316.C83658-100000@earl-grey.cloud9.net> X-PGP-Fingerprint: C1EB 0653 DB8B A557 3829 00F9 D60F 941A 3186 03B6 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 2002-09-19 01:35, Peter Leftwich wrote: > I would like a file similar to my ~/.login (which sets some leave reminders > and prompt customizations) but only to run when a new gnome-terminal is > launched, for example some kind of ~/.terminalrc file? > > This may be possible via my ~/.cshrc but I am not very crafty at using > "test" in the first few lines to run `ps -auxww | grep XFree86` and if that > returns true to run a few lines of code. That's almost certainly the wrong way of doing something like this. You can't be sure that the new login session is within a gnome-terminal, just because some process happens to be called XFree86. Think of the following series of events: - You fire up X11. - You switch to console ttyv0 with CTRL+ALT+F1. - You log into console ttyv0. - Your ttyv0 console login runs .terminalrc !!! I'm sure that gnome-terminal has some other way of firing up a shell with customised settings. Or you could check for DISPLAY in the environment *and* make sure that this is a gnome-terminal by making sure that the process-ID of $$ matches a running gnome-terminal instance. That can get tricky though. An example of a way to determine the name of the program that spawned the currently running shell (bash in my case) is shown below: $ ps -o pid,ppid,command | awk -v pid=$$ '$1 == pid && $3 ~ bash {print $2}' 219 $ ps -ax -o pid,ppid,command | awk '$1 == 219 {print $0}' 219 1 screen -a -O Using this in a shell script could be a bit tricky: pid=`ps -o pid,ppid,command |\ awk -v pid=$$ '$1 == pid && $3 ~ bash {print $2}'` if ps -ax -o pid,ppid,command | awk '$1 == '"$pid"' {print $0}' |\ grep screen >/dev/null 2>&1 ;then # echo "We are running bash under screen." else # echo "What is this? Where am I?" fi I hope this helps. -- Giorgos Keramidas FreeBSD 4.6-RELEASE #0: Wed Sep 18 23:08:01 EEST 2002 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message