From 82abadcecc7534b4847238ee2a977f33256b0439 Mon Sep 17 00:00:00 2001
From: George Abbott <george@gabbott.dev>
Date: Sun, 26 Jan 2025 11:37:22 +0000
Subject: sh

---
 scripts/sh/wr | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100755 scripts/sh/wr

(limited to 'scripts/sh/wr')

diff --git a/scripts/sh/wr b/scripts/sh/wr
new file mode 100755
index 0000000..f7b0c6a
--- /dev/null
+++ b/scripts/sh/wr
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Usage (- represents end of arguments) :-
+# wr - :: opens the raw directory in vim for navigation (wrf is generally better)
+# wr name - :: Opens the file "name"
+# (TODO)wr dir/name - :: Creates "dir" if doesnt exist and opens "dir/name"
+# wr fuzzy :: opens a fuzzy find list of wr files to edit. Shortcut is "wrf"
+# (TODO)wr tree  :: opens a tree view of all files. Shortcut is "wrt"
+
+begins_with() { # haystack prefix
+    value=$1
+    prefix=$2
+
+    case "$value" in
+       "$prefix"*) return 0
+    esac
+
+    return 1
+}
+
+[ -z "$EDITOR" ] && echo "EDITOR not set" && exit
+[ -z "$FUZZY" ] && echo "FUZZY not set" && exit
+
+tree() {
+    eza --tree "$HOME/wr"
+}
+
+fuzzy() {
+    FILE="$(find "$HOME/wr" -type f | $FUZZY)"
+    [ -z "$FILE" ] && exit 0
+    if ! begins_with "$FILE" "$HOME/wr" ; then
+	FILE="$HOME/wr/$FILE"
+    fi
+
+    mkdir "$(dirname "$FILE")" -p 
+    $EDITOR "$FILE"
+}
+
+if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; 
+then 
+    fuzzy 
+    exit 0
+fi
+
+if [ "$1" = "tree" ] ; then 
+    tree
+    exit 0
+fi
+
+mkdir "$HOME/wr/$(dirname $1)" -p
+$EDITOR "$HOME/wr/$1"
-- 
cgit v1.2.1