summaryrefslogtreecommitdiffstats
path: root/.scripts/tools
diff options
context:
space:
mode:
authorStephen Gregoratto <themanhimself@sgregoratto.me>2019-03-13 11:29:11 +1100
committerStephen Gregoratto <themanhimself@sgregoratto.me>2019-03-13 11:29:11 +1100
commit53c42a5d00d158000146c23da31532fc6240bd2d (patch)
tree1c7cfb04fc0cf6b535e0e1d9177bcabe51dabe53 /.scripts/tools
parentb74f98ede6fa6aa4bb03fd7775be5e35f790d7e9 (diff)
downloadeibhear-53c42a5d00d158000146c23da31532fc6240bd2d.tar.gz
eibhear-53c42a5d00d158000146c23da31532fc6240bd2d.tar.zst
eibhear-53c42a5d00d158000146c23da31532fc6240bd2d.zip
change rotdir to use ed(1)
Diffstat (limited to '.scripts/tools')
-rwxr-xr-x.scripts/tools/rotdir17
1 files changed, 15 insertions, 2 deletions
diff --git a/.scripts/tools/rotdir b/.scripts/tools/rotdir
index 50e1d84..2fabeda 100755
--- a/.scripts/tools/rotdir
+++ b/.scripts/tools/rotdir
@@ -1,3 +1,16 @@
#!/bin/sh
-# Give this script a filename argument. Returns PWD rotated with that file first.
-ls "$PWD" | awk "BEGIN { lines = \"\"; m = 0; } /^$1$/ { m = 1; } { if (!m) { if (lines) { lines = lines\"\n\"; } lines = lines\"\"\$0; } else { print \$0; } } END { print lines; }"
+if [ -z "$1" ]; then
+ echo usage: rotdir regex 2>&1
+ exit 1;
+fi
+
+ed -s <<EOF
+# Read in all files in the current dir
+r !find "$PWD" -maxdepth 1
+# Search all lines for regex, move to top
+g/$1/m0
+# Print all lines
+,p
+# Force quit
+Q
+EOF