mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

commit e7da40b12a50b337489b334b9a8c7a7a2fe3ecc7
parent 435db85f1c3fcc483827b837110d52406127bb97
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sun, 24 Dec 2023 16:56:54 +0100

wiki

Diffstat:
wikiaddfield | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/wikiaddfield b/wikiaddfield @@ -0,0 +1,18 @@ +#!/bin/bash + +FILE="$1" +FIELD="$2" +VAL="$3" +cd "$HOME/todo/wiki" + +if grep "^$FIELD: " $FILE > /dev/null +then + sed -i "s/^$FIELD: .*/&$VAL/" $FILE +else + # Remove blank lines from the end of a file: + # https://unix.stackexchange.com/a/552195 + sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' $FILE + echo >> $FILE + echo "$FIELD: $VAL" >> $FILE +fi +