Passing parameters to an alias in ksh ...under AIX

Don Mullins mullins at convex.COM
Thu Dec 20 05:34:07 AEST 1990


In article <1235 at lafayet.UUCP> rob at 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 at 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:
 <filename>
alias cd=_cd

cd <dir>

--------------------------------- 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:
 <filename>

title <text>

--------------------------------- 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 at convex.com
UUCP ------ {uiucuxc, uunet, sun, ...}!convex!mullins



More information about the Comp.unix.shell mailing list