derename.sh
authorNiki Roo <niki@nikiroo.be>
Sat, 18 Apr 2020 16:16:18 +0000 (18:16 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 18 Apr 2020 16:16:18 +0000 (18:16 +0200)
derename.sh [new file with mode: 0755]

diff --git a/derename.sh b/derename.sh
new file mode 100755 (executable)
index 0000000..6c8cbff
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+git status | grep renamed: | sed 's/[^:]*: *\([^>]*\) -> \(.*\)/\1>\2/g' | while read -r ln; do
+       old="`echo "$ln" | cut -f1 -d'>'`"
+       new="`echo "$ln" | cut -f2 -d'>'`"
+       mkdir -p "`dirname "$old"`"
+       git mv "$new" "$old"
+       rmdir "`dirname "$new"`" 2>/dev/null
+       true
+done
+