# vim: ft=zsh noet local target die_msg re edscript target=$1 if [[ $2 == '!' ]]; then shift 2 re=$1 edscript=$2$'\nw\n' die_msg="failed to edit file ${target:t} to not match ${(qqq)re}" if grep -q $re $target; then ed -s $target <<<$edscript # || die $die_msg grep -q $re $target && die $die_msg fi else shift re=$1 edscript=$2$'\nw\n' die_msg="failed to edit file ${target:t} to match ${(qqq)re}" if ! grep -q $re $target; then ed -s $target <<<$edscript # || die $die_msg grep -q $re $target || die $die_msg fi fi