Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!texsun!convex!news From: mullins@convex.COM (Don Mullins) Newsgroups: comp.unix.shell Subject: Re: Passing parameters to an alias in ksh ...under AIX Message-ID: <1990Dec19.183407.8863@convex.com> Date: 19 Dec 90 18:34:07 GMT References: <1235@lafayet.UUCP> Sender: news@convex.com (news access account) Reply-To: mullins@convex.COM (Don Mullins) Distribution: na Organization: Convex Computer Corporation, Richardson, TX Lines: 91 Nntp-Posting-Host: starman.convex.com In article <1235@lafayet.UUCP> rob@lafayet.UUCP (Rob Freyder) writes: >I am trying to pass a parameter to an alias under AIX on the RS6000. >I would like to set up an alias that will take a directory name as an >argument and then print that in the title of my X window. I am not having >trouble changing the title ... that is a simple escape sequence. > >My Problem is that I cant get the alias to accept a parameter. I am using >$1 to reference the first parameter... Is this correct ? > >Thanks. Rob. >-- > ____ ____ ____ Core Lab - Western Atlas Int'l INC > \ \ / /\ / \ Rob Humans (318) 235-9431 > \ / /\ \/ /\ \ Freyder Internet rob@lafayet.waii.com > \/___/ \/___/ \__\ Bang ...!uunet!lafayet!rob I don't know how to pass args to an alias (similar to !* in csh/tcsh), but you can in a function. The following function will cd to the arg passed. Then it will update the title line if you are running X windows, otherwise it will change the prompt to reflect the cwd. It optimizes the path by substituting a '~' for the user's home. Our version of ksh accepts '\033' of ESC and '\007' for BEL; substitute the actual chars if needed. The "$@" in the cd command is equiv. to "$1" "$2" ... "$*" could be used to get "$1d$2d$3d"... where d is the IFS variable. both functions assume: $HOST = hostname (i.e. "starman" for my machine). $HOME = user's home dir. $PWD = present working dir. use by: alias cd=_cd cd --------------------------------- CUT HERE ------------------------------------ function _cd { # I use the if to prevent the update if the cd fails if 'cd' "$@" then if [ "$DISPLAY" != "" ] then # We are running X, update the title line case "$PWD" in ${HOME}*) XTITLE="${HOST}:~${PWD#"$HOME"}" ;; *) XTITLE="${HOST}:${PWD}" ;; esac print -n "\033]2; ${XTITLE} \007" else # Just a terminal, reset the prompt case "$PWD" in ${HOME}*) PS1="${HOST}:~${PWD#"$HOME"} $ " ;; *) PS1="${HOST}:${PWD} $ " ;; esac fi fi } --------------------------------- END HERE ------------------------------------ This one just sets the title line... use by: title --------------------------------- CUT HERE ------------------------------------ function title { case "$PWD" in ${HOME}*) XTITLE="${HOST}:~${PWD#"$HOME"}" ;; *) XTITLE="${HOST}:${PWD}" ;; esac print -n "\033]2; ${XTITLE} \007" } --------------------------------- END HERE ------------------------------------ Let me know if someone shows you how to get an alias to directly accept args. Good luck, Don -- Don Mullins INTERNET -- mullins@convex.com UUCP ------ {uiucuxc, uunet, sun, ...}!convex!mullins