pilgrim@daimi.aau.dk (Jakob G}rdsted) (01/23/91)
I have a problem with the prompt. I want a little script to be executed, every time I press return (I want the prompt to change). Is this possible with a shell-script, or do I have to write a C-program, which I know very little about. Please anwers this question. Thanks in advance. Pilgrim
subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (01/23/91)
In article <1991Jan23.083259.16296@daimi.aau.dk> pilgrim@daimi.aau.dk (Jakob G}rdsted) writes: >I have a problem with the prompt. > >I want a little script to be executed, every time >I press return (I want the prompt to change). > >Is this possible with a shell-script, or do >I have to write a C-program, which I know >very little about. The tcsh and zsh shells have exactly what you want to do built in. If you > alias precmd shellscript, # In tcsh, or Z> function precmd {shellscript} # in zsh it will execute 'shellscript' right before it prints every prompt. You can get tcsh from many sites, (I think the 'official' one these days is tesla.ee.cornell.edu). You can get zsh from Princeton.EDU. -Kartik > >Please anwers this question. > > Thanks in advance. Pilgrim -- internet# find . -name core -exec cat {} \; |& tee /dev/tty* subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet kartik@silvertone.Princeton.EDU (NeXT mail) -| SUBBARAO@PUCC.BITNET - Bitnet
jik@athena.mit.edu (Jonathan I. Kamens) (01/23/91)
It would be easier for us to answer your question if you were to tell us what shell you are using. It might also be useful for you to tell us *how* you want the prompt to change, i.e. what information you want it to contain. It is possible that your shell has facilities for displaying the information built into the shell prompt code. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710
chet@thor.INS.CWRU.Edu (Chet Ramey) (01/24/91)
In article <1991Jan23.083259.16296@daimi.aau.dk> pilgrim@daimi.aau.dk (Jakob G}rdsted) writes: >I want a little script to be executed, every time >I press return (I want the prompt to change). Bash will do this for you. To have `prog' executed before each primary prompt, do the following: PROMPT_COMMAND=prog Bash also expands a number of control strings in the prompt before it is printed; if you want the prompt to change to include one of the following it's not necessary to run a script \t the time \d the date \n CRLF \s the name of the shell \w the current working directory \W the last element of PWD \u your username \h the hostname \# the command number of this command \! the history number of this command \$ a $ or a # if you are root \<octal> character code in octal \\ a backslash Chet -- Chet Ramey ``There's just no surf in Network Services Group Cleveland, U.S.A. ...'' Case Western Reserve University chet@ins.CWRU.Edu My opinions are just those, and mine alone.
edw@sequent.UUCP (Ed Wright) (01/24/91)
In article <1991Jan23.083259.16296@daimi.aau.dk> pilgrim@daimi.aau.dk (Jakob G}rdsted) writes:
%I have a problem with the prompt.
Don't we all.
Well Pilgrim ( as the duke would say)
Its kind of hard to tell you how to change something with no idea
of what change your are after.
Here is a simple one for your .cshrc
alias cd 'cd \!* ;set prompt=`pwd`" {\!} "'
That will change your prompt to show process number each time you
do something. A simple press of the return key wont change it
this will make the path to your working directory be part of the
prompt.
You can take that to a silly extreme
alias cd 'cd \!* ;set prompt=`hostname`" "`whoami`" "`pwd`" {\!} "'
Post more information, and no doubt you'll get better answers.
Cheers
Ed
--
I think I've got the hang of it now .... :w :q :wq :wq! ^d X exit
X Q :quitbye CtrlAltDel ~~q :~q logout save/quit :!QUIT ^[zz
^[ZZ ZZZZ ^H ^@ ^L ^[c ^# ^E ^X ^I ^T ? help helpquit ^D ^d
^C ^c helpexit ?Quit ?q decwrl or uunet or tek !sequent!edw
dfs@doe.carleton.ca (David F. Skoll) (02/08/91)
In <51331@sequent.UUCP> edw@sequent.UUCP (Ed Wright) writes: >You can take that to a silly extreme >alias cd 'cd \!* ;set prompt=`hostname`" "`whoami`" "`pwd`" {\!} "' I have taken my prompt to an even SILLIER extreme (but I like it.) Here's an extract from my .cshrc: alias cd "cd \!*; prompt" alias chdir "cd \!*" alias popd "popd \!*; prompt" set effuser=`whoami` set host=`hostname` set tty=`tty` if ($effuser == "root") then set hash="#" else set hash="%" set path=($path .) endif alias prompt 'set prompt="--> $cwd <--\\ \\!: ${effuser}@${host}($tty:t)${hash} "' This is what is looks like right now: --> /enterprise/transporter/dfs <-- 2: dfs@riker(ttyp4)% | Cursor here ---------+ -- David F. Skoll.
erik@westworld.esd.sgi.com (Erik Fortune) (02/08/91)
Hah! You want silly, extreme prompts? Here's an excerpt from *my* aliases file: (-: alias back 'cd $lastdir' alias cd 'cd \!:* ; ExitDir ; FixLocation ; FixPrompt ; EnterDir' alias ExitDir 'set lastdir=${thisdir}' alias EnterDir 'set thisdir=${cwd} ; FixPrompt' #aliases to make cd,pushd,and popd understandable if ( ! $?PROMPTCOMMENT ) setenv PROMPTCOMMENT "" if ( ! $?CDENTER ) setenv CDENTER .cdinit.cmd if ( ! $?CDEXIT ) setenv CDEXIT .cdexit.cmd if ( ! $?rev_vid ) setenv rev_vid "" if ( ! $?norm_vid ) setenv norm_vid "" if ( ! $?host_pfx ) setenv host_pfx "" if ( ! $?thisdir ) set this_dir = . if ( ! $?lastdir ) set last_dir = . alias EnterDir 'if (-e "$thisdir/$CDENTER") source $thisdir/$CDENTER' alias ExitDir 'if (-e "$thisdir/$CDEXIT") source $thisdir/$CDEXIT' alias FixLocation 'set lastdir = "$thisdir";set thisdir = "`pwd`"' alias FixPrompt 'set prompt="${host_pfx}${rev_vid}<${HOST}:${PROMPTCOMMENT}${cwd:t}>${norm_vid} "' I use color xterm, and the $host_pfx is the escape sequence to change xterm foreground and background colors, so the color of my window varies with the host I'm talking to. If I'm not on an xterm (but I am on ansi), it changes the colors of prompt depending on the host I'm currently logged into. The $rev_vid is the escape sequence to set whatever terminal I'm on into reverse video, $norm_vid sets it back. A session looks like this (I'm rlogged in to "piranha" in a directory /mumble/mumble/blah: [ xterm is white on navy, prompt is navy on white ] <piranha:blah> ~^Z [ xterm changes color to white on firebrick, prompt is firebrick on white ] <westworld:erik> It's ugly, but I love it. Oh, yeah. If a directory has a file named .cdinit.cmd in it, the file is sourced whenever I cd into the directory. If a directory has a .cdexit.cmd, the file is sourced when I leave. I have local aliases for lots of directories. -- Erik
de5@ornl.gov (Dave Sill) (02/08/91)
In article <1991Feb8.003607.10413@odin.corp.sgi.com>, erik@westworld.esd.sgi.com (Erik Fortune) writes: > >Oh, yeah. If a directory has a file named .cdinit.cmd in it, the >file is sourced whenever I cd into the directory. If a directory >has a .cdexit.cmd, the file is sourced when I leave. I have local >aliases for lots of directories. I hope you never cd to directories writable by others, at least on multiuser systems. -- Dave Sill (de5@ornl.gov) It will be a great day when our schools have Martin Marietta Energy Systems all the money they need and the Air Force Workstation Support has to hold a bake sale to buy a new bomber.
bob@MorningStar.Com (Bob Sutterfield) (02/08/91)
I like to have my pwd in my xterm window's title stripe, and the time of day in the shell prompt. I also like to have the prompt in inverse-video if I happen to be doing rootly things at the moment, just to warn me of the increased probability that I'm about to break something. I use cshe, a local csh variant. %t gives the current time string and %S/%s shift inverse/normal video, as per the termcap entry. Most of the prompt string substitution capabilities (or something similar) are also available in tcsh and its descendants. In the .cshrc excerpt below, I've changed actual escape and bell characters into their equivalent two-character graphic representation. It could probably be done prettier in csh, or cleaner in ksh functions, but you get the idea. # set host=(`hostname | tr '.' ' '`) setenv HOST $host[1] # # interactive shell? if (! $?prompt) exit # if ($?DISPLAY) then alias precmd 'echo -n "^[]0;"{$HOST}":$cwd^G"' set prompt="%t> " if ($?uid) then if ($uid == 0) set prompt="%S%t>%s " endif else set prompt={$HOST}":%/> " if ($?uid) then if ($uid == 0) set prompt={$HOST}":%S%/>%s " endif endif #
karl.kleinpaste@osc.edu (02/09/91)
bob@MorningStar.Com writes:
if ($uid == 0) set prompt={$HOST}":%S%/>%s "
Aw, Bob, c'mon:
if ($uid == 0) set prompt="%m:%S%/>%s "
Or %M, if you like the FQDN form, and your hostname is set to it.
--karl
--
Note new address:
karl_kleinpaste@cis.ohio-state.edu => karl.kleinpaste@osc.edu
barnett@grymoire.crd.ge.com (Bruce Barnett) (02/11/91)
In article <1991Feb8.003607.10413@odin.corp.sgi.com> erik@westworld.esd.sgi.com (Erik Fortune) writes: > alias EnterDir 'if (-e "$thisdir/$CDENTER") source $thisdir/$CDENTER' > alias ExitDir 'if (-e "$thisdir/$CDEXIT") source $thisdir/$CDEXIT' de5@ornl.gov (Dave Sill) writes: >I hope you never cd to directories writable by others, at least on >multiuser systems. Easy to fix. Change the "-e file" to a " -f file && -o file ": alias EnterDir 'if ( -f "$thisdir/$CDENTER" && -o "$thisdir/$CDENTER" ) source $thisdir/$CDENTER' alias ExitDir 'if ( -f "$thisdir/$CDEXIT" && -o "$thisdir/$CDEXIT" ) source $thisdir/$CDEXIT' As long as the file isn't group or world writable, that is. -- Bruce G. Barnett barnett@crd.ge.com uunet!crdgw1!barnett
allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (02/12/91)
As quoted from <dfs.665954950@riker> by dfs@doe.carleton.ca (David F. Skoll): +--------------- | In <51331@sequent.UUCP> edw@sequent.UUCP (Ed Wright) writes: | | >You can take that to a silly extreme | >alias cd 'cd \!* ;set prompt=`hostname`" "`whoami`" "`pwd`" {\!} "' | | I have taken my prompt to an even SILLIER extreme (but I like it.) Here's | an extract from my .cshrc: > (deleted for brevity) | This is what is looks like right now: | | --> /enterprise/transporter/dfs <-- | 2: dfs@riker(ttyp4)% +--------------- If you don't mind some ksh injected into this discussion: case "$-" in *i*) typeset -i Level Level=${LEVEL:-0} Level=$Level+1 LEVEL=$Level unset Level export LEVEL case $LEVEL in 1) level="" ;; *) level="${LEVEL}@" ;; esac UID="`id|sed -n 's/^uid=\([0-9][0-9]*\)(.*$/\1/p'`" case "$UID" in 0) prompt='K#' ;; 204) prompt='K$' ;; *) prompt="`awk -F: '$3 == '$UID' { print \"{\" $1 \"}\" exit }' /etc/passwd` K$" ;; esac PS1="${level}`uname -n`:! ${prompt} " unset prompt level ;; esac This is actually an older version; my current version is driven off the login name, but it's on a different machine. The prompt, in both versions, looks like: 2@ncoast:141 K$ _ ("_" is the prompt, a convention of mine in messages which include interactive shell stuff.) "2@": 2nd level login; 141: command number; "K" to remind me it's Korn shell; "$" because it's non-root. Root gets "K#"; if I su to anyone else, I get: 2@ncoast:142 {news} K$ _ The newer version also indicates the (compressed) tty and directory stack depth, if it's not 1: 2@telotech[con/0]:143 (test) K$ pwd /u/allbery 2@ncoast[con/0]:144 (test) K$ pushd /tmp /tmp /u/allbery 2+2@ncoast[con/0]:145 (test) K$ _ The console is "con"; MultiView windows (a sort of "screen" which emulates the real terminal instead of a VT102) are indicated as real-tty/windo-number ("con/0"); there is no [] if it's not running on a terminal-like fd (i.e. a pipe). The () is a project ID; it's omitted if I haven't set a project. This is usually a handier method of identifying a window than the window number. (The directory stack is implemented via ksh functions, and includes most, if not all, of the csh directory stack facilities.) I tried including the current directory in the prompt, but it got too big too fast; it's big enough as it is, and paths are generally a lot longer than the other stuff I include. And I detest two-line prompts. Moreover, the project ID is usually sufficient for my needs, since a project usually has a specific directory associated with it. ++Brandon -- Me: Brandon S. Allbery VHF/UHF: KB8JRR on 220, 2m, 440 Internet: allbery@NCoast.ORG Packet: KB8JRR @ WA8BXN America OnLine: KB8JRR AMPR: KB8JRR.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery Delphi: ALLBERY