commit 02d296a04e1c27efb6c5d2bd6fe4239d3c45d7da
parent 86b25cd76ad9a2b4346f1fa045c3474dbbdbdd87
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Mon, 25 Dec 2023 12:36:51 +0100
wiki
Diffstat:
4 files changed, 24 insertions(+), 39 deletions(-)
diff --git a/wikiaddfield b/wikiaddfield
@@ -1,9 +1,8 @@
#!/bin/bash
-FILE="$1"
+FILE="$1" # full path to file
FIELD="$2"
VAL="$3"
-cd "$HOME/todo/wiki"
if grep "^$FIELD: " $FILE > /dev/null
then
diff --git a/wikifolder b/wikifolder
@@ -1,17 +0,0 @@
-#!/bin/bash
-
-FILE="$1"
-FOLDER="$2"
-cd "$HOME/todo/wiki"
-
-if grep '^Folder: ' $FILE > /dev/null
-then
- sed -i "s/^Folder: .*/Folder: $FOLDER/" $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 "Folder: $FOLDER" >> $FILE
-fi
-
diff --git a/wikimv b/wikimv
@@ -1,25 +1,12 @@
#!/bin/bash
-FROM="$1"
-TO="$2"
-FROMF="$HOME/todo/wiki/$FROM"
-TOF="$HOME/todo/wiki/$TO"
+# move file in wiki folder (without changing incoming)
-if [ -f "$TOF" ]
-then
- echo 'target already exists'
- exit 42
-fi
+FOLDER="$1"
+FROM="$2"
+TO="$3"
+FROMF="$HOME/$FOLDER/$FROM"
+TOF="$HOME/$TO/$TO"
-mv "$FROMF" "$TOF" || (echo 'fail move'; exit 42)
+mv -n "$FROMF" "$TOF" || (echo 'fail move'; exit 42)
-# now replace all links in files with match
-
-cd "$HOME/todo/wiki"
-grep -RlF "[$FROM]" | while read a; do
- if [ -f $a ]; then
- sed -i "s/\[$FROM\]/\[$TO\]/g" $a
- fi
-done
-
-exit 0
diff --git a/wikiupdate b/wikiupdate
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# in wiki folder FOLDER, replace links to FROM to links to TO
+
+FOLDER="$1"
+FROM="$2"
+TO="$3"
+
+cd "$HOME/$FOLDER"
+grep -RlF "[$FROM]" | while read a; do
+ if [ -f $a ]; then
+ sed -i "s/\[$FROM\]/\[$TO\]/g" $a
+ fi
+done
+
+exit 0