From owner-freebsd-questions Wed Nov 19 15:15:03 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id PAA10709 for questions-outgoing; Wed, 19 Nov 1997 15:15:03 -0800 (PST) (envelope-from owner-freebsd-questions) Received: from phoenix.volant.org (phoenix.volant.org [205.179.79.193]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id PAA10697 for ; Wed, 19 Nov 1997 15:15:00 -0800 (PST) (envelope-from patl@phoenix.volant.org) From: patl@phoenix.volant.org Received: from asimov.phoenix.volant.org [205.179.79.65] by phoenix.volant.org with smtp (Exim 1.62 #1) id 0xYJKf-0000Ra-00; Wed, 19 Nov 1997 15:14:53 -0800 Received: from localhost by asimov.phoenix.volant.org (SMI-8.6/SMI-SVR4) id PAA26607; Wed, 19 Nov 1997 15:14:48 -0800 Date: Wed, 19 Nov 1997 15:14:48 -0800 (PST) Reply-To: patl@phoenix.volant.org Subject: Re: Keeping mutliple machine and telnets straight.... To: Studded cc: FreeBSD Questions In-Reply-To: <199711192156.NAA29691@mail.san.rr.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Sender: owner-freebsd-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > On Wed, 19 Nov 1997 08:40:40 -0600, Dave Glowacki wrote: > ...[elided]... > > The % at the end of the prompt is generally associated with *csh. > A more Bash-like thing would be to use the $ that is traditional for > Bourne (plain sh) and Bash shells. And while we're comparing prompts.. :) > I like to know what directory I'm in, but it can get too long to read the > commands that I'm typing in, so I put the directory and such on one line, > and my prompt right below. If you do this with an xterm, make sure you > use the -rw argument, otherwise it won't wrap properly. I prefer to put that in the window's border. First, set a couple of variables. I use these in a few other places in my .bashrc. host=$(uname -n) # SVr4 doesn't seem to have a USER environment variable by default : ${USER:=$(/usr/ucb/whoami)} export USER This block defines a 'label' function that simply inserts its command-line parameters into the titlebar of the window; and 'label-icon' which does the same for the icon label. (Remember, these are only suggestions to the window manager. Not all WMs support them.) # Different terminal emulators take slightly different escape # sequences for the title-bar and icon label functions. # Ain't standards wunnerful? # if [ "$TERM" = "iris-ansi" ] ; then # DCS = ESC P or octal 220 # ST = ESC backslash or octal 234 function label { builtin echo -ne "\2201.y$*\234" ; } function label-icon { builtin echo -ne "\2203.y$*\234" ; } elif [ "$TERM" = "xterm" ] ; then # This sequence changes both the title bar and the icon function label { builtin echo -ne "\033]0;$*\007" ; } function label-icon { : } else # Sun shelltool/cmdtool, NeWS ANSIterm/jet, etc. # function label { builtin echo -ne "\033]l$*\033\\" ; } function label-icon { builtin echo -ne "\033]L$*\033\\" ; } } This function takes no parameters. It generates the string and invokes 'label' to set the window title. The first line, declaring and setting the Pwd variable, is to ensure that any path prefix matching my home directory is converted into a tilde. I really don't like having to spawn a perl (or any other external process) to do this; but I don't know of any clean portable way to do this with bash built-ins. (NOTE that this is pretty old code, and I haven't bothered to determine whether later versions of bash would allow me to clean it up.) function stripe { local Pwd=$(perl -e '$_=$ENV{"PWD"};s:^$ENV{"HOME"}:~:;print') label "$USER @ $host - $Pwd" } Finally, since I don't want to spawn a perl for every command prompt, I define functions to shadow those commands that would change the working directory. Note that rlogin will change the label on the icon to be '[new-host-name]' when it is possible to set the icon and titlebar separately. function cd { builtin cd $* ; stripe ; } function pushd { builtin pushd $* ; stripe ; } function popd { builtin popd $* ; stripe ; } function pwd { builtin pwd ; stripe ; } function suspend { builtin suspend ; stripe ; } function su { # NOTE that the titlebar will remain at the current # (pre-su) value unless the new user's shell also # updates it. So we make sure that it gets at least # a minimal indication of the change. label "[[SU $*]]" command su $* stripe } function rlogin { label-icon "[$1]" command rlogin $* stripe ; label-icon "[$host]" } If at any point the titlebar does get out of sync, I can manually issue a 'stripe' command to bring it back. -Pat