]> git.phdru.name Git - git-scripts.git/commitdiff
Feat: Add script `rename`
authorOleg Broytman <phd@phdru.name>
Thu, 21 Aug 2025 16:11:31 +0000 (19:11 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 27 Aug 2025 10:36:56 +0000 (13:36 +0300)
Only rename, not move yet.

rename [new file with mode: 0755]

diff --git a/rename b/rename
new file mode 100755 (executable)
index 0000000..3abe96c
--- /dev/null
+++ b/rename
@@ -0,0 +1,30 @@
+#! /bin/sh
+
+if [ -z "$1" -o -z "$2" -o -n "$3" ]; then
+    echo "Usage: $0 /path/to/repo new_name" >&2
+    exit 1
+fi
+
+start_dir="`pwd`" &&
+path_to_repo="$1" &&
+cd "$path_to_repo" &&
+path_to_repo="`pwd`" &&
+cd "$start_dir" &&
+
+cd "`dirname \"$0\"`" &&
+if ! grep -q "^$path_to_repo\$" locate-all.list; then
+    echo "$path_to_repo" is not a known repository >&2
+    exit 1
+fi
+
+dname="`dirname $path_to_repo`" &&
+new_path="$dname/$2" &&
+mv "$path_to_repo" "$new_path" &&
+
+tmpfile="`mktemp`" &&
+sed "s!^$path_to_repo\$!$new_path!" locate-all.list > "$tmpfile" &&
+if cmp -s "$tmpfile" locate-all.list; then
+    exec rm -f "$tmpfile"
+else
+    exec mv "$tmpfile" locate-all.list
+fi