commit 88bf44b115150248250865fdd8915fa0ed032074
parent 741fab61e2cc9ae62005d4bfb5d0e29c335bcccc
Author: Jacob R. Edwards <n/a>
Date: Mon, 22 Nov 2021 16:52:15 -0800
Fix cleanpath with more than two periods
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/local/bin/bin/cleanpath b/local/bin/bin/cleanpath
@@ -4,7 +4,7 @@
# [cleanname, the perfect name, is taken by plan9]
#
# 1. Insert separators between lower-case and upper-case letters
-# 2. Replace most punctuation with space or nothing (including all but the last period)
+# 2. Replace most punctuation with space or nothing
# 3. Replace space with hyphen
# 4. Replace excess hyphens with nothing
# 5. Replace upper-case letters with their lower-case equivilents
@@ -12,7 +12,14 @@
sed -E 's/([^A-Z])([A-Z])/\1 \2/g
s/'\''//g
s/[]!"#$%&()+,:;<>@[\\^{|}~]/ /g
-s/\.([^.]*\.)/-\1/g
+
+# I believe it is impossible to do with a single sed substitution.
+:l
+/\.[^.]*\./ {
+ s/\./-/
+ t l
+}
+
y/ /--/
s/--+/-/g
s!(^|[/.])-!\1!g