env_helper

Boyd Waters bwaters at nrao.edu
Mon Mar 16 16:24:54 PDT 2009


Very weird, I was working on path_helper yesterday!

I like the "port env" idea.

We need "rpath" and "lpath" -- to add to the beginning or end of a PATH


Here's what we use at work:

#!/bin/ksh
#
# Script to define path-related manipulation functions. Must be run with "."
#
# Revision history: 1.0 MRM 940204 Functions from Chris Flatters' .profile
#                                  with permission
#                   1.1 MRM 950817 Corrections & updates from Chris

# Define some useful functions for setting paths:

# PrependPath <pathname> <dir> makes <dir> the first element of
# the search path stored in <pathname> unless the first element
# of the path is the current working directory (.), in which case
# <dir> becomes the second element of the search path, or unless
# <dir> is already an element of the search path, in which case
# the search path is left unchanged.

function PrependPath
{
    typeset path

    eval path=\${${1}}

    if   [ -n "$path" ]
    then
         case $path in
         ${2}*)    ;;                # Directory already at beginning
         *:${2}*)  ;;                # Directory already present
         .:*)       eval ${1}=.:${2}:${path##.:} ;;
         *)         eval ${1}=${2}:$path ;;
         esac
    else eval export ${1}=${2}
    fi

}

# PostpendPath <pathname> <dir> makes <dir> the last element of
# the search path stored in <pathname> unless the last element
# of the path is the current working directory (.), in which case
# <dir> becomes the second-last element of the search path, or unless
# <dir> is already an element of the search path, in which case
# the search path is left unchanged.

function PostpendPath
{
    typeset path

    eval path=\${${1}}

    if   [ -n "$path" ]
    then
         case $path in
         ${2}*)    ;;           # Directory already at beginning
         *:${2}*)  ;;           # Directory already present
         *:.)       eval ${1}=${path%%:.}:${2}:. ;;
         *)         eval ${1}=$path:${2} ;;
         esac
    else eval export ${1}=${2}
    fi
}

# PrependXPath <pathname> <dir> prepends a set of pathnames
# for XtResolvePathname rooted at <dir> to the path stored
# in <pathname>.  This is intended for use with XFILESEARCHPATH
# etc.

function PrependXPath
{
    typeset dir

    eval dir=${2}

    # Items suggested in X11R6 man page for XtResolvePathname
    PrependPath ${1} ${dir}/%T/%N%S
    PrependPath ${1} ${dir}/%l/%T/%N%S
    PrependPath ${1} ${dir}/%L/%T/%N%S
    PrependPath ${1} ${dir}/%T/%N%C%S
    PrependPath ${1} ${dir}/%l/%T/%N%C%S
    PrependPath ${1} ${dir}/%L/%T/%N%C%S
}

# PostpendXPath <pathname> <dir> appends a set of pathnames
# for XtResolvePathname rooted at <dir> to the path stored
# in <pathname>.  This is intended for use with XFILESEARCHPATH
# etc.

function PostpendXPath
{
    typeset dir

    eval dir=${2}

    # Items suggested in X11R6 man page for XtResolvePathname
    PostpendPath ${1} ${dir}/%L/%T/%N%C%S
    PostpendPath ${1} ${dir}/%l/%T/%N%C%S
    PostpendPath ${1} ${dir}/%T/%N%C%S
    PostpendPath ${1} ${dir}/%L/%T/%N%S
    PostpendPath ${1} ${dir}/%l/%T/%N%S
    PostpendPath ${1} ${dir}/%T/%N%S
}

# PrependUIDPath <pathname> <dir> prepends a set of pathnames
# for the Mrm functions rooted at <dir> to the path stored
# in <pathname>.  If the path begins with %U%S then the new
# entries will be inserted following %U%S

function PrependUIDPath
{
    typeset dir
    typeset path
    typeset pcu

    eval dir=${2}
    eval path=\${${1}}
    pcu=%U      # To get around SCCS %U% keyword substitution

    case $path in
    %U?S*)    eval ${1}=${path#\%U\%S}
              eval path=\${${1}}
              eval ${1}=${path#:}
              PrependPath ${1} ${dir}/%T/$pcu%S
              PrependPath ${1} ${dir}/%l/%T/$pcu%S
              PrependPath ${1} ${dir}/%L/%T/$pcu%S
              eval ${1}=$pcu%S:\${${1}}
              ;;
    *)        PrependPath ${1} ${dir}/%T/$pcu%S
              PrependPath ${1} ${dir}/%l/%T/$pcu%S
              PrependPath ${1} ${dir}/%L/%T/$pcu%S
              ;;
    esac
}

# PostpendUIDPath <pathname> <dir> appends a set of pathnames
# for the Mrm functions rooted at <dir> to the path stored
# in <pathname>.

function PostpendUIDPath
{
    typeset dir
    typeset pcu

    eval dir=${2}
    pcu=%U      # Get around SCCS %U% substitution

    PostpendPath ${1} ${dir}/%L/%T/$pcu%S
    PostpendPath ${1} ${dir}/%l/%T/$pcu%S
    PostpendPath ${1} ${dir}/%T/$pcu%S
}


More information about the macports-dev mailing list