From owner-freebsd-questions Wed Aug 12 08:19:34 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA09982 for freebsd-questions-outgoing; Wed, 12 Aug 1998 08:19:34 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from phoenix.volant.org (phoenix.volant.org [205.179.79.193]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA09946 for ; Wed, 12 Aug 1998 08:19:25 -0700 (PDT) (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.92 #8) id 0z6cfv-0006P7-00; Wed, 12 Aug 1998 08:18:55 -0700 Received: from localhost by asimov.phoenix.volant.org (SMI-8.6/SMI-SVR4) id IAA01789; Wed, 12 Aug 1998 08:18:51 -0700 Date: Wed, 12 Aug 1998 08:18:51 -0700 (PDT) Reply-To: patl@phoenix.volant.org Subject: Re: BASH prompt question To: flygt@sr.se cc: FreeBSD Questions In-Reply-To: <19980803213618.C11549@sr.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > > > > I would like to make my bash prompt show a little more info, like > > > > > what dir the user is in. How would I do this? > > ... > > > PS1='\u@\h:`pwd -P` \$ ' > > > \$ will be replaced with uid==0 ? '#' : '$' > > I often find that to be a little too long prompt. If one puts in a \W > after the h: only the rightmost part of the path is visible. > Something like: PS1='\u@\h: \W \\$ ' Since I'm usually using some form of X11-based terminal emulator, I prefer to keep the prompt short and of a (relatively) fixed length. When using an emulator that supports color, I use: : ${USER:=$(/usr/ucb/whoami)} export USER PS1="\[\033[1;34m\]$USER@\h.\!>\[\033[30m\] " This will put the login name, hostname, and history entry number followed by a right broket (greater than sign), in blue. (I use red for root.) Without color support the PS1 line reduces to: PS1="$USER@\h.\!> " I keep track of the path in the window's titlebar. (This requires a window manager that let's you change the titlebar text. Most of the ones I've tried do; but not all.) Since I've been doing this for a while, on a variety of machines and OSes, the code to set it up is a bit more baroque than strictly necessary: if [ "$PS1" != "" ] ; then function setup_window_frobbery { # We can't do terminal-specific things when running under the # CDE Display Manager if [ -z "$DT" ] ; then # Set the terminal to full eight-bit mode for the Meta-shift keys. # In case we are running in a terminal emulator that loses the # tty settings. Of course, we lose if the terminal really can't # handle 8bit data; but how often will we be doing that? # if [ $OS_MAJOR_VERSION = 5 ] ; then /bin/stty -markp -parenb -istrip cs8 else /bin/stty pass8 fi fi host=$(uname -n) # Stripe has to be a function because it is referenced from # functions. Functions do not perform internal alias # substitution. (It could be a variable, but it might # be expanded during function definition instead of during # execution, and why clutter the environment with it? ) if test -s /usr/bin/stripe ; then # Export PWD because without it in the environment # /usr/bin/stripe segfaults. function stripe { /usr/bin/stripe $* ; } export PWD else function stripe { # I kind of hate to spawn a perl every time this is run; # but there is no builtin way to convert the initial # directory qualifiers back to a tilde when somewhere # under the home directory. # local Pwd=$(perl -e '$_=$ENV{"PWD"};s:^$ENV{"HOME"}:~:;print') #label "Commands: $USER @ $host - $Pwd" label "$USER @ $host - $Pwd" } fi if [ `uname -s` = "IRIX" ] ; then # Correct some brain-damaged default key bindings stty intr ^c quit ^\\ fi # 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\\" ; } #function label { # perl -e 'print "\033]l'"$*"'\033\\";' #} #function label-icon { # perl -e 'print "\033]L'"$*"'\033\\";' #} fi 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 resize { builtin echo -ne "\033[;$1;$2t" ; } function su { # local IN_SU=$PWD ; # local OLD_HISTFILE=$HISTFILE # unset HISTFILE # Ensure that the title-bar has some indication that we have # changed users, even if the new user doesn't update it. label "[ SU $* ] @ $host" # We want HOME, USER, etc. to be set appropriately for # root rather than inherited. Unfortunatly, the Sun # standard su has no way to do this and still retain # anything from the old environment (including current # working directory...) # # NOTE: This really should check the parameters to # determine how to set USER, HOME, etc. # /usr/bin/env - HOME=/ USER=root DISPLAY=$DISPLAY TERM=$TERM IN_SU=$PWD /usr/bin/su $* # if [ -n "$HISTFILE" ] ; then # declare -x HISTFILE=$OLD_HISTFILE # fi stripe } function rlogin { label-icon "[$1]" # /usr/ucb/rlogin $* command rlogin $* stripe ; label-icon "[$host]" } } # The following depends upon the precedence in the expr man page: # string-match -> * / % -> inequalities -> & -> | # # WINDOW_PARENT is SunView specific - it isn't there # for `openwin -nosunview'. # # DISPLAY is X11 or X/NeWS specific. # if [ \( \ \( "$WINDOW_PARENT" \!= "" \) -o \ \( "$DISPLAY" \!= "" \) \ \) -a \( \ \( "$TERM" = "sun" \) -o \ \( "$TERM" = "sun-cmd" \) -o \ \( "$TERM" = "xterm" \) -o \ \( "$TERM" = "dtterm" \) -o \ \( "$TERM" = "vt100" \) -o \ \( "$TERM" = "iris-ansi" \) \ \) ] then #if tty=$(tty) ; then # Use unique history file for each window. # HISTFILE=$HOME/.dotfiles/.bash_history$DOTHOST.$(tty | cut -d/ -f3) HISTFILE=$HOME/.dotfiles/.bash_history$DOTHOST.$(tty | cut -d/ -f3,4 | tr -d /) if test "$tty" \!= "/dev/console" ; then setup_window_frobbery fi #fi unset tty fi fi To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message