Parameter passing in aliases

Parameter passing in aliases

Post by Tariq A Kha » Sat, 30 Dec 1995 04:00:00



I am trying to display the username, hostname and the current directory
as title of the hpterm window. I was able to do this by compiling a
small c program (title) to set the title of the hpterm and add the
following to the .login in csh


settitle
alias cd 'cd \!*;settitle'

This works fine. But I am not able to do the in ksh/posix-sh. The alias
command

alias cd='cd $0;settitle'  

does not work. I had tried all ways I could think of to pass the
parameter to the alias command. I need an alias for cd which would
change the directory and the execute the settitle.

Thanks in advance.


New York, New York                                  

 
 
 

Parameter passing in aliases

Post by Mike Stroy » Tue, 02 Jan 1996 04:00:00



|I am trying to display the username, hostname and the current directory
|as title of the hpterm window. I was able to do this by compiling a
|small c program (title) to set the title of the hpterm and add the
|following to the .login in csh


|settitle
|alias cd 'cd \!*;settitle'

|This works fine. But I am not able to do the in ksh/posix-sh.  ...

  The function mechanism in ksh is much more powerful than aliases.
Here is an implmentation of window title that does not require a "title"
program.  It also provides "pushd", "popd" and "dirs" functions that
should be familiar to former csh users.  The mcd function is multiple
choice from among the contents of the directory stack.

function dtterm_title {
    print "\033]2;$1\007\c"

Quote:}

function dtterm_icon_label {
    print "\033]1;$1\007\c"

Quote:}

function hpterm_title {
    print "\033&f0a0k${#1}D$1\c"

Quote:}

function hpterm_icon_label {
    print "\033&f0a-1k${#1}D$1\c"

Quote:}

case $TERM in
hpterm)
    alias title=hpterm_title
    alias icon_label=hpterm_icon_label
    escape=$(print "\033")
    export PS1="${escape}&v2S%${escape}&v6S "
    export PS2="${escape}&v2S>${escape}&v6S "
    export PS3="${escape}&v2S>${escape}&v6S "
    unset escape
    ;;
dtterm)
    alias title=dtterm_title
    alias icon_label=dtterm_icon_label
    escape=$(print "\033")
    export PS1="${escape}[32m%${escape}[37m "
    export PS2="${escape}[32m>${escape}[37m "
    export PS3="${escape}[32m>${escape}[37m "
    unset escape
    ;;
*)
    alias title=':'
    alias icon_label=':'
    export PS1='% '
    export PS2='> '
    export PS3='> '
    ;;
esac

mcd()
{
    select dir in ${DIRS[*]}        # choose one.
    do
    if [ "${dir-}" ]    # valid response.
    then
        'cd' $(eval print -r $dir)
        src=0
        # search for the selected directory in the DIRS stack
        while [ $src -lt ${#DIRS[*]} ]
        do
            if [ "$dir" = "${DIRS[$src]}" ]
            then
                # shift DIRS entrys up one to make room for selected directory
                temp="${DIRS[$src]}"
                while [ $src -gt 0 ]
                do
                    DIRS[$src]="${DIRS[$src-1]}"
                    let "src = src - 1"
                done
                DIRS[0]="$temp"
                # set src high to break out of search loop
                src=${#DIRS[*]}
            fi
            let "src = src + 1"
        done
        print -r "${DIRS[*]}"
    else
        print "cd: no change"
    fi
    _record_dir

    break
    done

Quote:}

function _record_dir
{
    DIRS[0]="${PWD#${HOME%/}}"
    if [ "${DIRS[0]}" != "$PWD" ]
    then
        DIRS[0]="~${DIRS[0]}"
    fi
    title "${HOSTNAME}:${LOGNAME}:${DIRS[0]}"

Quote:}

_record_dir

function pushd
{
    if [ $# -eq 0 ]
    then
        'cd' $(eval print -r "${DIRS[1]}")
        DIRS[1]="${DIRS[0]}"
    else
        'cd' $1
        count=${#DIRS[*]}
        let "src = count - 1"
        dest=count
        while [ $src -ge 0 ]
        do
            DIRS[$dest]="${DIRS[$src]}"
            let "src = src - 1"
            let "dest = dest - 1"
        done
    fi
    _record_dir
    print -r "${DIRS[*]}"

Quote:}

function popd
{
    count=${#DIRS[*]}
    src=1
    dest=0
    while [ $src -lt $count ]
    do
        DIRS[dest]=${DIRS[src]}
        let "src = src + 1"
        let "dest = dest + 1"
    done
    unset DIRS[$dest]
    'cd' $(eval print -r "$DIRS")
    _record_dir
    print -r ${DIRS[*]}

Quote:}

function dirs
{
    print -r "${DIRS[*]}"

Quote:}

alias cd=mycd

function mycd
{
    'cd' $1
    _record_dir

Quote:}

function rlogin {
    /usr/bin/rlogin $*
    _record_dir

Quote:}

--


 
 
 

1. MeasureWare/Patrol/Oracle Snmart Plug Ins

I curently running MeasureWare with Patrol to monitor an Oracle
database.....

Unfortunately the Patrol is not Y2K and HP suggested Oracle Smart Plugs for
Openview.

Has anyone gone this route?
What was your experience like in the upgrade and configuration??

2. 3com home connect firmware upgrades

3. Netscape plug-ins for HP-Unix 10.10

4. Sparc instruction set reference

5. logging user log ins and outs

6. Connection problem with WMI, System Info, and more

7. Reward for NExS Spreadsheet Plug-Ins

8. Netscape audio or VRML plug-ins?

9. Netscape audio plug-ins?

10. NetScape Plug-Ins

11. Error while passing string type to functions

12. pass-through ?