5517c1f
#!/bin/sh
5517c1f
5517c1f
set -e +x
5517c1f
31a55c3
function fail {
31a55c3
    echo "$0: $1" >&2
31a55c3
    exit 1
31a55c3
}
31a55c3
5517c1f
USAGE="Usage: $0 dep"
5517c1f
5517c1f
if [ $# -ne 1 ]; then
31a55c3
    fail "$USAGE"
5517c1f
fi
5517c1f
5517c1f
DEP=$1
5517c1f
5517c1f
CABALFILE=$(ls *.cabal)
5517c1f
5517c1f
if [ $(echo $CABALFILE | wc -w) -ne 1 ]; then
31a55c3
   fail "There needs to be one .cabal file in the current dir!"
5517c1f
fi
5517c1f
5517c1f
if [ ! -f $CABALFILE.orig ]; then
5517c1f
    BACKUP=.orig
5517c1f
fi
5517c1f
ca7fad4
if grep "$DEP" $CABALFILE | sed -e "s/$DEP//" | grep -q -e "[A-Za-z]"; then
31a55c3
    fail "$0: deleting whole $DEP lines not safe - try more precise pattern"
5517c1f
fi
5517c1f
5517c1f
sed -i$BACKUP -e "/$DEP/d" $CABALFILE