diff --git a/conf/type/__line/gencode-remote b/conf/type/__line/gencode-remote index 9ca36177..75cd92b4 100755 --- a/conf/type/__line/gencode-remote +++ b/conf/type/__line/gencode-remote @@ -20,8 +20,10 @@ # file="/$__object_id" +regex="" state_should="present" -[ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file") +[ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file") +[ -f "$__object/parameter/regex" ] && regex=$(cat "$__object/parameter/regex") [ -f "$__object/parameter/state" ] && state_should=$(cat "$__object/parameter/state") state_is="$(cat "$__object/explorer/state")" @@ -41,7 +43,18 @@ case "$state_should" in ;; absent) - echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\"" + if [ "$regex" -a "$line" ]; then + echo "Mutally exclusive parameters regex and line given for state absent" >&2 + exit 1 + fi + + [ "$line" ] && regex="^$line\$" + + cat << eof +tmp=\$(mktemp) +sed '/$regex/d' "$file" > \$tmp && cat "\$tmp" > "$file" && rm -f "\$tmp" +eof + #echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\"" ;; *) echo "Unknown state: $state_should" >&2 diff --git a/conf/type/__line/man.text b/conf/type/__line/man.text index 137e31d1..e1a5941c 100644 --- a/conf/type/__line/man.text +++ b/conf/type/__line/man.text @@ -23,11 +23,20 @@ state:: line:: Specifies the line which should be absent or present + Must be present, if state is present. + Must not be combined with regex, if state is absent. regex:: - If supplied, search for this regex. - Otherwise entire line must be matched. + If state is present, search for this pattern and add + given line, if the given regular expression does not match. + + In case of absent, ensure all lines matching the + regular expression are absent (cannot be combined with + the line parameter, if state is absent). + + If the regular expression contains / (slashes), they need + to be escaped with \ (backslash): / becomes \/. file:: If supplied, use this as the destination file.