diff --git a/bin/sde b/bin/sde index fbac9a2..058561f 100755 --- a/bin/sde +++ b/bin/sde @@ -71,30 +71,25 @@ fi # load corresponding library for sh scripts # . "$SDEROOT/lib/libsde.in" +. "$SDEROOT/lib/sde-wrapper.in" if [ $# -eq 0 ]; then command="help" -elif [ "$1" != "${1%-*}" ]; then - # unknown command - echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood." - # call help without arguments - set -- - command="help" -elif [ -x "$SDEROOT/bin/sde-$1" ]; then - command="$1"; shift -elif grep -q "^#Alias: $1$" $SDEROOT/bin/sde-* 2> /dev/null; then - # use alias - command="$( grep -l "^#Alias: $1$" `ls -1d $SDEROOT/bin/sde-* | grep -v 'bin/sde-.*-.*'` 2> /dev/null | - head -n 1 | sed -e 's,.*/sde-,,' )" - shift else - # unknown command - echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood." - # call help without arguments - set -- - command="help" + # detect requested command + command="$( sde_wrapper_command "$1" )" + if [ -z "$command" ]; then + # unknown command + echo_error "Command '$COLOR_INFO$1$COLOR_NORMAL' not understood." + # call help without arguments + set -- + command="help" + else + shift + fi fi + [ -x "$SDEROOT/bin/sde-$command" ] || echo_abort 2 "Can't execute '$COLOR_INFO$SDEROOT/bin/sde-$command$COLOR_NORMAL', sorry." diff --git a/lib/sde-wrapper.in b/lib/sde-wrapper.in new file mode 100644 index 0000000..0923605 --- /dev/null +++ b/lib/sde-wrapper.in @@ -0,0 +1,34 @@ +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: lib/sde-wrapper.in +# Copyright (C) 2006 - 2007 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. A copy of the +# GNU General Public License can be found in the file COPYING. +# --- SDE-COPYRIGHT-NOTE-END --- + +# list all the valid command wrappers +# +sde_list_command_files() { + ls -1d "$SDEROOT/bin/sde-"* | grep -v 'bin/sde-.*-.*' +} + +sde_wrapper_command() { + local cmdbin= + if [ "$1" != "${1%-*}" ]; then + # trying to cheat, no dashes alowed + return + elif [ -x "$SDEROOT/bin/sde-$1" ]; then + # command given explicitly + echo "$1" + else + # given token may be an alias of a valid command + cmdbin=$( grep -l "^#Alias: $1$" `sde_list_command_files` | head -n 1 ) + echo "$cmdbin" | sed -e 's,.*/sde-,,' + fi +}