Date: Wed, 19 Nov 1997 15:14:48 -0800 (PST) From: patl@phoenix.volant.org To: Studded <Studded@dal.net> Cc: FreeBSD Questions <FreeBSD-Questions@freebsd.org> Subject: Re: Keeping mutliple machine and telnets straight.... Message-ID: <ML-3.3.879981288.8394.patl@asimov> In-Reply-To: <199711192156.NAA29691@mail.san.rr.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ML-3.3.879981288.8394.patl>