summaryrefslogtreecommitdiff
path: root/scripts/sh/wr
diff options
context:
space:
mode:
authorGeorge Abbott <george@gabbott.dev>2025-01-26 11:37:22 +0000
committerGeorge Abbott <george@gabbott.dev>2025-01-26 11:37:22 +0000
commit82abadcecc7534b4847238ee2a977f33256b0439 (patch)
treead8752c1dc9914829e80bc2f3f1a45dfec8f4b4a /scripts/sh/wr
parentbac748dbe8c28cf1ed3b387b24f89ffe5a58ffc9 (diff)
sh
Diffstat (limited to 'scripts/sh/wr')
-rwxr-xr-xscripts/sh/wr50
1 files changed, 50 insertions, 0 deletions
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"