Joerg Sonnenberger wrote:
On Sun, Jul 20, 2008 at 04:26:47AM +0200, Christian Biere wrote:+cat "${userfile}" __CONF_FILE__ __DB_FILE__ 2>/dev/null | \ +{ + while read line + do + line="${line##\#*}"+ prog="${line%%\ *}" + if [ X != "X${prog}" ] && [ -x "${prog}" ]+ then exec ${line} "${@}" + fi + doneCan you make this awk please? read is horrible slow for larger files... Joerg
I made changes to the patch. It now does a better job of stripping out comments. It's a little neater, I think, now. See attached...
Louis
--- pkgtools/pkg_alternatives/files/wrapper.sh.orig 2008-07-21 08:17:07.000000000 -0400 +++ pkgtools/pkg_alternatives/files/wrapper.sh 2008-07-21 14:32:28.000000000 -0400 @@ -44,18 +44,20 @@ else userfile=~/.pkg_alternatives/${wrapper} fi -alternatives=$(cat ${userfile} __CONF_FILE__ __DB_FILE__ 2>/dev/null | \ - grep -v "^#" | tr ' ' '¬') -found= -for a in ${alternatives}; do - prog=$(echo ${a} | cut -d '¬' -f 1) - if [ -x ${prog} ]; then - found=$(echo ${a} | tr '¬' ' ') - break - fi +files=__DB_FILE__ +for f in $userfile __CONF_FILE__ ;do + [ -f "$f" ] && files="$f $files" done +found=$(awk '!/^[ ]*#/{ + f = "if [ -x " $1 " ] ; then echo " $0 " ;fi " | getline found + if ( f == 1 ) { + print found + exit + } +}' $files ) + if [ -z "${found}" ]; then echo "${progname}: no alternatives found" 1>&2 exit 1