cfgfoo

git clone https://orangeshoelaces.net/git/cfgfoo.git

5842a843a821f73b30e5b5ade90ebfcd7203cacc

Author: Vasilii Kolobkov on 12/19/2018

Committer: Vasilii Kolobkov on 12/19/2018

Override lines

Lines matching $2 pattern are deleted and $3 is appended. Pattern is
basic regular expression (BRE).

Stats

aliases               |  1 +
steps/edit/overrideln | 13 ++++++++
2 files changed, 14 insertions(+)

Patch

diff --git a/aliases b/aliases
index 1134afa..e15b47e 100644
--- a/aliases
+++ b/aliases
@@ -5,6 +5,7 @@ alias acme_reqcrt1="cfgfoo ${CFGFOOPATH}/steps/acme-client/reqcrt1 "
 alias acme_schedcrtrefresh="cfgfoo ${CFGFOOPATH}/steps/acme-client/schedcrtrefresh "
 
 alias appendfln="cfgfoo ${CFGFOOPATH}/steps/edit/addfln "
+alias overrideln="cfgfoo ${CFGFOOPATH}/steps/edit/addfln "
 
 alias mkdir="cfgfoo ${CFGFOOPATH}/steps/fs/mkdir "
 alias install="cfgfoo ${CFGFOOPATH}/steps/fs/install -s "
diff --git a/steps/edit/overrideln b/steps/edit/overrideln
new file mode 100644
index 0000000..bd15883
--- /dev/null
+++ b/steps/edit/overrideln
@@ -0,0 +1,13 @@
+step_taken() {
+	[ -f "$1" ] &&
+	grep -Fxq "$3" "$1"
+}
+
+take_step() {
+	{
+		printf '%g /%s/ d\n' "$(echo "$2" | sed 's!/!\\/!g')"
+		printf '$a\n'
+		printf '%s\n.\n' "$3"
+		printf 'w\nq\n'
+	} | TERM=dump ex -s "$1"
+}